diff --git a/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java b/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java index 05b242b..4083d2c 100644 --- a/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java +++ b/src/main/java/blockrenderer6343/client/WorldSceneRenderer.java @@ -1,6 +1,5 @@ package blockrenderer6343.client; -import static cn.kuzuanpa.thinker.client.handler.dummyWorldHandler.dummyWorldObjects; import static org.lwjgl.opengl.GL11.*; import java.nio.ByteBuffer; @@ -137,12 +136,22 @@ public void setCameraLookAt(Vector3f eyePos, Vector3f lookAt, Vector3f worldUp) public boolean sync(){ if(world.lock) return false; if(world instanceof TrackedDummyWorld)((TrackedDummyWorld) world).clearBlocks(); - List tmp = new ArrayList<>(); - dummyWorldHandler.dummyWorldObjects.forEach((obj) -> tmp.addAll(obj.addToWorld(world))); - dummyWorldHandler.dummyWorldObjects.addAll( tmp); if(world instanceof TrackedDummyWorld)((TrackedDummyWorld) world).onProfileChanged(); return true; } + + public void onTick(){ + world.lock=true; + List tmp = new ArrayList<>(); + List tmp1 = new ArrayList<>(); + dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.onTick:147").forEach((obj) -> { + if(obj.shouldInWorld(world.timer)){if(!obj.alreadyInWorld())tmp.addAll(obj.addToWorld(world)); + }else if(obj.alreadyInWorld())tmp1.addAll(obj.removeFromWorld(world)); + }); + dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.onTick:151").addAll( tmp); + dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.onTick:152").removeAll( tmp1); + world.lock=false; + } public void setCameraLookAt(Vector3f lookAt, double radius, double rotationPitch, double rotationYaw) { this.lookAt = lookAt; Vector3 vecX = new Vector3(Math.cos(rotationPitch), 0, Math.sin(rotationPitch)); @@ -254,7 +263,7 @@ void renderSceneForPicking() { glInitNames(); glPushName(-1); - for (IdummyWorldThinkerObject obj : dummyWorldObjects) { + for (IdummyWorldThinkerObject obj : dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.renderSceneForPicking:266")) { try { glEnable(GL_DEPTH_TEST); @@ -321,13 +330,15 @@ protected void drawWorld() { glEnable(GL_TEXTURE_2D); glEnable(GL_ALPHA_TEST); glEnable(GL_DEPTH_TEST); - dummyWorldObjects.forEach((obj) -> { + world.lock=true; + dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.drawWorld:333").forEach((obj) -> { try { - obj.render(world, world.timer, null); + if(obj.shouldInWorld(world.timer))obj.render(world, world.timer, null); } catch (Exception e) { Thinker.err(e); } }); + world.lock=false; //onMouseMoved(Mouse.getX(),Mouse.getY()); @@ -359,7 +370,7 @@ public MovingObjectPosition rayTrace(Vector3f hitPos,BlockPosition pos) { (hitPos.y - startPos.yCoord), (hitPos.z - startPos.zCoord)); - return ((TrackedDummyWorld) this.world).rayTraceBlockswithTargetMap(startPos, endPos,dummyWorldHandler.dummyWorldObjects.stream().map(IdummyWorldThinkerObject::getPos).collect(Collectors.toSet()), pos); + return ((TrackedDummyWorld) this.world).rayTraceBlockswithTargetMap(startPos, endPos,dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.rayTrace:371").stream().map(IdummyWorldThinkerObject::getPos).collect(Collectors.toSet()), pos); } /*** @@ -377,7 +388,7 @@ protected MovingObjectPosition screenPos2BlockPosFace(int mouseX, int mouseY, in drawWorld(); AtomicReference result = new AtomicReference<>(); - dummyWorldHandler.dummyWorldObjects.forEach((blockDummy)->{ + dummyWorldHandler.getDummyWorldObjects("WorldSceneRenderer.screenPos2BlockPosFace:389").forEach((blockDummy)->{ BlockPosition pos = blockDummy.getPos(); GL11.glPushMatrix(); if(!blockDummy.getWorldAnimeList().isEmpty())blockDummy.getWorldAnimeList().forEach(gAnime->{ diff --git a/src/main/java/blockrenderer6343/world/DummyWorld.java b/src/main/java/blockrenderer6343/world/DummyWorld.java index 353fed8..5979f09 100644 --- a/src/main/java/blockrenderer6343/world/DummyWorld.java +++ b/src/main/java/blockrenderer6343/world/DummyWorld.java @@ -45,10 +45,9 @@ public DummyWorld() { } @Override public void updateEntities() { - if(!lock)System.out.println("World missing lock when ticking!"); ArrayList invalidTileEntities = new ArrayList<>(); - for (IdummyWorldThinkerObject o : dummyWorldHandler.dummyWorldObjects) { + for (IdummyWorldThinkerObject o : dummyWorldHandler.getDummyWorldObjects("DummyWorld.updateEntities:51")) { if(o.getWorldAnimeList().stream().filter(anime -> anime instanceof IDummyWorldTickingAnime).anyMatch(anime -> ((IDummyWorldTickingAnime) anime).beforeTick(timer, o, this)))return; @@ -76,12 +75,6 @@ public void updateEntities() { this.loadedTileEntityList.removeAll(invalidTileEntities); } - public void updateEntitiesForNEI() { - lock=true; - super.updateEntities(); - lock=false; - } - @Override public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) {} diff --git a/src/main/java/blockrenderer6343/world/DummyWorldTickThread.java b/src/main/java/blockrenderer6343/world/DummyWorldTickThread.java index 421b0f5..67ec823 100644 --- a/src/main/java/blockrenderer6343/world/DummyWorldTickThread.java +++ b/src/main/java/blockrenderer6343/world/DummyWorldTickThread.java @@ -2,6 +2,7 @@ import cn.kuzuanpa.thinker.Thinker; import cn.kuzuanpa.thinker.client.handler.configHandler; +import cn.kuzuanpa.thinker.client.handler.dummyWorldHandler; public class DummyWorldTickThread extends Thread{ @Override @@ -18,13 +19,13 @@ public DummyWorldTickThread() { @Override public void run() { while (true) { - if(trackedDummyWorld!=null&&(int)Math.abs((System.currentTimeMillis()%100000)-lastTickTime) > intervalBetweenTicks){ + if(trackedDummyWorld!=null&&!trackedDummyWorld.lock&&(int)Math.abs((System.currentTimeMillis()%100000)-lastTickTime) > intervalBetweenTicks){ lastTickTime = (int)(System.currentTimeMillis()%100000); - trackedDummyWorld.lock=true; + try { trackedDummyWorld.updateEntities(); - }catch (Exception e){Thinker.err("Exception occurred when ticking Dummy world");e.printStackTrace();} - trackedDummyWorld.lock=false; + }catch (Exception e){Thinker.err("Exception occurred when ticking Dummy world, Previous user:"+ dummyWorldHandler.ObjectListUser);e.printStackTrace();} + if(configHandler.recordDummyWorldTickTooLong.get()&&System.currentTimeMillis()%100000-lastTickTime>2*intervalBetweenTicks)System.out.println("A Tick of DummyWorld takes too long: "+(System.currentTimeMillis()%100000-lastTickTime)+"ms"); }else { try { @@ -35,7 +36,6 @@ public void run() { } public void setTrackedDummyWorld(DummyWorld world){ trackedDummyWorld=world; - if(world!=null)world.lock=true; this.interrupt(); } } diff --git a/src/main/java/cn/kuzuanpa/thinker/Thinker.java b/src/main/java/cn/kuzuanpa/thinker/Thinker.java index 17bb1e0..e65927d 100644 --- a/src/main/java/cn/kuzuanpa/thinker/Thinker.java +++ b/src/main/java/cn/kuzuanpa/thinker/Thinker.java @@ -17,25 +17,28 @@ import blockrenderer6343.world.DummyWorldTickThread; import cn.kuzuanpa.thinker.client.handler.configHandler; import cn.kuzuanpa.thinker.client.json.*; -import cn.kuzuanpa.thinker.client.ThinkingGuiWelcome; import cn.kuzuanpa.thinker.command.CommandGetTileNBT; import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.Loader; -import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.*; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; -import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.dedicated.DedicatedServer; import net.minecraftforge.common.MinecraftForge; +import org.apache.logging.log4j.Level; +import org.spongepowered.asm.mixin.MixinEnvironment; import static cn.kuzuanpa.thinker.client.json.thinkerJsonReader.animesAdaptors; import static cn.kuzuanpa.thinker.client.json.thinkerJsonReader.objectsAdaptors; -@Mod(modid = Thinker.MOD_ID, version = Thinker.VERSION, dependencies = "required-after:CodeChickenCore@[1.0.7,);after:geckolib3") +@Mod(modid = Thinker.MOD_ID, version = Thinker.VERSION, dependencies = "required-after:CodeChickenCore@[1.0.7,)") public class Thinker { public static final String MOD_ID = "thinker"; @@ -43,14 +46,19 @@ public class Thinker public static final String VERSION = "0.0.1"; public static final DummyWorldTickThread dummyWorldTickThread=new DummyWorldTickThread(); public static int delay = 5; - public static boolean isGeckoLibLoaded=false; + public static boolean isGeckoLibLoaded=false,isServerSide=false; @SidedProxy(clientSide = "cn.kuzuanpa.thinker.clientProxy", serverSide = "cn.kuzuanpa.thinker.commonProxy") public static commonProxy PROXY; @EventHandler public void preInit(FMLPreInitializationEvent event){ + isServerSide=MinecraftServer.getServer() instanceof DedicatedServer; isGeckoLibLoaded= Loader.isModLoaded("geckolib3"); + if(isServerSide){ + FMLLog.log(Level.ERROR,"Thinker is an CLIENT only mod, and will disable entirely in Server!"); + return; + } FMLCommonHandler.instance().bus().register(this); MinecraftForge.EVENT_BUS.register(this); configHandler.preInit(event); @@ -58,13 +66,15 @@ public void preInit(FMLPreInitializationEvent event){ @EventHandler public void init(FMLInitializationEvent event) { + if(isServerSide)return; PROXY.init(event); - try { - thinkerJsonReader.readAllProfiles("ideas");}catch (Exception ignored){} + dummyWorldTickThread.start(); configHandler.saveAll(); registerObjectAdaptor(new defaultObjectsAdaptor()); - registerAnimeAdaptor(new defaultAnimeAdaptor()); + registerAnimeAdaptor(new defaultAnimeAdaptor());try { + thinkerJsonReader.readAllProfiles("ideas"); + }catch (Exception ignored){} } @EventHandler public void registerCommands(FMLServerStartingEvent e){ @@ -93,13 +103,14 @@ public static float getFloat(Object str){ } public static boolean getBoolean(Object str){return Boolean.parseBoolean((String) str);} + @SideOnly(Side.CLIENT) @SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { if(!configHandler.welcome.get())return; if (delay > 0 && event.phase == TickEvent.Phase.END) { --delay; if (delay == 0) { - FMLClientHandler.instance().getClient().displayGuiScreen(new ThinkingGuiWelcome()); + FMLClientHandler.instance().getClient().displayGuiScreen(new cn.kuzuanpa.thinker.client.ThinkingGuiMain("HelloThinker")); configHandler.welcome.set(false); configHandler.welcome.save(); } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiMain.java b/src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiMain.java index e79ae37..79a93b9 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiMain.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiMain.java @@ -80,11 +80,19 @@ public ThinkingGuiMain(ItemStack item) { allowUserInput = false; selectedProfileID = profileHandler.getProfileFromItem(item.getUnlocalizedName()).id; } + public ThinkingGuiMain(String id) { + openByUser=true; + allowUserInput = false; + selectedProfileID =id; + } public DummyWorldButton worldButton= new DummyWorldButton(1,0,0,displayWidth,displayHeight); public void onOpenByUserAfter(){ initTime=System.currentTimeMillis(); openByUser=false; - if(!selectedProfileID.equals(""))onProfileChanged(selectedProfileID); + if(!selectedProfileID.isEmpty()){ + onProfileChanged(selectedProfileID); + foldThemeSelector(true); + } } public void initGui() { super.initGui(); @@ -119,20 +127,20 @@ protected void keyTyped(char p_73869_1_, int p_73869_2_) @Override protected void mouseClicked(int p_73864_1_, int p_73864_2_, int mouseButton) { - for (int l = this.buttonList.size() - 1; l >= 0 ;l--) - { - ThinkerButtonBase guibutton = (ThinkerButtonBase)this.buttonList.get(l); - if(guibutton.updateHoverState(p_73864_1_, p_73864_2_)) - { - GuiScreenEvent.ActionPerformedEvent.Pre event = new GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList); - if (MinecraftForge.EVENT_BUS.post(event)) - break; - if(event.button.id!=0)event.button.func_146113_a(this.mc.getSoundHandler()); - if (this.onButtonPressed(event.button)) break; - if (this.equals(this.mc.currentScreen)) - MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList)); - } - } + for (int l = this.buttonList.size() - 1; l >= 0 ;l--) + { + ThinkerButtonBase guibutton = (ThinkerButtonBase)this.buttonList.get(l); + if(guibutton.updateHoverState(p_73864_1_, p_73864_2_)) + { + GuiScreenEvent.ActionPerformedEvent.Pre event = new GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList); + if (MinecraftForge.EVENT_BUS.post(event)) + break; + if(event.button.id!=0)event.button.func_146113_a(this.mc.getSoundHandler()); + if (this.onButtonPressed(event.button)) break; + if (this.equals(this.mc.currentScreen)) + MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList)); + } + } } protected void onProfileChanged(String newProfileID){ initTime=System.currentTimeMillis(); @@ -148,7 +156,7 @@ protected void onProfileChanged(String newProfileID){ selectedProfileID =newProfileID; } protected boolean onButtonPressed(GuiButton button) { - ((DummyWorldButton)buttonList.get(1)).clickOnOtherButton=button.id!=1; + ((DummyWorldButton)buttonList.get(1)).clickOnOtherButton=button.id!=1&&button.id<10; if(button.id==2) this.mc.displayGuiScreen(new ThinkerSettingsGui()); if(button.id==3) { int mouseY=this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; @@ -167,15 +175,18 @@ protected boolean onButtonPressed(GuiButton button) { return true; } public void foldThemeSelector(boolean immediately){ - ((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime)-(immediately?10:0), (int) (System.currentTimeMillis()-initTime+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0)); - ((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime)-(immediately?10:0), (int) (System.currentTimeMillis()-initTime+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0)); - ((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime)-(immediately?10:0), (int) (System.currentTimeMillis()-initTime+ (immediately?0:configHandler.getConfiguredAnimeTime(200))),16,0)); + ((ThinkerButtonBase)buttonList.get(3)).getGuiAnimeList().clear(); + ((ThinkerButtonBase)buttonList.get(4)).getGuiAnimeList().clear(); + ((ThinkerButtonBase)buttonList.get(5)).getGuiAnimeList().clear(); + ((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) getTimer()-(immediately?10:0), (int) (getTimer()+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0)); + ((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) getTimer()-(immediately?10:0), (int) (getTimer()+ (immediately?0:configHandler.getConfiguredAnimeTime(500))),-80-8*currentProfileLayer,0)); + ((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) getTimer()-(immediately?10:0), (int) (getTimer()+ (immediately?0:configHandler.getConfiguredAnimeTime(200))),16,0)); themeSelectorFolded=true; } public void unfoldThemeSelector(){ - ((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime), (int) (System.currentTimeMillis()-initTime+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0)); - ((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime), (int) (System.currentTimeMillis()-initTime+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0)); - ((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) (System.currentTimeMillis()-initTime), (int) (System.currentTimeMillis()-initTime+ configHandler.getConfiguredAnimeTime(200)),-16,0)); + ((ThinkerButtonBase)buttonList.get(3)).addAnime(new animeMoveLinear((int) getTimer(), (int) (getTimer()+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0)); + ((ThinkerButtonBase)buttonList.get(4)).addAnime(new animeMoveLinear((int) getTimer(), (int) (getTimer()+ configHandler.getConfiguredAnimeTime(500)),80+8*currentProfileLayer,0)); + ((ThinkerButtonBase)buttonList.get(5)).addAnime(new animeMoveLinear((int) getTimer(), (int) (getTimer()+ configHandler.getConfiguredAnimeTime(200)),-16,0)); themeSelectorFolded=false; } public void handleMouseInput(){ @@ -202,7 +213,7 @@ public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_){ if(!button.visible)return; if(button.updateHoverState(x,y))hoveringString= Collections.singletonList(button.displayString); }); - if (hoveringString == null||hoveringString.stream().allMatch(string->string.equals(""))) return; + if (hoveringString == null||hoveringString.stream().allMatch(String::isEmpty)) return; drawHoveringText(hoveringString, x, y+5, fontRendererObj); } public boolean close() { diff --git a/src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiWelcome.java b/src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiWelcome.java deleted file mode 100644 index 3c7478e..0000000 --- a/src/main/java/cn/kuzuanpa/thinker/client/ThinkingGuiWelcome.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * This class was created by . It is a part of Thinker. - * Get the Source Code in github: - * https://github.com/kuzuanpa/Thinker - * - * Thinker is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Thinker is Open Source and distributed under the - * LGPLv3 License: https://www.gnu.org/licenses/lgpl-3.0.txt - * - */ - -/* - * This class was created by . It is a part of Thinker. - * Get the Source Code in github: - * https://github.com/kuzuanpa/Thinker - * - * Thinker is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * Thinker is Open Source and distributed under the - * LGPLv3 License: https://www.gnu.org/licenses/lgpl-3.0.txt - * - */ -package cn.kuzuanpa.thinker.client; - -import cn.kuzuanpa.thinker.client.handler.profileHandler; -import cn.kuzuanpa.thinker.client.objects.dummyWorld.IdummyWorldThinkerObject; -import cn.kuzuanpa.thinker.client.handler.dummyWorldHandler; -import cn.kuzuanpa.thinker.client.objects.gui.DummyWorldButton; -import cn.kuzuanpa.thinker.client.objects.gui.ThinkerButtonBase; -import cn.kuzuanpa.thinker.client.objects.gui.ThinkingBackground; -import cn.kuzuanpa.thinker.client.objects.gui.anime.animeRotateSteadily; -import cn.kuzuanpa.thinker.client.objects.gui.thinkerImage; -import cpw.mods.fml.client.FMLClientHandler; -import cpw.mods.fml.common.registry.LanguageRegistry; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.init.Items; -import net.minecraftforge.client.event.GuiScreenEvent; -import net.minecraftforge.common.MinecraftForge; -import org.lwjgl.input.Mouse; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static cn.kuzuanpa.thinker.client.handler.dummyWorldHandler.*; -import static cn.kuzuanpa.thinker.client.handler.keyBindHandler.keyThink; - -/** - * @author kuzuanpa - */ -@SideOnly(Side.CLIENT) -public class ThinkingGuiWelcome extends GuiScreen { - - private int displayWidth,displayHeight; - public String selectedProfileID="HelloThinker"; - public boolean openByUser,themeSelectorFolded=false; - public long initTime=0,lastProfileSelectedTime=0; - private List hoveringString=new ArrayList<>(); - protected List buttonsHaveAnime = new ArrayList(); - public ThinkingGuiWelcome() { - openByUser=true; - allowUserInput = false; - } - public void postInit(){ - initTime=System.currentTimeMillis(); - openByUser=false; - } - public void initGui() { - super.initGui(); - displayWidth= FMLClientHandler.instance().getClient().currentScreen.width; - displayHeight= FMLClientHandler.instance().getClient().currentScreen.height; - buttonList.clear(); - buttonsHaveAnime.clear(); - dummyWorldObjects.clear(); - //buttonList.add(new ThinkerButton(-1,displayWidth-20,displayHeight-20,20,20,l10n("R"))); - buttonList.add(new ThinkingBackground(0, displayWidth,displayHeight)); - buttonList.add(new DummyWorldButton(1,0,0,displayWidth,displayHeight)); - buttonList.add(new thinkerImage(2,displayWidth-52,20,0,0,32,32,"textures/base.png", l10n("thinker.settings")).addAnime(new animeRotateSteadily(0.05F)).addToList(buttonsHaveAnime)); - - - ArrayList blocks=new ArrayList<>(); - profileHandler.clearAllProfile(); - profileHandler.addProfile(new profileHandler.thinkingProfile("test1",Items.string.getIconFromDamage(0),new thinkerImage(12,displayWidth-122,20,0,0,32,32,"textures/base.png", l10n("test")).addAnime(new animeRotateSteadily(0.05F)).addToList(buttonsHaveAnime))); - profileHandler.addProfile(new profileHandler.thinkingProfile("HelloThinker",Items.string.getIconFromDamage(0),blocks,new thinkerImage(13,displayWidth-122,20,0,0,32,32,"textures/base.png", l10n("test")).addAnime(new animeRotateSteadily(0.05F)).addToList(buttonsHaveAnime))); - - if(openByUser)postInit(); - List buttonsProfile= profileHandler.getProfile("HelloThinker").buttons; - buttonList.addAll(buttonsProfile); - profileHandler.onProfileChanged("HelloThinker"); - dummyWorldHandler.onProfileChanged("HelloThinker"); - ((DummyWorldButton)buttonList.get(1)).onProfileChanged(); - } - - public String l10n(String key){String text1= LanguageRegistry.instance().getStringLocalization(key);if(text1.equals(""))return key;return text1;} - protected void keyTyped(char p_73869_1_, int p_73869_2_) - { - if (p_73869_2_ == 1|| p_73869_2_== keyThink.getKeyCode()) - { - close(); - } - } - @Override - protected void mouseClicked(int p_73864_1_, int p_73864_2_, int mouseButton) - { - for (int l = this.buttonList.size() - 1; l >= 0 ;l--) - { - ThinkerButtonBase guibutton = (ThinkerButtonBase)this.buttonList.get(l); - if(guibutton.updateHoverState(p_73864_1_, p_73864_2_)) - { - GuiScreenEvent.ActionPerformedEvent.Pre event = new GuiScreenEvent.ActionPerformedEvent.Pre(this, guibutton, this.buttonList); - if (MinecraftForge.EVENT_BUS.post(event)) - break; - if(event.button.id!=0)event.button.func_146113_a(this.mc.getSoundHandler()); - if (this.onButtonPressed(event.button)) break; - if (this.equals(this.mc.currentScreen)) - MinecraftForge.EVENT_BUS.post(new GuiScreenEvent.ActionPerformedEvent.Post(this, event.button, this.buttonList)); - } - } - } - protected boolean onButtonPressed(GuiButton button) { - ((DummyWorldButton)buttonList.get(1)).clickOnOtherButton=button.id!=1; - return true; - } - public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_){ - this.buttonsHaveAnime.forEach(b -> b.updateTimer(getTimer())); - super.drawScreen(p_73863_1_,p_73863_2_,p_73863_3_); - profileHandler.tick(); - - if(!Mouse.isInsideWindow())return; - int x = Mouse.getX() * this.width / this.mc.displayWidth; - int y = this.height - Mouse.getY() * this.height / this.mc.displayHeight - 1; - buttonList.forEach(b -> { - if (!(b instanceof ThinkerButtonBase)) return; - ThinkerButtonBase button = (ThinkerButtonBase) b; - if(!button.visible)return; - if(button.updateHoverState(x,y))hoveringString= Collections.singletonList(button.displayString); - }); - if (hoveringString == null||hoveringString.stream().allMatch(string->string.equals(""))) return; - drawHoveringText(hoveringString, x, y+5, fontRendererObj); - } - public boolean close() { - this.mc.displayGuiScreen(null); - this.mc.setIngameFocus(); - return true; - } - public boolean doesGuiPauseGame() - { - return false; - } - public long getTimer(){ - return System.currentTimeMillis()-initTime; - } -} diff --git a/src/main/java/cn/kuzuanpa/thinker/client/handler/dummyWorldHandler.java b/src/main/java/cn/kuzuanpa/thinker/client/handler/dummyWorldHandler.java index a19d91e..2ccdafd 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/handler/dummyWorldHandler.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/handler/dummyWorldHandler.java @@ -35,7 +35,12 @@ import java.util.List; public class dummyWorldHandler { - public static List dummyWorldObjects =new ArrayList<>(); + private static final List dummyWorldObjects =new ArrayList<>(); + public static String ObjectListUser=""; + public static List getDummyWorldObjects(String getterName) { + ObjectListUser=getterName; + return dummyWorldObjects; + } public static void onProfileChanged(String profileID){ dummyWorldObjects.clear(); if(profileHandler.getProfile(profileID).dummyWorldThinkerObjects.isEmpty())return; diff --git a/src/main/java/cn/kuzuanpa/thinker/client/json/defaultAnimeAdaptor.java b/src/main/java/cn/kuzuanpa/thinker/client/json/defaultAnimeAdaptor.java index 9b78aaf..d1e29e8 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/json/defaultAnimeAdaptor.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/json/defaultAnimeAdaptor.java @@ -28,32 +28,32 @@ public class defaultAnimeAdaptor implements IThinkerAnimeAdaptor{ public boolean isMapHaveValidContents(Map values) { if (!values.containsKey("type")) return false; - if (((String) values.get("type")).startsWith("gui")) switch (((String) values.get("type")).replaceFirst("gui.", "")) { + if (((String) values.get("type")).startsWith("gui")) switch (((String) values.get("type"))) { - case "MoveLinear": + case "gui.MoveLinear": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.moveLinear)"); - case "moveLinear": - return false;//cn.kuzuanpa.thinker.client.objects.gui.anime.animeMoveLinear.isMapHaveValidContents(values); - case "Color": + case "gui.moveLinear": + return cn.kuzuanpa.thinker.client.objects.gui.anime.animeMoveLinear.isMapHaveValidContents(values); + case "gui.Color": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.color)"); - case "RGBA": - case "color": + case "gui.RGBA": + case "gui.color": return cn.kuzuanpa.thinker.client.objects.gui.anime.animeRGBA.isMapHaveValidContents(values); - case "Rotate": + case "gui.Rotate": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.rotate)"); - case "rotate": + case "gui.rotate": return false;//dummyWorldBlock.isMapHaveValidContents(values); - case "RotateSteadily": + case "gui.RotateSteadily": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.rotateSteadily)"); - case "rotateSteadily": + case "gui.rotateSteadily": return false;//dummyWorldTile.isMapHaveValidContents(values); - case "Scale": + case "gui.Scale": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.scale)"); - case "scale": - return false;//dummyWorldTile.isMapHaveValidContents(values); - case "Transparency": + case "gui.scale": + return cn.kuzuanpa.thinker.client.objects.gui.anime.animeScale.isMapHaveValidContents(values); + case "gui.Transparency": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.transparency)"); - case "transparency": + case "gui.transparency": return cn.kuzuanpa.thinker.client.objects.gui.anime.animeTransparency.isMapHaveValidContents(values); default: return false; @@ -105,31 +105,31 @@ public IThinkerAnime create(Map values) { if (!values.containsKey("type")) return null; - if (((String) values.get("type")).startsWith("gui")) switch (((String) values.get("type")).replaceFirst("gui.", "")) { - case "MoveLinear": + if (((String) values.get("type")).startsWith("gui")) switch (((String) values.get("type"))) { + case "gui.MoveLinear": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.moveLinear)"); - case "moveLinear": + case "gui.moveLinear": return null; - case "Color": + case "gui.Color": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.color)"); - case "RGBA": - case "color": + case "gui.RGBA": + case "gui.color": return cn.kuzuanpa.thinker.client.objects.gui.anime.animeRGBA.create(values); - case "Rotate": + case "gui.Rotate": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.rotate)"); - case "rotate": + case "gui.rotate": return null; - case "RotateSteadily": + case "gui.RotateSteadily": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.rotateSteadily)"); - case "rotateSteadily": + case "gui.rotateSteadily": return null; - case "Scale": + case "gui.Scale": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.scale)"); - case "scale": - return null; - case "Transparency": + case "gui.scale": + return cn.kuzuanpa.thinker.client.objects.gui.anime.animeScale.create(values); + case "gui.Transparency": Thinker.log("syntax improvable: First Letter should be lower case.(type=gui.transparency)"); - case "transparency": + case "gui.transparency": return cn.kuzuanpa.thinker.client.objects.gui.anime.animeTransparency.create(values); default: return null; diff --git a/src/main/java/cn/kuzuanpa/thinker/client/json/thinkerJsonReader.java b/src/main/java/cn/kuzuanpa/thinker/client/json/thinkerJsonReader.java index b3ad118..b878529 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/json/thinkerJsonReader.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/json/thinkerJsonReader.java @@ -21,7 +21,6 @@ import cn.kuzuanpa.thinker.client.objects.IThinkerAnime; import cn.kuzuanpa.thinker.client.objects.dummyWorld.*; import cn.kuzuanpa.thinker.client.objects.gui.ThinkerButtonBase; -import cn.kuzuanpa.thinker.client.objects.gui.anime.IGuiAnime; import com.google.gson.JsonParseException; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/IdummyWorldThinkerObject.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/IdummyWorldThinkerObject.java index 53d5e02..f6cb5b4 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/IdummyWorldThinkerObject.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/IdummyWorldThinkerObject.java @@ -22,12 +22,19 @@ import java.util.List; public interface IdummyWorldThinkerObject extends IThinkerObject, IAnimatableThinkerObject { + boolean shouldInWorld(long timer); + boolean alreadyInWorld(); void render(DummyWorld world, long timer, BlockPosition mousePointingPos); /** * add object to world - * @return objects needed to add to render list, return new ArrayList<>() if null + * @return objects needed to add to render list, itself shouldn't be contained, return new ArrayList<>() if null */ List addToWorld(DummyWorld world); + /** + * remove object from world + * @return objects needed to remove from render list, itself shouldn't be contained, return new ArrayList<>() if null + */ + List removeFromWorld(DummyWorld world); BlockPosition getPos(); } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBlock.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBlock.java index 10edc47..09206e0 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBlock.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBlock.java @@ -44,20 +44,17 @@ public class dummyWorldBlock implements IdummyWorldThinkerObject, IAnimatableThinkerObject { public final ArrayList WorldAnimeList = new ArrayList<>(); - public boolean renderAllFaces=false; + public boolean renderAllFaces=false,hasTileEntity=false, rendering =false; public BlockPosition pos; public Block block; public ItemStack itemStack; public int dummyPlayerX =0, dummyPlayerY =0, dummyPlayerZ =0; public float dummyPlayerCarmeaPitch =0, dummyPlayerCarmeaYaw =0; public int meta; - public dummyWorldBlock(BlockPosition pos, Block block, IDummyWorldAnimes... animes){ - this(pos,block,0,animes); - } - public dummyWorldBlock(BlockPosition pos, Block block) { - this(pos,block,0); - } - public dummyWorldBlock(BlockPosition pos, ItemStack itemStack, int dummyPlayerX, int dummyPlayerY, int dummyPlayerZ,float dummyPlayerCarmeaPitch,float dummyPlayerCarmeaYaw, IDummyWorldAnimes... animes){ + public long joinTime,leaveTime; + public dummyWorldBlock(long joinTime,long leaveTime, BlockPosition pos, ItemStack itemStack, int dummyPlayerX, int dummyPlayerY, int dummyPlayerZ,float dummyPlayerCarmeaPitch,float dummyPlayerCarmeaYaw, IDummyWorldAnimes... animes){ + this.joinTime=joinTime; + this.leaveTime=leaveTime; this.pos=pos; this.itemStack =itemStack; this.dummyPlayerX =dummyPlayerX; @@ -67,7 +64,9 @@ public dummyWorldBlock(BlockPosition pos, ItemStack itemStack, int dummyPlayerX, this.dummyPlayerCarmeaYaw=dummyPlayerCarmeaYaw; Collections.addAll(WorldAnimeList,animes); } - public dummyWorldBlock(BlockPosition pos, Block block, int meta, IDummyWorldAnimes... animes){ + public dummyWorldBlock(long joinTime,long leaveTime, BlockPosition pos, Block block, int meta, IDummyWorldAnimes... animes){ + this.joinTime=joinTime; + this.leaveTime=leaveTime; this.pos=pos; this.block=block; this.meta=meta; @@ -86,6 +85,17 @@ public ArrayList getWorldAnimeList() { public BlockPosition getPos(){ return pos; } + + @Override + public boolean shouldInWorld(long timer) { + return joinTime<=timer && timer addToWorld(DummyWorld world) { - dummyWorldBlock block = ((dummyWorldBlock) this); + rendering=true; + dummyWorldBlock block = this; List tmp = new ArrayList<>(); if (block.itemStack != null) { block.itemStack.copy().tryPlaceItemIntoWorld(new DummyEntityPlayer(world).setPos(dummyPlayerX,dummyPlayerY,dummyPlayerZ).setFacing(dummyPlayerCarmeaPitch,dummyPlayerCarmeaYaw), world, pos.x, pos.y, pos.z, 0, 0, 0, 0); @@ -139,18 +148,29 @@ public List addToWorld(DummyWorld world) { block.block = Blocks.air; } if (world.getTileEntity(pos.x, pos.y, pos.z) != null) - tmp.add(new dummyWorldTile(pos,world.getTileEntity(pos.x, pos.y, pos.z), block.WorldAnimeList)); + tmp.add(new dummyWorldTile(joinTime, leaveTime, pos,world.getTileEntity(pos.x, pos.y, pos.z), block.WorldAnimeList)); } else world.setBlock(pos.x, pos.y, pos.z, block.block); if (!block.block.hasTileEntity(block.meta)) return tmp; - TileEntity tileEntity = block.block.createTileEntity(world, block.meta); - if (tileEntity != null) - tmp.add( new dummyWorldTile(pos,world.getTileEntity(pos.x, pos.y, pos.z), block.WorldAnimeList)); + TileEntity tile = block.block.createTileEntity(world, block.meta); + if (tile != null) { + hasTileEntity=true; + tmp.add( new dummyWorldTile(joinTime, leaveTime, pos,world.getTileEntity(pos.x, pos.y, pos.z), block.WorldAnimeList)); + } + return tmp; + } + + @Override + public List removeFromWorld(DummyWorld world) { + rendering=false; + List tmp = new ArrayList<>(); + world.setBlockToAir(pos.x, pos.y, pos.z); + if(hasTileEntity) tmp.add( new dummyWorldTile(joinTime, leaveTime, pos,world.getTileEntity(pos.x, pos.y, pos.z),this.getWorldAnimeList())); return tmp; } //JsonReader public static boolean isMapHaveValidContents(Map values) { - boolean result= values.containsKey("posX")&& values.containsKey("posY")&& values.containsKey("posZ")&& + boolean result= values.containsKey("joinTime")&&values.containsKey("leaveTime")&&values.containsKey("posX")&& values.containsKey("posY")&& values.containsKey("posZ")&& ((values.containsKey("block") && values.containsKey("meta")) || values.containsKey("fromItem"));//block+meta or fromItem if(!result) thinkerJsonReader.requestLogError("Not Enough contents for dummyWorldBlock: posX, posY, posZ, (block, meta) or (fromItem) "); return result; @@ -187,8 +207,8 @@ public static dummyWorldBlock create(Map values) { BlockPosition pos = new BlockPosition(getInt(values.get("posX")),getInt(values.get("posY")),getInt(values.get("posZ"))); - if(values.containsKey("fromItem"))return new dummyWorldBlock(pos,getItemStack((String)values.get("fromItem")),dummyPlayerX,dummyPlayerY,dummyPlayerZ,dummyPlayerPitch,dummyPlayerYaw).setRenderAllFace(renderAllFaces); - if(values.containsKey("block")&&values.containsKey("meta"))return new dummyWorldBlock(pos,Block.getBlockFromName((String) values.get("block")),getInt(values.get("meta"))).setRenderAllFace(renderAllFaces); + if(values.containsKey("fromItem"))return new dummyWorldBlock(getLong(values.get("joinTime")),getLong(values.get("leaveTime")),pos,getItemStack((String)values.get("fromItem")),dummyPlayerX,dummyPlayerY,dummyPlayerZ,dummyPlayerPitch,dummyPlayerYaw).setRenderAllFace(renderAllFaces); + if(values.containsKey("block")&&values.containsKey("meta"))return new dummyWorldBlock(getLong(values.get("joinTime")),getLong(values.get("leaveTime")), pos,Block.getBlockFromName((String) values.get("block")),getInt(values.get("meta"))).setRenderAllFace(renderAllFaces); return null; } } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBundle.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBundle.java index 9a928c9..96d7604 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBundle.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldBundle.java @@ -39,7 +39,7 @@ public dummyWorldBundle(){} public final ArrayList subObjects=new ArrayList<>(); public final ArrayList WorldAnimeList = new ArrayList<>(); public BlockPosition pos; - + public boolean inWorld =false; @Override public ArrayList getGuiAnimeList() { return null; @@ -50,6 +50,16 @@ public ArrayList getWorldAnimeList() { return WorldAnimeList; } + @Override + public boolean shouldInWorld(long timer) { + return subObjects.stream().anyMatch(idummyWorldThinkerObject -> idummyWorldThinkerObject.shouldInWorld(timer)); + } + + @Override + public boolean alreadyInWorld() { + return inWorld; + } + @Override public void render(DummyWorld world, long timer, BlockPosition mousePointingPos) { GL11.glPushMatrix(); @@ -71,11 +81,20 @@ public void render(DummyWorld world, long timer, BlockPosition mousePointingPos) @Override public List addToWorld(DummyWorld world) { + inWorld=true; List tmp = new ArrayList<>(); subObjects.forEach(obj->tmp.addAll(obj.addToWorld(world))); return tmp; } + @Override + public List removeFromWorld(DummyWorld world) { + inWorld=false; + List tmp = new ArrayList<>(); + subObjects.forEach(obj->tmp.addAll(obj.removeFromWorld(world))); + return tmp; + } + @Override public BlockPosition getPos() { return pos; @@ -86,8 +105,7 @@ public dummyWorldBundle addSubObject(IdummyWorldThinkerObject object){ } //JsonReader public static boolean isMapHaveValidContents(Map values) { - boolean result= values.containsKey("posX")&& values.containsKey("posY")&& values.containsKey("posZ")&& - values.containsKey("subObjects")&&values.get("subObjects") instanceof Map && objectsAdaptors.stream().anyMatch(adaptor-> ((Map) values.get("subObjects")).values().stream().allMatch(obj -> adaptor.isMapHaveValidContents((Map) obj))); + boolean result= values.containsKey("subObjects")&&values.get("subObjects") instanceof Map && objectsAdaptors.stream().anyMatch(adaptor-> ((Map) values.get("subObjects")).values().stream().allMatch(obj -> adaptor.isMapHaveValidContents((Map) obj))); if(!result) thinkerJsonReader.requestLogError("Not Enough contents for bundle: "); return result; } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldGeckoModel.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldGeckoModel.java index 0d29b3d..243125b 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldGeckoModel.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldGeckoModel.java @@ -47,6 +47,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -59,8 +60,12 @@ public class dummyWorldGeckoModel implements IGeoRenderer WorldAnimeList = new ArrayList<>(); public final BlockPosition pos ; + public boolean rendering=false; + public long joinTime,leaveTime; public static boolean isMapHaveValidContents(Map values) { - boolean result = values.containsKey("posX")&& + boolean result = values.containsKey("joinTime")&& + values.containsKey("leaveTime")&& + values.containsKey("posX")&& values.containsKey("posY")&& values.containsKey("posZ")&& values.containsKey("modelPath")&& @@ -71,15 +76,27 @@ public static boolean isMapHaveValidContents(Map values) { } public static dummyWorldGeckoModel create(Map values) { - return new dummyWorldGeckoModel(new BlockPosition(getInt(values.get("posX")),getInt(values.get("posY")),getInt(values.get("posZ"))),(String) values.get("modelPath"),(String) values.get("texturePath"),(String) values.get("animePath")); + return new dummyWorldGeckoModel(getLong(values.get("joinTime")),getLong(values.get("leaveTime")),new BlockPosition(getInt(values.get("posX")),getInt(values.get("posY")),getInt(values.get("posZ"))),(String) values.get("modelPath"),(String) values.get("texturePath"),(String) values.get("animePath")); } private final dummyWorldGeckoModelContainer dummyGeckoModel; - public dummyWorldGeckoModel(BlockPosition pos,String modelLocation, String textureLocation, String animeLocation) { + public dummyWorldGeckoModel(long joinTime,long leaveTime, BlockPosition pos,String modelLocation, String textureLocation, String animeLocation) { + this.joinTime=joinTime; + this.leaveTime=leaveTime; this.pos = pos; dummyGeckoModel =new dummyWorldGeckoModelContainer(modelLocation, textureLocation, animeLocation); } - public void render(DummyWorld world, long timer, BlockPosition mousePointingPos) { + @Override + public boolean shouldInWorld(long timer) { + return joinTime<=timer && timer addToWorld(DummyWorld world) { - return new ArrayList<>(); + rendering=true; + return new ArrayList<>(); } + + @Override + public List removeFromWorld(DummyWorld world) { + rendering=false; + return Collections.emptyList(); + } + public void destroy(){ this.dummyGeckoModel.thinkerModel.destroy(); } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldItem.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldItem.java index 8cd5ade..2f56ffa 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldItem.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldItem.java @@ -54,7 +54,12 @@ public class dummyWorldItem implements IdummyWorldThinkerObject, IAnimatableThin public float posX,posY,posZ; public ItemStack itemStack; public float pitch =0, yaw =0,roll=0; - public dummyWorldItem(float posX,float posY,float posZ, ItemStack itemStack, float roll, float pitch, float yaw, IDummyWorldAnimes... animes){ + public boolean rendering=false; + public long joinTime,leaveTime; + + public dummyWorldItem(long joinTime,long leaveTime, float posX,float posY,float posZ, ItemStack itemStack, float roll, float pitch, float yaw, IDummyWorldAnimes... animes){ + this.joinTime=joinTime; + this.leaveTime=leaveTime; this.posX=posX; this.posY=posY; this.posZ=posZ; @@ -76,6 +81,17 @@ public ArrayList getWorldAnimeList() { public BlockPosition getPos(){ return new BlockPosition((int) posX, (int) posY, (int) posZ); } + + @Override + public boolean shouldInWorld(long timer) { + return joinTime<=timer && timer addToWorld(DummyWorld world) { + rendering=true; return new ArrayList<>(); } + @Override + public List removeFromWorld(DummyWorld world) { + rendering=false; + return Collections.emptyList(); + } + //JsonReader public static boolean isMapHaveValidContents(Map values) { - boolean result= values.containsKey("posX")&& values.containsKey("posY")&& values.containsKey("posZ")&& + boolean result= values.containsKey("joinTime")&& values.containsKey("leaveTime")&& + values.containsKey("posX")&& values.containsKey("posY")&& values.containsKey("posZ")&& values.containsKey("item"); if(!result) thinkerJsonReader.requestLogError("Not Enough contents for dummyWorldBlock: posX, posY, posZ, item"); return result; @@ -142,7 +166,7 @@ public static dummyWorldItem create(Map values) { if(values.containsKey("yaw")) yaw = getFloat(values.get("yaw")); if(values.containsKey("roll")) roll = getFloat(values.get("roll")); - if(values.containsKey("item"))return new dummyWorldItem(getFloat(values.get("posX")),getFloat(values.get("posY")),getFloat(values.get("posZ")) , getItemStack((String)values.get("item")),roll,pitch,yaw); + if(values.containsKey("item"))return new dummyWorldItem(getLong(values.get("joinTime")),getLong(values.get("leaveTime")), getFloat(values.get("posX")),getFloat(values.get("posY")),getFloat(values.get("posZ")) , getItemStack((String)values.get("item")),roll,pitch,yaw); return null; } } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldTile.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldTile.java index 2c3901e..ac0997d 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldTile.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/dummyWorld/dummyWorldTile.java @@ -38,28 +38,32 @@ import static blockrenderer6343.client.WorldSceneRenderer.setDefaultPassRenderState; import static cn.kuzuanpa.thinker.Thinker.getInt; +import static cn.kuzuanpa.thinker.Thinker.getLong; public class dummyWorldTile implements IdummyWorldThinkerObject, IAnimatableThinkerObject { public BlockPosition pos; public final ArrayList WorldAnimeList = new ArrayList<>(); public TileEntity tile; + public boolean rendering=false; + public long joinTime,leaveTime; - public dummyWorldTile(BlockPosition pos, TileEntity tile, ArrayList animes){ + public dummyWorldTile(long joinTime,long leaveTime, BlockPosition pos, TileEntity tile, ArrayList animes){ + this.joinTime=joinTime; + this.leaveTime=leaveTime; this.pos=pos; this.tile=tile; WorldAnimeList.addAll(animes); } - public dummyWorldTile(BlockPosition pos, TileEntity tile, IDummyWorldAnimes... animes) { - this.pos = pos; - this.tile = tile; - Collections.addAll(WorldAnimeList, animes); - } - public dummyWorldTile(BlockPosition pos, TileEntity tile) { + public dummyWorldTile(long joinTime,long leaveTime, BlockPosition pos, TileEntity tile) { + this.joinTime=joinTime; + this.leaveTime=leaveTime; this.pos = pos; this.tile = tile; } public static boolean isMapHaveValidContents(Map values) { - boolean result = values.containsKey("posX")&& + boolean result = values.containsKey("joinTime")&& + values.containsKey("leaveTime")&& + values.containsKey("posX")&& values.containsKey("posY")&& values.containsKey("posZ")&& values.containsKey("tileEntityNBT"); @@ -76,7 +80,7 @@ public static dummyWorldTile create(Map values) { tileEntityNBT.setInteger("z",getInt(values.get("posZ"))); TileEntity tile = TileEntity.createAndLoadEntity(tileEntityNBT); - return new dummyWorldTile(new BlockPosition(getInt(values.get("posX")),getInt(values.get("posY")),getInt(values.get("posZ"))),tile); + return new dummyWorldTile(getLong(values.get("joinTime")),getLong(values.get("leaveTime")),new BlockPosition(getInt(values.get("posX")),getInt(values.get("posY")),getInt(values.get("posZ"))),tile); } @Override public ArrayList getGuiAnimeList() { @@ -88,6 +92,16 @@ public ArrayList getWorldAnimeList() { return WorldAnimeList; } + @Override + public boolean shouldInWorld(long timer) { + return joinTime<=timer && timer addToWorld(DummyWorld world) { + rendering=true; world.setTileEntity(pos.x, pos.y, pos.z, tile); if (tile.blockType != null) world.setBlock(pos.x, pos.y, pos.z, tile.blockType); return new ArrayList<>(); } + @Override + public List removeFromWorld(DummyWorld world) { + rendering=false; + world.removeTileEntity(pos.x, pos.y, pos.z); + if (tile.blockType != null) world.setBlockToAir(pos.x, pos.y, pos.z); + return Collections.emptyList(); + } + @Override public BlockPosition getPos() { return pos; diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/DummyWorldButton.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/DummyWorldButton.java index 6efd262..d07f9c5 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/DummyWorldButton.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/DummyWorldButton.java @@ -30,6 +30,7 @@ import blockrenderer6343.client.WorldSceneRenderer; import blockrenderer6343.world.TrackedDummyWorld; import cn.kuzuanpa.thinker.client.ThinkingGuiMain; +import cn.kuzuanpa.thinker.client.handler.dummyWorldHandler; import cn.kuzuanpa.thinker.client.handler.profileHandler; import codechicken.lib.gui.GuiDraw; import codechicken.lib.math.MathHelper; @@ -43,8 +44,6 @@ import org.lwjgl.util.vector.Vector3f; -import static cn.kuzuanpa.thinker.client.handler.dummyWorldHandler.dummyWorldObjects; - public class DummyWorldButton extends ThinkerButtonBase{ protected static ImmediateWorldSceneRenderer renderer; protected static Vector3f center; @@ -80,7 +79,7 @@ protected void initializeSceneRenderer(boolean resetCamera) { lookAt = renderer.getLookAt(); worldUp = renderer.getWorldUp(); } - dummyWorldObjects.clear(); + dummyWorldHandler.getDummyWorldObjects("DummyWorldButton.initializeSceneRenderer:84").clear(); renderer = new ImmediateWorldSceneRenderer(new TrackedDummyWorld()); renderer.setClearColor(0xC6C6C6); @@ -153,7 +152,7 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) { resetCenter(); } if(!worldSynced)return; - + renderer.onTick(); updateHoverState(mouseX,mouseY); GuiAnimeList.forEach(anime -> anime.animeDrawPre(timer)); diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/ThinkingProfileList.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/ThinkingProfileList.java index 27bf82a..a240ba1 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/ThinkingProfileList.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/ThinkingProfileList.java @@ -72,8 +72,8 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) { } public void walkMaps(int depth, Map map,Minecraft mc, AtomicInteger i,String path){ map.forEach((key,value)->{ - if(!path.equals("")&&!profileHandler.unfoldedDirs.contains(path))return; - if(value instanceof profileHandler.thinkingProfile) { + if(!path.isEmpty() &&!profileHandler.unfoldedDirs.contains(path))return; + if(value instanceof profileHandler.thinkingProfile && !((profileHandler.thinkingProfile) value).id.equals("HelloThinker")) { profileListHeight=Math.max(profileListHeight,i.get()); drawProfileAt(mc,depth*8, (int) (profileHandler.YOffset+i.get()),(profileHandler.thinkingProfile)value,depth); i.getAndAdd(16+configHandler.themeSelectorProfileGap.getI()); @@ -138,7 +138,7 @@ public String searchButtons(int depth, Map map,Minecraft mc, Atom if(!path.equals("")&&!profileHandler.unfoldedDirs.contains(path))return ""; String key = entry.getKey(); Object value = entry.getValue(); - if (value instanceof profileHandler.thinkingProfile) { + if (value instanceof profileHandler.thinkingProfile && !((profileHandler.thinkingProfile) value).id.equals("HelloThinker")) { if (isXYinButton((int) (profileHandler.YOffset + i.get()), mouseY)) return "Profile:"+key; i.getAndAdd(16 + configHandler.themeSelectorProfileGap.getI()); } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeMoveLinear.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeMoveLinear.java index 07a6982..0d3aaec 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeMoveLinear.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeMoveLinear.java @@ -14,9 +14,15 @@ */ package cn.kuzuanpa.thinker.client.objects.gui.anime; +import cn.kuzuanpa.thinker.client.json.thinkerJsonReader; import cn.kuzuanpa.thinker.client.objects.gui.ThinkerButtonBase; import org.lwjgl.opengl.GL11; +import java.util.Map; + +import static cn.kuzuanpa.thinker.Thinker.getFloat; +import static cn.kuzuanpa.thinker.Thinker.getInt; + public class animeMoveLinear implements IGuiAnime { public animeMoveLinear(int startTime, int endTime, int dX, int dY){ this.startTime=startTime; @@ -60,4 +66,19 @@ public void updateButton(long time, ThinkerButtonBase button) { public String jsonName() { return "Gui.MoveLinear"; } + + public static boolean isMapHaveValidContents(Map values) { + boolean result = values.containsKey("startTime")&& + values.containsKey("endTime")&& + values.containsKey("dX")&& + values.containsKey("dY"); + if(!result) + thinkerJsonReader.requestLogError("Not Enough contents for gui.Scale: startTime, endTime, dX, dY"); + return result; + } + + public static animeMoveLinear create(Map values) { + + return new animeMoveLinear(getInt(values.get("startTime")),getInt(values.get("endTime")),getInt(values.get("dX")),getInt(values.get("dY"))); + } } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeScale.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeScale.java index f7f941e..8c08e69 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeScale.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/anime/animeScale.java @@ -14,9 +14,15 @@ */ package cn.kuzuanpa.thinker.client.objects.gui.anime; +import cn.kuzuanpa.thinker.client.json.thinkerJsonReader; import cn.kuzuanpa.thinker.client.objects.gui.ThinkerButtonBase; import org.lwjgl.opengl.GL11; +import java.util.Map; + +import static cn.kuzuanpa.thinker.Thinker.getFloat; +import static cn.kuzuanpa.thinker.Thinker.getInt; + public class animeScale implements IGuiAnime { public animeScale(int startTime,int endTime,float scaleRate,float scaleX,float scaleY){ this.startTime=startTime; @@ -41,10 +47,26 @@ public void animeDrawPre(long time) {} public void animeDrawAfter(long time) {} @Override public void updateButton(long time, ThinkerButtonBase button) { - //TODO } @Override public String jsonName() { return "Gui.Scale"; } + + public static boolean isMapHaveValidContents(Map values) { + boolean result = values.containsKey("startTime")&& + values.containsKey("endTime")&& + values.containsKey("scaleRate"); + if(!result) + thinkerJsonReader.requestLogError("Not Enough contents for gui.Scale: startTime, endTime, scaleRate"); + return result; + } + + public static animeScale create(Map values) { + float scaleX=1.0F,scaleY=1.0F; + if(values.containsKey("scaleX"))scaleX=getFloat(values.get("scaleX")); + if(values.containsKey("scaleY"))scaleY=getFloat(values.get("scaleY")); + + return new animeScale(getInt(values.get("startTime")),getInt(values.get("endTime")),getFloat(values.get("scaleRate")),scaleX,scaleY); + } } diff --git a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/custom/customImage.java b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/custom/customImage.java index 1c2f484..66029e8 100644 --- a/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/custom/customImage.java +++ b/src/main/java/cn/kuzuanpa/thinker/client/objects/gui/custom/customImage.java @@ -42,7 +42,6 @@ import static cn.kuzuanpa.thinker.Thinker.getInt; public class customImage extends ThinkerButtonBase implements IAnimatableThinkerObject { - public final ArrayList GuiAnimeList = new ArrayList<>(); public customImage(int id, String texturePath, int posX, int posY, int width, int height){ super(id,posX,posY,width,height,""); @@ -101,9 +100,6 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY){ if (this.visible) { GL11.glPushMatrix(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTextureId); - GL11.glTranslatef(xPosition + (width / 2F), yPosition + (height / 2F),0); - GuiAnimeList.forEach(anime -> anime.animeDraw(timer)); - GL11.glTranslatef(-(xPosition + (width / 2F)), -(yPosition + (height / 2F)),0); //why (256F/height)? idk, i just rendered some picture and guessed this argument. float var7 = 0.00390625F*(256F/height)*(height*1F/width); @@ -114,8 +110,10 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY){ tessellator.addVertexWithUV(posX + width, posY + height, zLevel, width * var7, height * var8); tessellator.addVertexWithUV(posX + width, posY, zLevel, width * var7, 0); tessellator.addVertexWithUV(posX, posY, zLevel, 0, 0); + GL11.glTranslatef(xPosition, yPosition ,0); + GuiAnimeList.forEach(anime -> anime.animeDraw(timer)); + GL11.glTranslatef(-(xPosition ), -(yPosition ),0); tessellator.draw(); - GL11.glPopMatrix(); } } diff --git a/src/main/java/cn/kuzuanpa/thinker/command/CommandGetTileNBT.java b/src/main/java/cn/kuzuanpa/thinker/command/CommandGetTileNBT.java index 8b34023..5e796d1 100644 --- a/src/main/java/cn/kuzuanpa/thinker/command/CommandGetTileNBT.java +++ b/src/main/java/cn/kuzuanpa/thinker/command/CommandGetTileNBT.java @@ -14,28 +14,16 @@ */ package cn.kuzuanpa.thinker.command; -import cn.kuzuanpa.thinker.util.Nbt; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.stream.JsonReader; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; import net.minecraft.command.WrongUsageException; -import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraftforge.common.DimensionManager; -import java.io.DataOutput; -import java.io.File; -import java.io.IOException; -import java.io.StringReader; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; public class CommandGetTileNBT extends CommandBase {