diff --git a/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java b/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java index c2e3ad5b..5afa34bf 100644 --- a/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java +++ b/src/main/java/crazypants/enderio/teleport/telepad/TeleportEntityRenderHandler.java @@ -1,9 +1,9 @@ package crazypants.enderio.teleport.telepad; -import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderLivingEvent; import org.lwjgl.opengl.GL11; @@ -11,30 +11,106 @@ import org.lwjgl.opengl.GL11; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import crazypants.render.RenderUtil; -public class TeleportEntityRenderHandler { +import static org.lwjgl.opengl.GL11.*; - private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); +public class TeleportEntityRenderHandler { @SubscribeEvent public void onEntityRender(RenderLivingEvent.Post event) { + EntityLivingBase e = event.entity; - float radius = e.width / 2.0F; - AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(-radius, 0, -radius, radius, e.height + 0.25, radius); + + if(e.getEntityData().getBoolean(TileTelePad.TELEPORTING_KEY)) { - GL11.glPushMatrix(); - GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); - GL11.glDepthMask(false); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glDisable(GL11.GL_LIGHTING); - GL11.glDisable(GL11.GL_CULL_FACE); - GL11.glDisable(GL11.GL_BLEND); - GL11.glTranslated(event.x, event.y, event.z); - bb = bb.expand(0.25, 0, 0.25); - GL11.glRotatef((e.ticksExisted + RenderUtil.getTimer().renderPartialTicks) * 4, 0, 1, 0); - if(event.entity.getEntityData().getBoolean(TileTelePad.TELEPORTING_KEY)) { - RenderGlobal.drawOutlinedBoundingBox(bb, 0xAA55FF); + float radius = e.width / 2.0F; + AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(-radius, 0, -radius, radius, e.height + 0.25, radius); + + glPushMatrix(); + glPushAttrib(GL_ALL_ATTRIB_BITS); + glDisable(GL_TEXTURE_2D); + glShadeModel(GL_SMOOTH); + glEnable(GL_BLEND); + OpenGlHelper.glBlendFunc(GL_SRC_ALPHA, GL_ONE, GL_ZERO, GL_ONE); + glDisable(GL_ALPHA_TEST); + glEnable(GL_CULL_FACE); + glDisable(GL_LIGHTING); + glDepthMask(false); + glTranslated(event.x, event.y, event.z); + bb = bb.expand(0.5, 0, 0.5); + float speed = (1 - (e.getEntityData().getFloat(TileTelePad.PROGRESS_KEY) * 0.7f)) * 100; + float rot = ((e.ticksExisted + RenderUtil.getTimer().renderPartialTicks) % speed) * (360 / speed); + System.out.println(rot); + glRotatef(rot, 0, 1, 0); + + double yMax = bb.maxY + 1; + + Tessellator tes = Tessellator.instance; + tes.startDrawingQuads(); + + colorBot(tes); + tes.addVertex(bb.minX, bb.minY, bb.minZ); + tes.addVertex(bb.minX, bb.minY, bb.maxZ); + colorTop(tes); + tes.addVertex(bb.minX, yMax, bb.maxZ); + tes.addVertex(bb.minX, yMax, bb.minZ); + colorBot(tes); + tes.addVertex(bb.minX, bb.minY, bb.maxZ); + tes.addVertex(bb.minX, bb.minY, bb.minZ); + colorTop(tes); + tes.addVertex(bb.minX, yMax, bb.minZ); + tes.addVertex(bb.minX, yMax, bb.maxZ); + + colorBot(tes); + tes.addVertex(bb.maxX, bb.minY, bb.minZ); + tes.addVertex(bb.maxX, bb.minY, bb.maxZ); + colorTop(tes); + tes.addVertex(bb.maxX, yMax, bb.maxZ); + tes.addVertex(bb.maxX, yMax, bb.minZ); + colorBot(tes); + tes.addVertex(bb.maxX, bb.minY, bb.maxZ); + tes.addVertex(bb.maxX, bb.minY, bb.minZ); + colorTop(tes); + tes.addVertex(bb.maxX, yMax, bb.minZ); + tes.addVertex(bb.maxX, yMax, bb.maxZ); + + colorBot(tes); + tes.addVertex(bb.minX, bb.minY, bb.minZ); + tes.addVertex(bb.maxX, bb.minY, bb.minZ); + colorTop(tes); + tes.addVertex(bb.maxX, yMax, bb.minZ); + tes.addVertex(bb.minX, yMax, bb.minZ); + colorBot(tes); + tes.addVertex(bb.maxX, bb.minY, bb.minZ); + tes.addVertex(bb.minX, bb.minY, bb.minZ); + colorTop(tes); + tes.addVertex(bb.minX, yMax, bb.minZ); + tes.addVertex(bb.maxX, yMax, bb.minZ); + + colorBot(tes); + tes.addVertex(bb.minX, bb.minY, bb.maxZ); + tes.addVertex(bb.maxX, bb.minY, bb.maxZ); + colorTop(tes); + tes.addVertex(bb.maxX, yMax, bb.maxZ); + tes.addVertex(bb.minX, yMax, bb.maxZ); + colorBot(tes); + tes.addVertex(bb.maxX, bb.minY, bb.maxZ); + tes.addVertex(bb.minX, bb.minY, bb.maxZ); + colorTop(tes); + tes.addVertex(bb.minX, yMax, bb.maxZ); + tes.addVertex(bb.maxX, yMax, bb.maxZ); + + tes.draw(); + + GL11.glPopAttrib(); + GL11.glPopMatrix(); } - GL11.glPopAttrib(); - GL11.glPopMatrix(); + } + + private void colorBot(Tessellator tes) { + tes.setColorRGBA(100, 100, 255, 100); + } + + private void colorTop(Tessellator tes) { + tes.setColorRGBA(150, 150, 255, 0); } } diff --git a/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java b/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java index be7fa9e8..a5895659 100644 --- a/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java +++ b/src/main/java/crazypants/enderio/teleport/telepad/TileTelePad.java @@ -41,7 +41,7 @@ import crazypants.util.IProgressTile; import crazypants.util.Util; public class TileTelePad extends TileTravelAnchor implements IInternalPowerReceiver, ITelePad, IProgressTile { - + private boolean inNetwork; private EnumSet connections = EnumSet.noneOf(ForgeDirection.class); @@ -63,6 +63,9 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei private static final ResourceLocation activeRes = AbstractMachineEntity.getSoundFor("telepad.active"); private MachineSound activeSound = null; + + public static final String TELEPORTING_KEY = "eio:teleporting"; + public static final String PROGRESS_KEY = "teleportprogress"; @Override public void updateEntity() { @@ -83,6 +86,7 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei } activeSound.setVolume(Math.min(activeSound.getVolume() + 0.1f, 0.5f)); activeSound.setPitch(1 + getProgress()); + updateQueuedEntities(); } else if(!active() && activeSound != null) { if(activeSound.getVolume() > 0) { activeSound.setVolume(activeSound.getVolume() - 0.1f); @@ -123,14 +127,20 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei } private void updateQueuedEntities() { - List toRemove = Lists.newArrayList(); - for (Entity e : toTeleport) { - if(!isEntityInRange(e)) { - toRemove.add(e); + if(worldObj.isRemote) { + if(active()) { + getCurrentTarget().getEntityData().setFloat(PROGRESS_KEY, getProgress()); + } + } else { + List toRemove = Lists.newArrayList(); + for (Entity e : toTeleport) { + if(!isEntityInRange(e)) { + toRemove.add(e); + } + } + for (Entity e : toRemove) { + dequeueTeleport(e); } - } - for (Entity e : toRemove) { - dequeueTeleport(e); } } @@ -273,8 +283,8 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei return (int) (getProgress() * scale); } - private int getPowerForTeleport() { - return new BlockCoord(this).distance(target) * 1000; + private int calculateTeleportPower() { + return this.maxPower = new BlockCoord(this).distance(target) * 1000; } public boolean active() { @@ -375,7 +385,6 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei if(inNetwork()) { if(isMaster()) { this.target = coords; - this.maxPower = getPowerForTeleport(); } else { this.master.setCoords(coords); } @@ -423,9 +432,8 @@ public class TileTelePad extends TileTravelAnchor implements IInternalPowerRecei return AxisAlignedBB.getBoundingBox(xCoord - 1, yCoord, zCoord - 1, xCoord + 2, yCoord + 3, zCoord + 2); } - public static final String TELEPORTING_KEY = "eio:teleporting"; - void enqueueTeleport(Entity entity) { + calculateTeleportPower(); entity.getEntityData().setBoolean(TELEPORTING_KEY, true); toTeleport.add(entity); if(entity.worldObj.isRemote) {