diff --git a/src/main/java/com/hbm/render/anim/HbmAnimations.java b/src/main/java/com/hbm/render/anim/HbmAnimations.java index 7078f668b..c4783ed9e 100644 --- a/src/main/java/com/hbm/render/anim/HbmAnimations.java +++ b/src/main/java/com/hbm/render/anim/HbmAnimations.java @@ -18,6 +18,7 @@ public class HbmAnimations { //animation is playing, though this will cancel the animation entirely. public static final Animation[][] hotbar = new Animation[9][8]; //now with 8 parallel rails per slot! time to get railed! + /** Keyframe-based animation system primarily used for guns, not to be confused with Drillgon's animloader system. */ public static class Animation { //the "name" of the animation slot. if the item has a different key than diff --git a/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java b/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java index 33bdb32d9..7895c3788 100644 --- a/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java +++ b/src/main/java/com/hbm/render/tileentity/RenderDoorGeneric.java @@ -11,6 +11,7 @@ import com.hbm.animloader.AnimationWrapper.EndResult; import com.hbm.animloader.AnimationWrapper.EndType; import com.hbm.blocks.BlockDummyable; import com.hbm.render.loader.IModelCustomNamed; +import com.hbm.render.tileentity.door.IRenderDoors; import com.hbm.tileentity.DoorDecl; import com.hbm.tileentity.TileEntityDoorGeneric; @@ -32,86 +33,96 @@ public class RenderDoorGeneric extends TileEntitySpecialRenderer { TileEntityDoorGeneric te = (TileEntityDoorGeneric) tile; - if(buf == null){ - buf = GLAllocation.createDirectByteBuffer(8*4).asDoubleBuffer(); - } + if(buf == null) buf = GLAllocation.createDirectByteBuffer(8*4).asDoubleBuffer(); DoorDecl door = te.getDoorType(); GL11.glPushMatrix(); - GL11.glTranslated(x+0.5, y, z+0.5); + GL11.glTranslated(x + 0.5, y, z+0.5); switch(te.getBlockMetadata() - BlockDummyable.offset) { - case 2: GL11.glRotatef(0+90, 0F, 1F, 0F); break; - case 4: GL11.glRotatef(90+90, 0F, 1F, 0F); break; - case 3: GL11.glRotatef(180+90, 0F, 1F, 0F); break; - case 5: GL11.glRotatef(270+90, 0F, 1F, 0F); break; - } - door.doOffsetTransform(); - - double[][] clip = door.getClippingPlanes(); - for(int i = 0; i < clip.length; i ++){ - GL11.glEnable(GL11.GL_CLIP_PLANE0+i); - buf.put(clip[i]); - buf.rewind(); - GL11.glClipPlane(GL11.GL_CLIP_PLANE0+i, buf); + case 2: GL11.glRotatef(90, 0F, 1F, 0F); break; + case 4: GL11.glRotatef(180, 0F, 1F, 0F); break; + case 3: GL11.glRotatef(270, 0F, 1F, 0F); break; + case 5: GL11.glRotatef(0, 0F, 1F, 0F); break; } - GL11.glShadeModel(GL11.GL_SMOOTH); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glEnable(GL11.GL_LIGHTING); + IRenderDoors sednaRenderer = door.getSEDNARenderer(); - AnimatedModel animModel = door.getAnimatedModel(); - if(animModel != null){ - Animation anim = door.getAnim(); - bindTexture(door.getTextureForPart(te.getSkinIndex(), "")); - long time = System.currentTimeMillis(); - long startTime = te.state > 1 ? te.animStartTime : time; - boolean reverse = te.state == 1 || te.state == 2; - AnimationWrapper w = new AnimationWrapper(startTime, anim).onEnd(new EndResult(EndType.STAY)); - if(reverse) - w.reverse(); - animModel.controller.setAnim(w); - animModel.renderAnimated(System.currentTimeMillis()); - } else { - IModelCustomNamed model = door.getModel(); + if(sednaRenderer != null) { - long ms = System.currentTimeMillis()-te.animStartTime; - float openTicks = MathHelper.clamp_float(te.state == 2 || te.state == 0 ? door.timeToOpen()*50-ms : ms, 0, door.timeToOpen()*50)*0.02F; - - for(String partName : model.getPartNames()) { - if(!door.doesRender(partName, false)) - continue; - - GL11.glPushMatrix(); - { - bindTexture(door.getTextureForPart(te.getSkinIndex(), partName)); - doPartTransform(door, partName, openTicks, false); - model.renderPart(partName); - - for(String innerPartName : door.getChildren(partName)) { - if(!door.doesRender(innerPartName, true)) - continue; - - GL11.glPushMatrix(); - { - bindTexture(door.getTextureForPart(te.getSkinIndex(), innerPartName)); - doPartTransform(door, innerPartName, openTicks, true); - model.renderPart(innerPartName); - } - GL11.glPopMatrix(); - } - } - GL11.glPopMatrix(); + GL11.glShadeModel(GL11.GL_SMOOTH); + sednaRenderer.render(te, buf); + GL11.glShadeModel(GL11.GL_FLAT); + + } else { + door.doOffsetTransform(); + + double[][] clip = door.getClippingPlanes(); + for(int i = 0; i < clip.length; i ++){ + GL11.glEnable(GL11.GL_CLIP_PLANE0+i); + buf.put(clip[i]); + buf.rewind(); + GL11.glClipPlane(GL11.GL_CLIP_PLANE0+i, buf); } + + GL11.glShadeModel(GL11.GL_SMOOTH); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glEnable(GL11.GL_LIGHTING); + + AnimatedModel animModel = door.getAnimatedModel(); + if(animModel != null){ + Animation anim = door.getAnim(); + bindTexture(door.getTextureForPart(te.getSkinIndex(), "")); + long time = System.currentTimeMillis(); + long startTime = te.state > 1 ? te.animStartTime : time; + boolean reverse = te.state == 1 || te.state == 2; + AnimationWrapper w = new AnimationWrapper(startTime, anim).onEnd(new EndResult(EndType.STAY)); + if(reverse) + w.reverse(); + animModel.controller.setAnim(w); + animModel.renderAnimated(System.currentTimeMillis()); + } else { + IModelCustomNamed model = door.getModel(); + + long ms = System.currentTimeMillis()-te.animStartTime; + float openTicks = MathHelper.clamp_float(te.state == 2 || te.state == 0 ? door.timeToOpen()*50-ms : ms, 0, door.timeToOpen()*50)*0.02F; + + for(String partName : model.getPartNames()) { + if(!door.doesRender(partName, false)) + continue; + + GL11.glPushMatrix(); + { + bindTexture(door.getTextureForPart(te.getSkinIndex(), partName)); + doPartTransform(door, partName, openTicks, false); + model.renderPart(partName); + + for(String innerPartName : door.getChildren(partName)) { + if(!door.doesRender(innerPartName, true)) + continue; + + GL11.glPushMatrix(); + { + bindTexture(door.getTextureForPart(te.getSkinIndex(), innerPartName)); + doPartTransform(door, innerPartName, openTicks, true); + model.renderPart(innerPartName); + } + GL11.glPopMatrix(); + } + } + GL11.glPopMatrix(); + } + } + + for(int i = 0; i < clip.length; i ++){ + GL11.glDisable(GL11.GL_CLIP_PLANE0+i); + } + + GL11.glDisable(GL11.GL_BLEND); + GL11.glShadeModel(GL11.GL_FLAT); } - for(int i = 0; i < clip.length; i ++){ - GL11.glDisable(GL11.GL_CLIP_PLANE0+i); - } - - GL11.glDisable(GL11.GL_BLEND); - GL11.glShadeModel(GL11.GL_FLAT); GL11.glPopMatrix(); } @@ -120,12 +131,9 @@ public class RenderDoorGeneric extends TileEntitySpecialRenderer { door.getOrigin(name, orig); door.getRotation(name, openTicks, rot); GL11.glTranslated(orig[0], orig[1], orig[2]); - if(rot[0] != 0) - GL11.glRotated(rot[0], 1, 0, 0); - if(rot[1] != 0) - GL11.glRotated(rot[1], 0, 1, 0); - if(rot[2] != 0) - GL11.glRotated(rot[2], 0, 0, 1); + if(rot[0] != 0) GL11.glRotated(rot[0], 1, 0, 0); + if(rot[1] != 0) GL11.glRotated(rot[1], 0, 1, 0); + if(rot[2] != 0) GL11.glRotated(rot[2], 0, 0, 1); GL11.glTranslated(-orig[0]+tran[0], -orig[1]+tran[1], -orig[2]+tran[2]); } } diff --git a/src/main/java/com/hbm/render/tileentity/door/IRenderDoors.java b/src/main/java/com/hbm/render/tileentity/door/IRenderDoors.java new file mode 100644 index 000000000..b531a7184 --- /dev/null +++ b/src/main/java/com/hbm/render/tileentity/door/IRenderDoors.java @@ -0,0 +1,10 @@ +package com.hbm.render.tileentity.door; + +import java.nio.DoubleBuffer; + +import com.hbm.tileentity.TileEntityDoorGeneric; + +public interface IRenderDoors { + + public void render(TileEntityDoorGeneric door, DoubleBuffer buf); +} diff --git a/src/main/java/com/hbm/tileentity/DoorDecl.java b/src/main/java/com/hbm/tileentity/DoorDecl.java index e7cf6981f..50fc9aa91 100644 --- a/src/main/java/com/hbm/tileentity/DoorDecl.java +++ b/src/main/java/com/hbm/tileentity/DoorDecl.java @@ -5,6 +5,7 @@ import com.hbm.animloader.Animation; import com.hbm.lib.Library; import com.hbm.main.ResourceManager; import com.hbm.render.loader.IModelCustomNamed; +import com.hbm.render.tileentity.door.IRenderDoors; import com.hbm.util.BobMathUtil; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @@ -1209,4 +1210,8 @@ public abstract class DoorDecl { f[2] = z; return f; } + + // keyframe animation system sneakily stitched into the door decl + public IRenderDoors getSEDNARenderer() { return null; } + public com.hbm.render.anim.HbmAnimations.Animation getSEDNAAnim(byte state) { return null; } } diff --git a/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java b/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java index e460bc08b..1154e4185 100644 --- a/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java +++ b/src/main/java/com/hbm/tileentity/TileEntityDoorGeneric.java @@ -8,6 +8,7 @@ import com.hbm.blocks.BlockDummyable; import com.hbm.blocks.generic.BlockDoorGeneric; import com.hbm.lib.Library; import com.hbm.main.MainRegistry; +import com.hbm.render.anim.HbmAnimations.Animation; import com.hbm.sound.AudioWrapper; import com.hbm.tileentity.machine.TileEntityLockableBase; import com.hbm.util.fauxpointtwelve.BlockPos; @@ -21,7 +22,12 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityDoorGeneric extends TileEntityLockableBase { +public class TileEntityDoorGeneric extends TileEntityLockableBase { + + public static byte STATE_CLOSED = 0; + public static byte STATE_OPEN = 1; + public static byte STATE_CLOSING = 2; + public static byte STATE_OPENING = 3; //0: closed, 1: open, 2: closing, 3: opening public byte state = 0; @@ -36,6 +42,8 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase { private AudioWrapper audio; private AudioWrapper audio2; + + public Animation currentAnimation; @Override public void updateEntity() { @@ -301,6 +309,10 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase { this.state = state; if(state > 1) animStartTime = System.currentTimeMillis(); + + if(state == STATE_OPENING || state == STATE_CLOSING) { + currentAnimation = this.doorType.getSEDNAAnim(state); + } } }