From 916cab1fbdc38ce0d0d1c4125a10631be91f70b1 Mon Sep 17 00:00:00 2001 From: Boblet Date: Thu, 25 Aug 2022 16:58:27 +0200 Subject: [PATCH] jar foreground actors --- .../java/com/hbm/wiaj/GuiWorldInAJar.java | 71 ++++++++++--------- .../java/com/hbm/wiaj/actors/ActorBase.java | 28 ++++++++ .../com/hbm/wiaj/actors/ActorTileEntity.java | 24 ++----- .../com/hbm/wiaj/actors/ISpecialActor.java | 8 ++- 4 files changed, 77 insertions(+), 54 deletions(-) create mode 100644 src/main/java/com/hbm/wiaj/actors/ActorBase.java diff --git a/src/main/java/com/hbm/wiaj/GuiWorldInAJar.java b/src/main/java/com/hbm/wiaj/GuiWorldInAJar.java index 58cce4bff..75e847907 100644 --- a/src/main/java/com/hbm/wiaj/GuiWorldInAJar.java +++ b/src/main/java/com/hbm/wiaj/GuiWorldInAJar.java @@ -29,14 +29,13 @@ import net.minecraft.nbt.NBTTagCompound; //krass public class GuiWorldInAJar extends GuiScreen { - WorldInAJar world; RenderBlocks renderer; JarScript testScript; public GuiWorldInAJar() { super(); - world = new WorldInAJar(15, 15, 15); + WorldInAJar world = new WorldInAJar(15, 15, 15); renderer = new RenderBlocks(world); renderer.enableAO = true; @@ -122,7 +121,13 @@ public class GuiWorldInAJar extends GuiScreen { brickScene.add(new ActionUpdateActor(0, "speed", 2F)); brickScene.add(new ActionUpdateActor(0, "hasCog", false)); brickScene.add(new ActionWait(20)); - brickScene.add(new ActionRotate(360, 0, 20)); + brickScene.add(new ActionUpdateActor(0, "rotation", 4)); + brickScene.add(new ActionWait(10)); + brickScene.add(new ActionUpdateActor(0, "rotation", 3)); + brickScene.add(new ActionWait(10)); + brickScene.add(new ActionUpdateActor(0, "rotation", 5)); + brickScene.add(new ActionWait(10)); + brickScene.add(new ActionUpdateActor(0, "rotation", 2)); brickScene.add(new ActionWait(100)); this.testScript.addScene(startingScene).addScene(brickScene); @@ -145,29 +150,16 @@ public class GuiWorldInAJar extends GuiScreen { private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { GL11.glPushMatrix(); - double scale = -10; - GL11.glTranslated(width / 2, height / 2 + 70, 100); - GL11.glScaled(scale, scale, scale); - GL11.glScaled(1, 1, 0.01); //incredible flattening power - - double pitch = testScript.lastRotationPitch + (testScript.rotationPitch - testScript.lastRotationPitch) * testScript.interp; - double yaw = testScript.lastRotationYaw + (testScript.rotationYaw - testScript.lastRotationYaw) * testScript.interp; - GL11.glRotated(pitch, 1, 0, 0); - GL11.glRotated(yaw, 0, 1, 0); - - GL11.glTranslated(-7, 0 , -7); - - GL11.glTranslated(world.sizeX / 2D, 0 , world.sizeZ / 2D); - GL11.glTranslated(world.sizeX / -2D, 0 , world.sizeZ / -2D); + setupRotation(); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); GL11.glShadeModel(GL11.GL_SMOOTH); Tessellator.instance.startDrawingQuads(); - for(int x = 0; x < world.sizeX; x++) { - for(int y = 0; y < world.sizeY; y++) { - for(int z = 0; z < world.sizeZ; z++) { - renderer.renderBlockByRenderType(world.getBlock(x, y, z), x, y, z); + for(int x = 0; x < testScript.world.sizeX; x++) { + for(int y = 0; y < testScript.world.sizeY; y++) { + for(int z = 0; z < testScript.world.sizeZ; z++) { + renderer.renderBlockByRenderType(testScript.world.getBlock(x, y, z), x, y, z); } } } @@ -175,31 +167,42 @@ public class GuiWorldInAJar extends GuiScreen { Tessellator.instance.draw(); GL11.glShadeModel(GL11.GL_FLAT); GL11.glPopMatrix(); - - RenderHelper.enableStandardItemLighting(); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240F, 240F); + + GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPushMatrix(); - - GL11.glTranslated(width / 2, height / 2 + 70, 100); - GL11.glScaled(scale, scale, scale); - GL11.glScaled(1, 1, 0.01); - GL11.glRotated(pitch, 1, 0, 0); - GL11.glRotated(yaw, 0, 1, 0); - GL11.glTranslated(-7, 0 , -7); - GL11.glTranslated(world.sizeX / 2D, 0 , world.sizeZ / 2D); - GL11.glTranslated(world.sizeX / -2D, 0 , world.sizeZ / -2D); + setupRotation(); + RenderHelper.enableStandardItemLighting(); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240F, 240F); for(Entry actor : this.testScript.actors.entrySet()) { GL11.glPushMatrix(); - actor.getValue().draw(this.testScript.ticksElapsed, this.testScript.interp); + actor.getValue().drawBackgroundComponent(this.testScript.ticksElapsed, this.testScript.interp); GL11.glPopMatrix(); } GL11.glPopMatrix(); } + private void setupRotation() { + + double scale = -50; + + GL11.glTranslated(width / 2, height / 2 + 70, 400); + GL11.glScaled(scale, scale, scale); + GL11.glScaled(1, 1, 0.5); //incredible flattening power + + double pitch = testScript.lastRotationPitch + (testScript.rotationPitch - testScript.lastRotationPitch) * testScript.interp; + double yaw = testScript.lastRotationYaw + (testScript.rotationYaw - testScript.lastRotationYaw) * testScript.interp; + + GL11.glRotated(pitch, 1, 0, 0); + GL11.glRotated(yaw, 0, 1, 0); + GL11.glTranslated(-7, 0 , -7); + GL11.glTranslated(testScript.world.sizeX / 2D, 0 , testScript.world.sizeZ / 2D); + GL11.glTranslated(testScript.world.sizeX / -2D, 0 , testScript.world.sizeZ / -2D); + } + @Override public boolean doesGuiPauseGame() { return false; diff --git a/src/main/java/com/hbm/wiaj/actors/ActorBase.java b/src/main/java/com/hbm/wiaj/actors/ActorBase.java new file mode 100644 index 000000000..be65923cf --- /dev/null +++ b/src/main/java/com/hbm/wiaj/actors/ActorBase.java @@ -0,0 +1,28 @@ +package com.hbm.wiaj.actors; + +import net.minecraft.nbt.NBTTagCompound; + +/** + * Very basic actor base class that holds NBT, not very useful on its own + * @author hbm + */ +public abstract class ActorBase implements ISpecialActor { + + protected NBTTagCompound data = new NBTTagCompound(); + + @Override + public void setActorData(NBTTagCompound data) { + this.data = data; + } + + @Override + public void setDataPoint(String tag, Object o) { + if(o instanceof String) this.data.setString(tag, (String) o); + if(o instanceof Integer) this.data.setInteger(tag, (Integer) o); + if(o instanceof Float) this.data.setFloat(tag, (Float) o); + if(o instanceof Double) this.data.setDouble(tag, (Double) o); + if(o instanceof Boolean) this.data.setBoolean(tag, (Boolean) o); + if(o instanceof Byte) this.data.setByte(tag, (Byte) o); + if(o instanceof Short) this.data.setShort(tag, (Short) o); + } +} diff --git a/src/main/java/com/hbm/wiaj/actors/ActorTileEntity.java b/src/main/java/com/hbm/wiaj/actors/ActorTileEntity.java index bbbb6d12b..0aeac2776 100644 --- a/src/main/java/com/hbm/wiaj/actors/ActorTileEntity.java +++ b/src/main/java/com/hbm/wiaj/actors/ActorTileEntity.java @@ -2,19 +2,19 @@ package com.hbm.wiaj.actors; import com.hbm.wiaj.JarScene; -import net.minecraft.nbt.NBTTagCompound; - -public class ActorTileEntity implements ISpecialActor { +public class ActorTileEntity extends ActorBase { ITileActorRenderer renderer; - NBTTagCompound data = new NBTTagCompound(); public ActorTileEntity(ITileActorRenderer renderer) { this.renderer = renderer; } @Override - public void draw(int ticks, float interp) { + public void drawForegroundComponent(int ticks, float interp) { } + + @Override + public void drawBackgroundComponent(int ticks, float interp) { renderer.renderActor(ticks, interp, data); } @@ -22,18 +22,4 @@ public class ActorTileEntity implements ISpecialActor { public void updateActor(JarScene scene) { renderer.updateActor(scene.script.ticksElapsed, data); } - - @Override - public void setActorData(NBTTagCompound data) { - this.data = data; - } - - @Override - public void setDataPoint(String tag, Object o) { - if(o instanceof String) this.data.setString(tag, (String) o); - if(o instanceof Integer) this.data.setInteger(tag, (Integer) o); - if(o instanceof Float) this.data.setFloat(tag, (Float) o); - if(o instanceof Double) this.data.setDouble(tag, (Double) o); - if(o instanceof Boolean) this.data.setBoolean(tag, (Boolean) o); - } } diff --git a/src/main/java/com/hbm/wiaj/actors/ISpecialActor.java b/src/main/java/com/hbm/wiaj/actors/ISpecialActor.java index 0ac958a45..244620dea 100644 --- a/src/main/java/com/hbm/wiaj/actors/ISpecialActor.java +++ b/src/main/java/com/hbm/wiaj/actors/ISpecialActor.java @@ -11,8 +11,14 @@ import net.minecraft.nbt.NBTTagCompound; */ public interface ISpecialActor { - public void draw(int ticks, float interp); + /** Draws things in the foreground like text boxes */ + public void drawForegroundComponent(int ticks, float interp); + /** Draws things in the background, fotted to the world renderer like TESRs */ + public void drawBackgroundComponent(int ticks, float interp); + /** Update ticks to emulate serverside ticking */ public void updateActor(JarScene scene); + /** Sets the data object to the passed NBT */ public void setActorData(NBTTagCompound data); + /** Auto-detects the passed object's type and sets the specified NBT tag */ public void setDataPoint(String tag, Object o); }