From 8d4cf31c5fa874876a3dcbefdc0826b08f8d807d Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Mon, 8 Jun 2015 17:56:06 +0100 Subject: Added the ritual sound file, re-wroked the eye following algorithm (thank you domi so so much <3) --- .../jewelrycraft/curses/CursePentagram.java | 208 +++--- .../jewelrycraft/model/ModelShadowEye.java | 295 ++++---- .../tileentity/TileEntityShadowEye.java | 792 ++++++++++----------- .../renders/TileEntityShadowEyeRender.java | 204 +++--- 4 files changed, 747 insertions(+), 752 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/darkknight/jewelrycraft/curses/CursePentagram.java b/src/main/java/darkknight/jewelrycraft/curses/CursePentagram.java index c6057d0..f59e92e 100644 --- a/src/main/java/darkknight/jewelrycraft/curses/CursePentagram.java +++ b/src/main/java/darkknight/jewelrycraft/curses/CursePentagram.java @@ -1,104 +1,104 @@ -package darkknight.jewelrycraft.curses; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.texture.TextureManager; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.SharedMonsterAttributes; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.DamageSource; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; -import net.minecraft.world.biome.BiomeGenBase; -import net.minecraftforge.client.event.RenderHandEvent; -import net.minecraftforge.client.event.RenderPlayerEvent; -import org.lwjgl.opengl.GL11; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import darkknight.jewelrycraft.api.Curse; -import darkknight.jewelrycraft.config.ConfigHandler; -import darkknight.jewelrycraft.damage.DamageSourceList; -import darkknight.jewelrycraft.util.Variables; - -public class CursePentagram extends Curse -{ - float rot = 0F; - - public CursePentagram(String name, int txtID, String pack) - { - super(name, txtID, pack); - } - - @Override - public void action(World world, EntityPlayer player) - { - // FMLInterModComms.sendMessage(modId, key, value); - // GameRegistry.findItem("Botania", "flower"); - // FMLInterModComms.fetchRuntimeMessages(forMod) - if (!world.isRemote){ - for(Object entity: world.getEntitiesWithinAABBExcludingEntity(player, AxisAlignedBB.getBoundingBox(player.boundingBox.minX - 0.5F, player.boundingBox.minY, player.boundingBox.minZ - 0.5F, player.boundingBox.maxX + 0.5F, player.boundingBox.maxY, player.boundingBox.maxZ + 0.5F))){ - if (entity instanceof EntityLivingBase && rand.nextInt(40) == 0){ - ((EntityLivingBase)entity).attackEntityFrom(DamageSourceList.shadows, 2f); - if (player.shouldHeal()) player.heal(2F); - else player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(player.getMaxHealth() + 2f); - } - } - } - } - - @Override - public void attackedByPlayerAction(World world, EntityPlayer player, Entity target) - {} - - @Override - public void playerRender(EntityPlayer player, RenderPlayerEvent.Specials.Post event) - {} - - @SideOnly (Side.CLIENT) - public void playerHandRender(EntityPlayer player, RenderHandEvent event) - { - ResourceLocation PENTAGRAM_TEXTURE = new ResourceLocation(Variables.MODID, "textures/gui/" + getTexturePack() + ".png"); - GL11.glPushMatrix(); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_SRC_COLOR); - Tessellator tessellator = Tessellator.instance; - TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); - texturemanager.bindTexture(PENTAGRAM_TEXTURE); - GL11.glRotatef(rot, 0F, 1F, 0F); - GL11.glTranslatef(-0.8F, (player.isSneaking() ? 0.1625F : 0F) + -1.6F, -0.8F); - GL11.glRotatef(90F, 1F, 0F, 0F); - GL11.glScalef(0.05F, 0.05F, 0.05F); - rot += 3F; - if (rot > 360F) rot = 0F; - float f = 0.00390625F; - float f1 = 0.00390625F; - int x = 0; - int y = 0; - int u = 32 * 7; - int v = 0; - int width = 32; - int height = 32; - tessellator.startDrawingQuads(); - tessellator.addVertexWithUV((double)(x + 0), (double)(y + height), (double)0, (double)((float)(u + 0) * f), (double)((float)(v + height) * f1)); - tessellator.addVertexWithUV((double)(x + width), (double)(y + height), (double)0, (double)((float)(u + width) * f), (double)((float)(v + height) * f1)); - tessellator.addVertexWithUV((double)(x + width), (double)(y + 0), (double)0, (double)((float)(u + width) * f), (double)((float)(v + 0) * f1)); - tessellator.addVertexWithUV((double)(x + 0), (double)(y + 0), (double)0, (double)((float)(u + 0) * f), (double)((float)(v + 0) * f1)); - tessellator.draw(); - GL11.glDisable(GL11.GL_BLEND); - GL11.glPopMatrix(); - } - - public String getDescription() - { - return StatCollector.translateToLocal("curse." + Variables.MODID + ".pentagram.description"); - } - - @Override - public boolean canCurseBeActivated(World world) - { - return ConfigHandler.CURSE_PENTAGRAM; - } -} +package darkknight.jewelrycraft.curses; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.SharedMonsterAttributes; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.DamageSource; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; +import net.minecraft.world.biome.BiomeGenBase; +import net.minecraftforge.client.event.RenderHandEvent; +import net.minecraftforge.client.event.RenderPlayerEvent; +import org.lwjgl.opengl.GL11; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.api.Curse; +import darkknight.jewelrycraft.config.ConfigHandler; +import darkknight.jewelrycraft.damage.DamageSourceList; +import darkknight.jewelrycraft.util.Variables; + +public class CursePentagram extends Curse +{ + float rot = 0F; + + public CursePentagram(String name, int txtID, String pack) + { + super(name, txtID, pack); + } + + @Override + public void action(World world, EntityPlayer player) + { + // FMLInterModComms.sendMessage(modId, key, value); + // GameRegistry.findItem("Botania", "flower"); + // FMLInterModComms.fetchRuntimeMessages(forMod) + if (!world.isRemote){ + for(Object entity: world.getEntitiesWithinAABBExcludingEntity(player, AxisAlignedBB.getBoundingBox(player.boundingBox.minX - 0.5F, player.boundingBox.minY, player.boundingBox.minZ - 0.5F, player.boundingBox.maxX + 0.5F, player.boundingBox.maxY, player.boundingBox.maxZ + 0.5F))){ + if (entity instanceof EntityLivingBase && rand.nextInt(40) == 0){ + ((EntityLivingBase)entity).attackEntityFrom(DamageSourceList.shadows, 2f); + if (player.shouldHeal()) player.heal(2F); + else player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(player.getMaxHealth() + 2f); + } + } + } + } + + @Override + public void attackedByPlayerAction(World world, EntityPlayer player, Entity target) + {} + + @Override + public void playerRender(EntityPlayer player, RenderPlayerEvent.Specials.Post event) + {} + + @SideOnly (Side.CLIENT) + public void playerHandRender(EntityPlayer player, RenderHandEvent event) + { + ResourceLocation PENTAGRAM_TEXTURE = new ResourceLocation(Variables.MODID, "textures/gui/" + getTexturePack() + ".png"); + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_SRC_COLOR); + Tessellator tessellator = Tessellator.instance; + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + texturemanager.bindTexture(PENTAGRAM_TEXTURE); + GL11.glRotatef(rot, 0F, 1F, 0F); + GL11.glTranslatef(-0.8F, (player.isSneaking() ? 0.1625F : 0F) + -1.6F, -0.8F); + GL11.glRotatef(90F, 1F, 0F, 0F); + GL11.glScalef(0.05F, 0.05F, 0.05F); + rot += 3F; + if (rot > 360F) rot = 0F; + float f = 0.00390625F; + float f1 = 0.00390625F; + int x = 0; + int y = 0; + int u = 32 * 7; + int v = 0; + int width = 32; + int height = 32; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double)(x + 0), (double)(y + height), (double)0, (double)((float)(u + 0) * f), (double)((float)(v + height) * f1)); + tessellator.addVertexWithUV((double)(x + width), (double)(y + height), (double)0, (double)((float)(u + width) * f), (double)((float)(v + height) * f1)); + tessellator.addVertexWithUV((double)(x + width), (double)(y + 0), (double)0, (double)((float)(u + width) * f), (double)((float)(v + 0) * f1)); + tessellator.addVertexWithUV((double)(x + 0), (double)(y + 0), (double)0, (double)((float)(u + 0) * f), (double)((float)(v + 0) * f1)); + tessellator.draw(); + GL11.glDisable(GL11.GL_BLEND); + GL11.glPopMatrix(); + } + + public String getDescription() + { + return StatCollector.translateToLocal("curse." + Variables.MODID + ".pentagram.description"); + } + + @Override + public boolean canCurseBeActivated(World world) + { + return ConfigHandler.CURSE_PENTAGRAM; + } +} diff --git a/src/main/java/darkknight/jewelrycraft/model/ModelShadowEye.java b/src/main/java/darkknight/jewelrycraft/model/ModelShadowEye.java index e396f72..e2f339d 100644 --- a/src/main/java/darkknight/jewelrycraft/model/ModelShadowEye.java +++ b/src/main/java/darkknight/jewelrycraft/model/ModelShadowEye.java @@ -5,158 +5,157 @@ // - ZeuX package darkknight.jewelrycraft.model; +import org.lwjgl.opengl.GL11; + import net.minecraft.client.model.ModelBase; import net.minecraft.client.model.ModelRenderer; import net.minecraft.entity.Entity; +import net.minecraft.util.Vec3; + +public class ModelShadowEye extends ModelBase { + // fields + ModelRenderer Eye; + ModelRenderer Platform1; + ModelRenderer Platform2; + ModelRenderer Atachement1; + ModelRenderer Atachement2; + ModelRenderer Cable1; + ModelRenderer Cable2; + ModelRenderer Cable3; + ModelRenderer Cable4; + float field_82221_e, field_82220_d; -public class ModelShadowEye extends ModelBase -{ - // fields - ModelRenderer Eye; - ModelRenderer Platform1; - ModelRenderer Platform2; - ModelRenderer Atachement1; - ModelRenderer Atachement2; - ModelRenderer Cable1; - ModelRenderer Cable2; - ModelRenderer Cable3; - ModelRenderer Cable4; - float field_82221_e, field_82220_d; - - /** + /** * */ - public ModelShadowEye() - { - textureWidth = 64; - textureHeight = 32; - Eye = new ModelRenderer(this, 0, 0); - Eye.addBox(-3.5F, -3.5F, -3.5F, 7, 7, 7); - Eye.setRotationPoint(0F, 17.5F, 0F); - Eye.setTextureSize(64, 32); - Eye.mirror = true; - setRotation(Eye, 0F, 0F, 0F); - Platform1 = new ModelRenderer(this, 0, 14); - Platform1.addBox(0F, 0F, 0F, 2, 2, 16); - Platform1.setRotationPoint(-1F, 11F, -8F); - Platform1.setTextureSize(64, 32); - Platform1.mirror = true; - setRotation(Platform1, 0F, 0F, 0F); - Platform2 = new ModelRenderer(this, 0, 14); - Platform2.addBox(0F, 0F, 0F, 2, 2, 16); - Platform2.setRotationPoint(-1F, 22F, -8F); - Platform2.setTextureSize(64, 32); - Platform2.mirror = true; - setRotation(Platform2, 0F, 0F, 0F); - Atachement1 = new ModelRenderer(this, 38, 0); - Atachement1.addBox(0F, 0F, 0F, 2, 2, 5); - Atachement1.setRotationPoint(-1F, 17F, -12F); - Atachement1.setTextureSize(64, 32); - Atachement1.mirror = true; - setRotation(Atachement1, 0F, 0F, 0F); - Atachement2 = new ModelRenderer(this, 38, 0); - Atachement2.addBox(0F, 0F, 0F, 2, 2, 5); - Atachement2.setRotationPoint(-1F, 17F, 7F); - Atachement2.setTextureSize(64, 32); - Atachement2.mirror = true; - setRotation(Atachement2, 0F, 0F, 0F); - Cable1 = new ModelRenderer(this, 29, 0); - Cable1.addBox(0F, 0F, 0F, 2, 6, 2); - Cable1.setRotationPoint(-1F, 12F, 4.2F); - Cable1.setTextureSize(64, 32); - Cable1.mirror = true; - setRotation(Cable1, 0.2617994F, 0F, 0F); - Cable2 = new ModelRenderer(this, 29, 0); - Cable2.addBox(0F, 0F, -1F, 2, 6, 2); - Cable2.setRotationPoint(-1F, 12F, -5.2F); - Cable2.setTextureSize(64, 32); - Cable2.mirror = true; - setRotation(Cable2, -0.2617994F, 0F, 0F); - Cable3 = new ModelRenderer(this, 29, 0); - Cable3.addBox(0F, 0F, 0F, 2, 6, 2); - Cable3.setRotationPoint(-1F, 23F, -3.9F); - Cable3.setTextureSize(64, 32); - Cable3.mirror = true; - setRotation(Cable3, -2.792527F, 0F, 0F); - Cable4 = new ModelRenderer(this, 29, 0); - Cable4.addBox(0F, 0F, -1F, 2, 6, 2); - Cable4.setRotationPoint(-1F, 23F, 4.9F); - Cable4.setTextureSize(64, 32); - Cable4.mirror = true; - setRotation(Cable4, 2.792527F, 0F, 0F); - } - - /** - * @param entity - * @param f - * @param f1 - * @param f2 - * @param f3 - * @param f4 - * @param f5 - */ - @Override - public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) - { - Eye.render(f5); - Platform1.render(f5); - Platform2.render(f5); - Atachement1.render(f5); - Atachement2.render(f5); - Cable1.render(f5); - Cable2.render(f5); - Cable3.render(f5); - Cable4.render(f5); - if (entity != null){ - float x = (float)(f - entity.posX); - float y = (float)(f1 - entity.posY); - float z = (float)(f2 - entity.posZ); - if (f4 == 4){ - if (f3 == 0) if (z < 0){ - Eye.rotateAngleY = (float)Math.asin(x / Math.sqrt(x * x + z * z)) + 135f; - Eye.rotateAngleZ = (float)-Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - }else{ - Eye.rotateAngleY = (float)-Math.asin(x / Math.sqrt(x * x + z * z)); - Eye.rotateAngleZ = (float)Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - } - if (f3 == 1) if (x < 0){ - Eye.rotateAngleY = (float)-Math.asin(z / Math.sqrt(x * x + z * z)); - Eye.rotateAngleZ = (float)Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - }else{ - Eye.rotateAngleY = (float)Math.asin(z / Math.sqrt(x * x + z * z)) + 135f; - Eye.rotateAngleZ = (float)-Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - } - if (f3 == 2) if (z < 0){ - Eye.rotateAngleY = (float)Math.asin(x / Math.sqrt(x * x + z * z)); - Eye.rotateAngleZ = (float)Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - }else{ - Eye.rotateAngleY = (float)-Math.asin(x / Math.sqrt(x * x + z * z)) + 135f; - Eye.rotateAngleZ = (float)-Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - } - if (f3 == 3) if (x < 0){ - Eye.rotateAngleY = (float)-Math.asin(z / Math.sqrt(x * x + z * z)) + 135f; - Eye.rotateAngleZ = (float)-Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - }else{ - Eye.rotateAngleY = (float)Math.asin(z / Math.sqrt(x * x + z * z)); - Eye.rotateAngleZ = (float)Math.asin((y + 1) / Math.sqrt(y * y + 4 * 4)); - } - }else{ - Eye.rotateAngleY = 0f; - Eye.rotateAngleZ = 0f; - } - } - } - - /** - * @param model - * @param x - * @param y - * @param z - */ - private void setRotation(ModelRenderer model, float x, float y, float z) - { - model.rotateAngleX = x; - model.rotateAngleY = y; - model.rotateAngleZ = z; - } + public ModelShadowEye() { + textureWidth = 64; + textureHeight = 32; + Eye = new ModelRenderer(this, 0, 0); + Eye.addBox(-3.5F, -3.5F, -3.5F, 7, 7, 7); + Eye.setRotationPoint(0F, 17.5F, 0F); + Eye.setTextureSize(64, 32); + Eye.mirror = true; + setRotation(Eye, 0F, 0F, 0F); + Platform1 = new ModelRenderer(this, 0, 14); + Platform1.addBox(0F, 0F, 0F, 2, 2, 16); + Platform1.setRotationPoint(-1F, 11F, -8F); + Platform1.setTextureSize(64, 32); + Platform1.mirror = true; + setRotation(Platform1, 0F, 0F, 0F); + Platform2 = new ModelRenderer(this, 0, 14); + Platform2.addBox(0F, 0F, 0F, 2, 2, 16); + Platform2.setRotationPoint(-1F, 22F, -8F); + Platform2.setTextureSize(64, 32); + Platform2.mirror = true; + setRotation(Platform2, 0F, 0F, 0F); + Atachement1 = new ModelRenderer(this, 38, 0); + Atachement1.addBox(0F, 0F, 0F, 2, 2, 5); + Atachement1.setRotationPoint(-1F, 17F, -12F); + Atachement1.setTextureSize(64, 32); + Atachement1.mirror = true; + setRotation(Atachement1, 0F, 0F, 0F); + Atachement2 = new ModelRenderer(this, 38, 0); + Atachement2.addBox(0F, 0F, 0F, 2, 2, 5); + Atachement2.setRotationPoint(-1F, 17F, 7F); + Atachement2.setTextureSize(64, 32); + Atachement2.mirror = true; + setRotation(Atachement2, 0F, 0F, 0F); + Cable1 = new ModelRenderer(this, 29, 0); + Cable1.addBox(0F, 0F, 0F, 2, 6, 2); + Cable1.setRotationPoint(-1F, 12F, 4.2F); + Cable1.setTextureSize(64, 32); + Cable1.mirror = true; + setRotation(Cable1, 0.2617994F, 0F, 0F); + Cable2 = new ModelRenderer(this, 29, 0); + Cable2.addBox(0F, 0F, -1F, 2, 6, 2); + Cable2.setRotationPoint(-1F, 12F, -5.2F); + Cable2.setTextureSize(64, 32); + Cable2.mirror = true; + setRotation(Cable2, -0.2617994F, 0F, 0F); + Cable3 = new ModelRenderer(this, 29, 0); + Cable3.addBox(0F, 0F, 0F, 2, 6, 2); + Cable3.setRotationPoint(-1F, 23F, -3.9F); + Cable3.setTextureSize(64, 32); + Cable3.mirror = true; + setRotation(Cable3, -2.792527F, 0F, 0F); + Cable4 = new ModelRenderer(this, 29, 0); + Cable4.addBox(0F, 0F, -1F, 2, 6, 2); + Cable4.setRotationPoint(-1F, 23F, 4.9F); + Cable4.setTextureSize(64, 32); + Cable4.mirror = true; + setRotation(Cable4, 2.792527F, 0F, 0F); + } + + /** + * @param entity + * @param f + * @param f1 + * @param f2 + * @param f3 + * @param f4 + * @param f5 + */ + @Override + public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) { + Platform1.render(f5); + Platform2.render(f5); + Atachement1.render(f5); + Atachement2.render(f5); + Cable1.render(f5); + Cable2.render(f5); + Cable3.render(f5); + Cable4.render(f5); + if(f3 == 0) GL11.glRotatef(90F, 0F, -1F, 0F); + else if(f3 == 1) GL11.glRotatef(180F, 0F, 1F, 0F); + else if(f3 == 2) GL11.glRotatef(90F, 0F, 1F, 0F); + Eye.render(f5); + if (f4 == 4) + { + Eye.rotateAngleX = f; + Eye.rotateAngleY = f1; + Eye.rotateAngleZ = f2; + } + else + { + Eye.rotateAngleX = 0F; + Eye.rotateAngleY = 0F; + Eye.rotateAngleZ = 0F; + } + } + + public static float[] getRotation(double posX1, double posY1, double posZ1, double posX2, double posY2, double posZ2) + { + float[] rotation = new float[2]; + double diffX = posX2 - posX1; + double diffZ = posZ2 - posZ1; + double diffY = posY2 - posY1; + double dist = Math.sqrt(diffZ * diffZ + diffX * diffX); + double pitch = -Math.toDegrees(Math.atan(diffY / dist)); + rotation[1] = (float) pitch; + double yaw = 0; + if (diffZ >= 0.0D && diffX >= 0.0D) { + yaw = Math.toDegrees(-Math.atan(diffX / diffZ)); + } else if (diffZ >= 0.0D && diffX <= 0.0D) { + yaw = Math.toDegrees(-Math.atan(diffX / diffZ)); + } else if (diffZ <= 0.0D && diffX >= 0.0D) { + yaw = -90D + Math.toDegrees(Math.atan(diffZ / diffX)); + } else if (diffZ <= 0.0D && diffX <= 0.0D) { + yaw = 90D + Math.toDegrees(Math.atan(diffZ / diffX)); + } + rotation[0] = (float) yaw; + return rotation; + } + + /** + * @param model + * @param x + * @param y + * @param z + */ + private void setRotation(ModelRenderer model, float x, float y, float z) { + model.rotateAngleX = x; + model.rotateAngleY = y; + model.rotateAngleZ = z; + } } diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java index 887b17f..cac74e2 100644 --- a/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java +++ b/src/main/java/darkknight/jewelrycraft/tileentity/TileEntityShadowEye.java @@ -1,400 +1,392 @@ -package darkknight.jewelrycraft.tileentity; - -import java.util.ArrayList; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.NetworkManager; -import net.minecraft.network.Packet; -import net.minecraft.network.play.server.S35PacketUpdateTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.EnumChatFormatting; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StatCollector; -import net.minecraft.world.World; -import darkknight.jewelrycraft.block.BlockHandPedestal; -import darkknight.jewelrycraft.block.BlockList; -import darkknight.jewelrycraft.config.ConfigHandler; -import darkknight.jewelrycraft.particles.EntityShadowsFX; -import darkknight.jewelrycraft.util.JewelryNBT; -import darkknight.jewelrycraft.util.JewelrycraftUtil; -import darkknight.jewelrycraft.util.PlayerUtils; -import darkknight.jewelrycraft.util.Variables; - -public class TileEntityShadowEye extends TileEntity -{ - public int opening, timer, t = 20; - public boolean active, shouldAddData; - public ArrayList pedestalItems = new ArrayList(); - ResourceLocation particleTexture = new ResourceLocation(Variables.MODID, "textures/particle/shadows.png"); - public EntityPlayer target; - - public TileEntityShadowEye() - { - opening = 1; - timer = 20; - active = false; - } - - /** - * @param nbt - */ - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - nbt.setInteger("opening", opening); - nbt.setInteger("timer", timer); - nbt.setBoolean("active", active); - nbt.setBoolean("shouldAddData", shouldAddData); - } - - /** - * @param nbt - */ - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - opening = nbt.getInteger("opening"); - timer = nbt.getInteger("timer"); - active = nbt.getBoolean("active"); - shouldAddData = nbt.getBoolean("shouldAddData"); - } - - /** - * - */ - @Override - public void updateEntity() - { - super.updateEntity(); - boolean valid = isValidStructure(worldObj, xCoord, yCoord, zCoord, blockMetadata); - boolean canStartRitual = valid && ((TileEntityHandPedestal)worldObj.getTileEntity(xCoord, yCoord - 3, zCoord)).heldItemStack != null && getNumberOfItems(worldObj, xCoord, yCoord, zCoord) > 0; - if (active){ - timer--; - if (canStartRitual && canChangePedestals(worldObj, xCoord, yCoord, zCoord) && opening == 4) changePedestals(worldObj, xCoord, yCoord, zCoord); - } - if (active && target != null && this.getDistanceFrom(target.posX, target.posY, target.posZ) > 30D){ - active = false; - timer = -1; - shouldAddData = false; - revertPedestals(worldObj, xCoord, yCoord, zCoord); - } - if (opening == 4 && timer <= 0) active = false; - if (!active && timer <= 0 && opening != 1){ - if (t > 0) t--; - if (t <= 0){ - opening--; - t = 20; - } - } - if (opening == 2 && timer <= 0 && t == 10 && shouldAddData){ - addData(worldObj, xCoord, yCoord, zCoord); - TileEntityHandPedestal target = (TileEntityHandPedestal)worldObj.getTileEntity(xCoord, yCoord - 3, zCoord); - if (target != null && target.getHeldItemStack() != null) JewelryNBT.addModifiers(target.getHeldItemStack(), pedestalItems); - revertPedestals(worldObj, xCoord, yCoord, zCoord); - } - if (active && timer <= 0){ - if (opening < 4){ - opening++; - timer = 20; - } - if (canStartRitual && opening == 4) timer = ConfigHandler.RITUAL_TIME; - else if (!canStartRitual){ - shouldAddData = false; - active = false; - timer = -1; - if (!worldObj.isRemote){ - JewelrycraftUtil.addCursePoints(target, 50); - target.addChatMessage(new ChatComponentText(EnumChatFormatting.BLACK + "The Shadows don't like to be disturbed for no reason!")); - target.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_PURPLE + "You feel a strange aura encumbering you.")); - } - } - } - for(Object player: worldObj.getEntitiesWithinAABB(EntityPlayer.class, getRenderBoundingBox().expand(10D, 10D, 10D))) - if (player != null){ - NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag((EntityPlayer)player, Variables.MODID); - persistTag.setBoolean("nearStartedRitual", false); - } - if (active && opening == 4){ - float din = 6F; - int i = Minecraft.getMinecraft().gameSettings.particleSetting; - for(float x = -din; x <= din; x += 0.2F) - for(float z = -din; z <= din; z += 0.2F) - if (x * x + z * z >= din * din - 1 && x * x + z * z <= din * din + 1) Minecraft.getMinecraft().effectRenderer.addEffect(new EntityShadowsFX(worldObj, xCoord + x + 0.5F, yCoord - 0.5F, zCoord + z + 0.5F, 15F, 0.04F - 0.01F * i, particleTexture)); - for(int l = 0; l <= 100 - i*45; l++) - worldObj.spawnParticle("depthsuspend", xCoord + 6.5F - worldObj.rand.nextInt(12) - worldObj.rand.nextFloat(), yCoord - 2F + worldObj.rand.nextInt(9) - worldObj.rand.nextFloat(), zCoord + 6.5F - worldObj.rand.nextInt(12) - worldObj.rand.nextFloat(), 0, 0, 0); - } - } - - /** - * @param world - * @param x - * @param y - * @param z - * @param metadata - * @return - */ - public boolean isValidStructure(World world, int x, int y, int z, int metadata) - { - if (world.getBlockMetadata(x, y, z) == 0 || world.getBlockMetadata(x, y, z) == 2){ - // Layers from top to bottom - // 1st Layer - if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) return false; - if (world.getBlock(x + 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x + 1, y + 1, z) != 5) return false; - if (world.getBlock(x - 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x - 1, y + 1, z) != 5) return false; - // 2nd Layer - if (world.getBlock(x + 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 2, y, z) != 1) return false; - if (world.getBlock(x + 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 1, y, z) != 4) return false; - if (world.getBlock(x - 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 1, y, z) != 5) return false; - if (world.getBlock(x - 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 2, y, z) != 0) return false; - // 3rd Layer - if (world.getBlock(x + 2, y - 1, z) != Blocks.stonebrick) return false; - if (world.getBlock(x - 2, y - 1, z) != Blocks.stonebrick) return false; - // 4th Layer - if (world.getBlock(x + 2, y - 2, z) != Blocks.stonebrick) return false; - if (world.getBlock(x - 2, y - 2, z) != Blocks.stonebrick) return false; - // 5th Layer - if (world.getBlock(x + 2, y - 3, z) != Blocks.stonebrick) return false; - if (world.getBlock(x - 2, y - 3, z) != Blocks.stonebrick) return false; - }else if (world.getBlockMetadata(x, y, z) == 1 || world.getBlockMetadata(x, y, z) == 3){ - // Layers from top to bottom - // 1st Layer - if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) return false; - if (world.getBlock(x, y + 1, z + 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z + 1) != 5) return false; - if (world.getBlock(x, y + 1, z - 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z - 1) != 5) return false; - // 2nd Layer - if (world.getBlock(x, y, z + 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 2) != 3) return false; - if (world.getBlock(x, y, z + 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 1) != 6) return false; - if (world.getBlock(x, y, z - 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 1) != 7) return false; - if (world.getBlock(x, y, z - 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 2) != 2) return false; - // 3rd Layer - if (world.getBlock(x, y - 1, z + 2) != Blocks.stonebrick) return false; - if (world.getBlock(x, y - 1, z - 2) != Blocks.stonebrick) return false; - // 4th Layer - if (world.getBlock(x, y - 2, z + 2) != Blocks.stonebrick) return false; - if (world.getBlock(x, y - 2, z - 2) != Blocks.stonebrick) return false; - // 5th Layer - if (world.getBlock(x, y - 3, z + 2) != Blocks.stonebrick) return false; - if (world.getBlock(x, y - 3, z - 2) != Blocks.stonebrick) return false; - } - // 3rd Layer - if (world.getBlock(x - 4, y - 1, z - 4) != BlockList.shadowBlock) return false; - if (world.getBlock(x - 4, y - 1, z + 4) != BlockList.shadowBlock) return false; - if (world.getBlock(x + 4, y - 1, z - 4) != BlockList.shadowBlock) return false; - if (world.getBlock(x + 4, y - 1, z + 4) != BlockList.shadowBlock) return false; - // 4th Layer - if (world.getBlock(x - 4, y - 2, z - 4) != Blocks.stonebrick) return false; - if (world.getBlock(x - 4, y - 2, z + 4) != Blocks.stonebrick) return false; - if (world.getBlock(x + 4, y - 2, z - 4) != Blocks.stonebrick) return false; - if (world.getBlock(x + 4, y - 2, z + 4) != Blocks.stonebrick) return false; - // 5th Layer - // Pillars - if (world.getBlock(x - 4, y - 3, z - 4) != Blocks.stonebrick) return false; - if (world.getBlock(x - 4, y - 3, z + 4) != Blocks.stonebrick) return false; - if (world.getBlock(x + 4, y - 3, z - 4) != Blocks.stonebrick) return false; - if (world.getBlock(x + 4, y - 3, z + 4) != Blocks.stonebrick) return false; - // Pedestals - if (!(world.getBlock(x, y - 3, z) instanceof BlockHandPedestal)) return false; - if (world.getBlock(x - 4, y - 3, z + 2) != BlockList.handPedestal || world.getBlockMetadata(x - 4, y - 3, z + 2) != 1) return false; - if (world.getBlock(x - 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x - 5, y - 3, z) != 2) return false; - if (world.getBlock(x - 4, y - 3, z - 2) != BlockList.handPedestal || world.getBlockMetadata(x - 4, y - 3, z - 2) != 3) return false; - if (world.getBlock(x - 2, y - 3, z - 4) != BlockList.handPedestal || world.getBlockMetadata(x - 2, y - 3, z - 4) != 3) return false; - if (world.getBlock(x, y - 3, z - 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z - 5) != 4) return false; - if (world.getBlock(x + 2, y - 3, z - 4) != BlockList.handPedestal || world.getBlockMetadata(x + 2, y - 3, z - 4) != 5) return false; - if (world.getBlock(x + 4, y - 3, z - 2) != BlockList.handPedestal || world.getBlockMetadata(x + 4, y - 3, z - 2) != 5) return false; - if (world.getBlock(x + 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x + 5, y - 3, z) != 6) return false; - if (world.getBlock(x + 4, y - 3, z + 2) != BlockList.handPedestal || world.getBlockMetadata(x + 4, y - 3, z + 2) != 7) return false; - if (world.getBlock(x + 2, y - 3, z + 4) != BlockList.handPedestal || world.getBlockMetadata(x + 2, y - 3, z + 4) != 7) return false; - if (world.getBlock(x, y - 3, z + 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z + 5) != 0) return false; - if (world.getBlock(x - 2, y - 3, z + 4) != BlockList.handPedestal || world.getBlockMetadata(x - 2, y - 3, z + 4) != 1) return false; - return true; - } - - /** - * @param world - * @param x - * @param y - * @param z - */ - public void addData(World world, int x, int y, int z) - { - pedestalItems.clear(); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z - 4)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z + 2)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z - 5)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z - 4)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z - 2)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 5, y - 3, z)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z - 2)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 5, y - 3, z)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z + 2)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z + 4)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z + 5)); - addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z + 4)); - } - - public int getNumberOfItems(World world, int x, int y, int z) - { - int items = 0; - if (((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z - 4)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z + 2)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z - 5)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z - 4)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z - 2)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x - 5, y - 3, z)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z - 2)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x + 5, y - 3, z)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z + 2)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z + 4)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z + 5)).heldItemStack != null) items++; - if (((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z + 4)).heldItemStack != null) items++; - return items; - } - - public boolean canChangePedestals(World world, int x, int y, int z) - { - if (world.getBlock(x, y - 3, z) != BlockList.handPedestal) return false; - if (world.getBlock(x + 2, y - 3, z - 4) != BlockList.handPedestal) return false; - if (world.getBlock(x - 4, y - 3, z + 2) != BlockList.handPedestal) return false; - if (world.getBlock(x, y - 3, z - 5) != BlockList.handPedestal) return false; - if (world.getBlock(x - 2, y - 3, z - 4) != BlockList.handPedestal) return false; - if (world.getBlock(x - 4, y - 3, z - 2) != BlockList.handPedestal) return false; - if (world.getBlock(x - 5, y - 3, z) != BlockList.handPedestal) return false; - if (world.getBlock(x + 4, y - 3, z - 2) != BlockList.handPedestal) return false; - if (world.getBlock(x + 5, y - 3, z) != BlockList.handPedestal) return false; - if (world.getBlock(x + 4, y - 3, z + 2) != BlockList.handPedestal) return false; - if (world.getBlock(x + 2, y - 3, z + 4) != BlockList.handPedestal) return false; - if (world.getBlock(x, y - 3, z + 5) != BlockList.handPedestal) return false; - if (world.getBlock(x - 2, y - 3, z + 4) != BlockList.handPedestal) return false; - return true; - } - - public void changePedestals(World world, int x, int y, int z) - { - changeHand(world, x, y - 3, z); - changeHand(world, x + 2, y - 3, z - 4); - changeHand(world, x - 4, y - 3, z + 2); - changeHand(world, x, y - 3, z - 5); - changeHand(world, x - 2, y - 3, z - 4); - changeHand(world, x - 4, y - 3, z - 2); - changeHand(world, x - 5, y - 3, z); - changeHand(world, x + 4, y - 3, z - 2); - changeHand(world, x + 5, y - 3, z); - changeHand(world, x + 4, y - 3, z + 2); - changeHand(world, x + 2, y - 3, z + 4); - changeHand(world, x, y - 3, z + 5); - changeHand(world, x - 2, y - 3, z + 4); - } - - public void changeHand(World world, int x, int y, int z) - { - int l = world.getBlockMetadata(x, y, z); - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(world.getBlock(x, y, z))); - TileEntityShadowHand tile = new TileEntityShadowHand(); - if (world.getTileEntity(x, y, z) instanceof TileEntityHandPedestal){ - if (((TileEntityHandPedestal)world.getTileEntity(x, y, z)).heldItemStack != null) tile.setHeldItemStack(((TileEntityHandPedestal)world.getTileEntity(x, y, z)).heldItemStack.copy()); - if (tile.heldItemStack != null) tile.closeHand(); - ((TileEntityHandPedestal)world.getTileEntity(x, y, z)).removeHeldItemStack(); - world.setBlock(x, y, z, BlockList.shadowHand, l, 2); - world.setTileEntity(x, y, z, tile); - } - } - - public void revertPedestals(World world, int x, int y, int z) - { - revertHand(world, x, y - 3, z); - revertHand(world, x + 2, y - 3, z - 4); - revertHand(world, x - 4, y - 3, z + 2); - revertHand(world, x, y - 3, z - 5); - revertHand(world, x - 2, y - 3, z - 4); - revertHand(world, x - 4, y - 3, z - 2); - revertHand(world, x - 5, y - 3, z); - revertHand(world, x + 4, y - 3, z - 2); - revertHand(world, x + 5, y - 3, z); - revertHand(world, x + 4, y - 3, z + 2); - revertHand(world, x + 2, y - 3, z + 4); - revertHand(world, x, y - 3, z + 5); - revertHand(world, x - 2, y - 3, z + 4); - } - - public void revertHand(World world, int x, int y, int z) - { - int l = world.getBlockMetadata(x, y, z); - world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(BlockList.handPedestal)); - world.playSoundEffect(x, y + 0.5F, z, "step.wood", 1F, 1F); - TileEntityHandPedestal tile = new TileEntityHandPedestal(); - if (world.getTileEntity(x, y, z) instanceof TileEntityShadowHand){ - if (((TileEntityShadowHand)world.getTileEntity(x, y, z)).heldItemStack != null) tile.setHeldItemStack(((TileEntityShadowHand)world.getTileEntity(x, y, z)).heldItemStack.copy()); - ((TileEntityShadowHand)world.getTileEntity(x, y, z)).removeHeldItemStack(); - world.setBlock(x, y, z, BlockList.handPedestal, l, 2); - world.setTileEntity(x, y, z, tile); - } - } - - /** - * @param pedestal - */ - public void addPedestalInfo(TileEntityHandPedestal pedestal) - { - ItemStack heldItemStack; - if (pedestal != null && (heldItemStack = pedestal.getHeldItemStack()) != null){ - if (pedestalItems.isEmpty()) pedestalItems.add(heldItemStack.copy()); - else{ - boolean hasItem = false; - int index = 0; - for(int ind = 0; ind < pedestalItems.size() && !hasItem; ind++) - if (heldItemStack.getItem().equals(pedestalItems.get(ind).getItem()) && heldItemStack.getItemDamage() == pedestalItems.get(ind).getItemDamage()){ - index = ind; - hasItem = true; - if (heldItemStack.hasTagCompound() && pedestalItems.get(ind).hasTagCompound() && !heldItemStack.getTagCompound().equals(pedestalItems.get(ind).getTagCompound())) hasItem = false; - } - if (!hasItem) pedestalItems.add(heldItemStack.copy()); - else{ - ItemStack object = pedestalItems.get(index).copy(); - object.stackSize++; - pedestalItems.set(index, object); - } - } - pedestal.removeHeldItemStack(); - pedestal.openHand(); - }else if (pedestal != null && target != null) JewelrycraftUtil.addCursePoints(target, 20); - } - - @SideOnly(Side.CLIENT) - public AxisAlignedBB getRenderBoundingBox() - { - AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(xCoord - 5.5D, yCoord - 5.5D, zCoord - 5.5D, xCoord + 5.5D, yCoord + 5.5D, zCoord + 5.5D); - return bb; - } - - /** - * @return - */ - @Override - public Packet getDescriptionPacket() - { - NBTTagCompound nbttagcompound = new NBTTagCompound(); - writeToNBT(nbttagcompound); - return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound); - } - - /** - * @param net - * @param packet - */ - @Override - public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) - { - readFromNBT(packet.func_148857_g()); - worldObj.func_147479_m(xCoord, yCoord, zCoord); - } -} +package darkknight.jewelrycraft.tileentity; + +import java.util.ArrayList; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.block.BlockHandPedestal; +import darkknight.jewelrycraft.block.BlockList; +import darkknight.jewelrycraft.config.ConfigHandler; +import darkknight.jewelrycraft.model.ModelShadowEye; +import darkknight.jewelrycraft.util.JewelryNBT; +import darkknight.jewelrycraft.util.JewelrycraftUtil; +import darkknight.jewelrycraft.util.PlayerUtils; +import darkknight.jewelrycraft.util.Variables; + +public class TileEntityShadowEye extends TileEntity +{ + public int opening, timer, t = 20; + public boolean active, shouldAddData; + public ArrayList pedestalItems = new ArrayList(); + ResourceLocation particleTexture = new ResourceLocation(Variables.MODID, "textures/particle/shadows.png"); + public EntityPlayer target; + public ModelShadowEye model = new ModelShadowEye(); + + public TileEntityShadowEye() + { + opening = 1; + timer = 20; + active = false; + } + + /** + * @param nbt + */ + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + nbt.setInteger("opening", opening); + nbt.setInteger("timer", timer); + nbt.setBoolean("active", active); + nbt.setBoolean("shouldAddData", shouldAddData); + } + + /** + * @param nbt + */ + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + opening = nbt.getInteger("opening"); + timer = nbt.getInteger("timer"); + active = nbt.getBoolean("active"); + shouldAddData = nbt.getBoolean("shouldAddData"); + } + + /** + * + */ + @Override + public void updateEntity() + { + super.updateEntity(); + boolean valid = isValidStructure(worldObj, xCoord, yCoord, zCoord, blockMetadata); + boolean canStartRitual = valid && ((TileEntityHandPedestal)worldObj.getTileEntity(xCoord, yCoord - 3, zCoord)).heldItemStack != null && getNumberOfItems(worldObj, xCoord, yCoord, zCoord) > 0; + if (active){ + timer--; + if (canStartRitual && canChangePedestals(worldObj, xCoord, yCoord, zCoord) && opening == 4) changePedestals(worldObj, xCoord, yCoord, zCoord); + } + if (active && target != null && this.getDistanceFrom(target.posX, target.posY, target.posZ) > 27D){ + active = false; + timer = -1; + shouldAddData = false; + revertPedestals(worldObj, xCoord, yCoord, zCoord); + } + if (opening == 4 && timer <= 0) active = false; + if (!active && timer <= 0 && opening != 1){ + if (t > 0) t--; + if (t <= 0){ + opening--; + t = 20; + } + } + if (opening == 2 && timer <= 0 && t == 10 && shouldAddData){ + addData(worldObj, xCoord, yCoord, zCoord); + TileEntityHandPedestal target = (TileEntityHandPedestal)worldObj.getTileEntity(xCoord, yCoord - 3, zCoord); + if (target != null && target.getHeldItemStack() != null) JewelryNBT.addModifiers(target.getHeldItemStack(), pedestalItems); + revertPedestals(worldObj, xCoord, yCoord, zCoord); + } + if (active && timer <= 0){ + if (opening < 4){ + opening++; + timer = 20; + } + if (canStartRitual && opening == 4) timer = ConfigHandler.RITUAL_TIME; + else if (!canStartRitual){ + shouldAddData = false; + active = false; + timer = -1; + if (!worldObj.isRemote){ + JewelrycraftUtil.addCursePoints(target, 50); + target.addChatMessage(new ChatComponentText(EnumChatFormatting.BLACK + "The Shadows don't like to be disturbed for no reason!")); + target.addChatMessage(new ChatComponentText(EnumChatFormatting.DARK_PURPLE + "You feel a strange aura encumbering you.")); + } + } + } + if (active && opening == 4){ + int i = Minecraft.getMinecraft().gameSettings.particleSetting; + for(int l = 0; l <= 100 - i*45; l++) + worldObj.spawnParticle("depthsuspend", xCoord + 6.5F - worldObj.rand.nextInt(12) - worldObj.rand.nextFloat(), yCoord - 2F + worldObj.rand.nextInt(9) - worldObj.rand.nextFloat(), zCoord + 6.5F - worldObj.rand.nextInt(12) - worldObj.rand.nextFloat(), 0, 0, 0); + } + } + + /** + * @param world + * @param x + * @param y + * @param z + * @param metadata + * @return + */ + public boolean isValidStructure(World world, int x, int y, int z, int metadata) + { + if (world.getBlockMetadata(x, y, z) == 0 || world.getBlockMetadata(x, y, z) == 2){ + // Layers from top to bottom + // 1st Layer + if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) return false; + if (world.getBlock(x + 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x + 1, y + 1, z) != 5) return false; + if (world.getBlock(x - 1, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x - 1, y + 1, z) != 5) return false; + // 2nd Layer + if (world.getBlock(x + 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 2, y, z) != 1) return false; + if (world.getBlock(x + 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x + 1, y, z) != 4) return false; + if (world.getBlock(x - 1, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 1, y, z) != 5) return false; + if (world.getBlock(x - 2, y, z) != Blocks.stone_brick_stairs || world.getBlockMetadata(x - 2, y, z) != 0) return false; + // 3rd Layer + if (world.getBlock(x + 2, y - 1, z) != Blocks.stonebrick) return false; + if (world.getBlock(x - 2, y - 1, z) != Blocks.stonebrick) return false; + // 4th Layer + if (world.getBlock(x + 2, y - 2, z) != Blocks.stonebrick) return false; + if (world.getBlock(x - 2, y - 2, z) != Blocks.stonebrick) return false; + // 5th Layer + if (world.getBlock(x + 2, y - 3, z) != Blocks.stonebrick) return false; + if (world.getBlock(x - 2, y - 3, z) != Blocks.stonebrick) return false; + }else if (world.getBlockMetadata(x, y, z) == 1 || world.getBlockMetadata(x, y, z) == 3){ + // Layers from top to bottom + // 1st Layer + if (world.getBlock(x, y + 1, z) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z) != 5) return false; + if (world.getBlock(x, y + 1, z + 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z + 1) != 5) return false; + if (world.getBlock(x, y + 1, z - 1) != Blocks.stone_slab || world.getBlockMetadata(x, y + 1, z - 1) != 5) return false; + // 2nd Layer + if (world.getBlock(x, y, z + 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 2) != 3) return false; + if (world.getBlock(x, y, z + 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z + 1) != 6) return false; + if (world.getBlock(x, y, z - 1) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 1) != 7) return false; + if (world.getBlock(x, y, z - 2) != Blocks.stone_brick_stairs || world.getBlockMetadata(x, y, z - 2) != 2) return false; + // 3rd Layer + if (world.getBlock(x, y - 1, z + 2) != Blocks.stonebrick) return false; + if (world.getBlock(x, y - 1, z - 2) != Blocks.stonebrick) return false; + // 4th Layer + if (world.getBlock(x, y - 2, z + 2) != Blocks.stonebrick) return false; + if (world.getBlock(x, y - 2, z - 2) != Blocks.stonebrick) return false; + // 5th Layer + if (world.getBlock(x, y - 3, z + 2) != Blocks.stonebrick) return false; + if (world.getBlock(x, y - 3, z - 2) != Blocks.stonebrick) return false; + } + // 3rd Layer + if (world.getBlock(x - 4, y - 1, z - 4) != BlockList.shadowBlock) return false; + if (world.getBlock(x - 4, y - 1, z + 4) != BlockList.shadowBlock) return false; + if (world.getBlock(x + 4, y - 1, z - 4) != BlockList.shadowBlock) return false; + if (world.getBlock(x + 4, y - 1, z + 4) != BlockList.shadowBlock) return false; + // 4th Layer + if (world.getBlock(x - 4, y - 2, z - 4) != Blocks.stonebrick) return false; + if (world.getBlock(x - 4, y - 2, z + 4) != Blocks.stonebrick) return false; + if (world.getBlock(x + 4, y - 2, z - 4) != Blocks.stonebrick) return false; + if (world.getBlock(x + 4, y - 2, z + 4) != Blocks.stonebrick) return false; + // 5th Layer + // Pillars + if (world.getBlock(x - 4, y - 3, z - 4) != Blocks.stonebrick) return false; + if (world.getBlock(x - 4, y - 3, z + 4) != Blocks.stonebrick) return false; + if (world.getBlock(x + 4, y - 3, z - 4) != Blocks.stonebrick) return false; + if (world.getBlock(x + 4, y - 3, z + 4) != Blocks.stonebrick) return false; + // Pedestals + if (!(world.getBlock(x, y - 3, z) instanceof BlockHandPedestal)) return false; + if (world.getBlock(x - 4, y - 3, z + 2) != BlockList.handPedestal || world.getBlockMetadata(x - 4, y - 3, z + 2) != 1) return false; + if (world.getBlock(x - 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x - 5, y - 3, z) != 2) return false; + if (world.getBlock(x - 4, y - 3, z - 2) != BlockList.handPedestal || world.getBlockMetadata(x - 4, y - 3, z - 2) != 3) return false; + if (world.getBlock(x - 2, y - 3, z - 4) != BlockList.handPedestal || world.getBlockMetadata(x - 2, y - 3, z - 4) != 3) return false; + if (world.getBlock(x, y - 3, z - 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z - 5) != 4) return false; + if (world.getBlock(x + 2, y - 3, z - 4) != BlockList.handPedestal || world.getBlockMetadata(x + 2, y - 3, z - 4) != 5) return false; + if (world.getBlock(x + 4, y - 3, z - 2) != BlockList.handPedestal || world.getBlockMetadata(x + 4, y - 3, z - 2) != 5) return false; + if (world.getBlock(x + 5, y - 3, z) != BlockList.handPedestal || world.getBlockMetadata(x + 5, y - 3, z) != 6) return false; + if (world.getBlock(x + 4, y - 3, z + 2) != BlockList.handPedestal || world.getBlockMetadata(x + 4, y - 3, z + 2) != 7) return false; + if (world.getBlock(x + 2, y - 3, z + 4) != BlockList.handPedestal || world.getBlockMetadata(x + 2, y - 3, z + 4) != 7) return false; + if (world.getBlock(x, y - 3, z + 5) != BlockList.handPedestal || world.getBlockMetadata(x, y - 3, z + 5) != 0) return false; + if (world.getBlock(x - 2, y - 3, z + 4) != BlockList.handPedestal || world.getBlockMetadata(x - 2, y - 3, z + 4) != 1) return false; + return true; + } + + /** + * @param world + * @param x + * @param y + * @param z + */ + public void addData(World world, int x, int y, int z) + { + pedestalItems.clear(); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z - 4)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z + 2)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z - 5)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z - 4)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z - 2)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 5, y - 3, z)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z - 2)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 5, y - 3, z)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z + 2)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z + 4)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z + 5)); + addPedestalInfo((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z + 4)); + } + + public int getNumberOfItems(World world, int x, int y, int z) + { + int items = 0; + if (((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z - 4)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z + 2)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z - 5)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z - 4)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x - 4, y - 3, z - 2)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x - 5, y - 3, z)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z - 2)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x + 5, y - 3, z)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x + 4, y - 3, z + 2)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x + 2, y - 3, z + 4)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x, y - 3, z + 5)).heldItemStack != null) items++; + if (((TileEntityHandPedestal)world.getTileEntity(x - 2, y - 3, z + 4)).heldItemStack != null) items++; + return items; + } + + public boolean canChangePedestals(World world, int x, int y, int z) + { + if (world.getBlock(x, y - 3, z) != BlockList.handPedestal) return false; + if (world.getBlock(x + 2, y - 3, z - 4) != BlockList.handPedestal) return false; + if (world.getBlock(x - 4, y - 3, z + 2) != BlockList.handPedestal) return false; + if (world.getBlock(x, y - 3, z - 5) != BlockList.handPedestal) return false; + if (world.getBlock(x - 2, y - 3, z - 4) != BlockList.handPedestal) return false; + if (world.getBlock(x - 4, y - 3, z - 2) != BlockList.handPedestal) return false; + if (world.getBlock(x - 5, y - 3, z) != BlockList.handPedestal) return false; + if (world.getBlock(x + 4, y - 3, z - 2) != BlockList.handPedestal) return false; + if (world.getBlock(x + 5, y - 3, z) != BlockList.handPedestal) return false; + if (world.getBlock(x + 4, y - 3, z + 2) != BlockList.handPedestal) return false; + if (world.getBlock(x + 2, y - 3, z + 4) != BlockList.handPedestal) return false; + if (world.getBlock(x, y - 3, z + 5) != BlockList.handPedestal) return false; + if (world.getBlock(x - 2, y - 3, z + 4) != BlockList.handPedestal) return false; + return true; + } + + public void changePedestals(World world, int x, int y, int z) + { + changeHand(world, x, y - 3, z); + changeHand(world, x + 2, y - 3, z - 4); + changeHand(world, x - 4, y - 3, z + 2); + changeHand(world, x, y - 3, z - 5); + changeHand(world, x - 2, y - 3, z - 4); + changeHand(world, x - 4, y - 3, z - 2); + changeHand(world, x - 5, y - 3, z); + changeHand(world, x + 4, y - 3, z - 2); + changeHand(world, x + 5, y - 3, z); + changeHand(world, x + 4, y - 3, z + 2); + changeHand(world, x + 2, y - 3, z + 4); + changeHand(world, x, y - 3, z + 5); + changeHand(world, x - 2, y - 3, z + 4); + } + + public void changeHand(World world, int x, int y, int z) + { + int l = world.getBlockMetadata(x, y, z); + world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(world.getBlock(x, y, z))); + TileEntityShadowHand tile = new TileEntityShadowHand(); + if (world.getTileEntity(x, y, z) instanceof TileEntityHandPedestal){ + if (((TileEntityHandPedestal)world.getTileEntity(x, y, z)).heldItemStack != null) tile.setHeldItemStack(((TileEntityHandPedestal)world.getTileEntity(x, y, z)).heldItemStack.copy()); + if (tile.heldItemStack != null) tile.closeHand(); + ((TileEntityHandPedestal)world.getTileEntity(x, y, z)).removeHeldItemStack(); + world.setBlock(x, y, z, BlockList.shadowHand, l, 2); + world.setTileEntity(x, y, z, tile); + } + } + + public void revertPedestals(World world, int x, int y, int z) + { + revertHand(world, x, y - 3, z); + revertHand(world, x + 2, y - 3, z - 4); + revertHand(world, x - 4, y - 3, z + 2); + revertHand(world, x, y - 3, z - 5); + revertHand(world, x - 2, y - 3, z - 4); + revertHand(world, x - 4, y - 3, z - 2); + revertHand(world, x - 5, y - 3, z); + revertHand(world, x + 4, y - 3, z - 2); + revertHand(world, x + 5, y - 3, z); + revertHand(world, x + 4, y - 3, z + 2); + revertHand(world, x + 2, y - 3, z + 4); + revertHand(world, x, y - 3, z + 5); + revertHand(world, x - 2, y - 3, z + 4); + } + + public void revertHand(World world, int x, int y, int z) + { + int l = world.getBlockMetadata(x, y, z); + world.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(BlockList.handPedestal)); + world.playSoundEffect(x, y + 0.5F, z, "step.wood", 1F, 1F); + TileEntityHandPedestal tile = new TileEntityHandPedestal(); + if (world.getTileEntity(x, y, z) instanceof TileEntityShadowHand){ + if (((TileEntityShadowHand)world.getTileEntity(x, y, z)).heldItemStack != null) tile.setHeldItemStack(((TileEntityShadowHand)world.getTileEntity(x, y, z)).heldItemStack.copy()); + ((TileEntityShadowHand)world.getTileEntity(x, y, z)).removeHeldItemStack(); + world.setBlock(x, y, z, BlockList.handPedestal, l, 2); + world.setTileEntity(x, y, z, tile); + } + } + + /** + * @param pedestal + */ + public void addPedestalInfo(TileEntityHandPedestal pedestal) + { + ItemStack heldItemStack; + if (pedestal != null && (heldItemStack = pedestal.getHeldItemStack()) != null){ + if (pedestalItems.isEmpty()) pedestalItems.add(heldItemStack.copy()); + else{ + boolean hasItem = false; + int index = 0; + for(int ind = 0; ind < pedestalItems.size() && !hasItem; ind++) + if (heldItemStack.getItem().equals(pedestalItems.get(ind).getItem()) && heldItemStack.getItemDamage() == pedestalItems.get(ind).getItemDamage()){ + index = ind; + hasItem = true; + if (heldItemStack.hasTagCompound() && pedestalItems.get(ind).hasTagCompound() && !heldItemStack.getTagCompound().equals(pedestalItems.get(ind).getTagCompound())) hasItem = false; + } + if (!hasItem) pedestalItems.add(heldItemStack.copy()); + else{ + ItemStack object = pedestalItems.get(index).copy(); + object.stackSize++; + pedestalItems.set(index, object); + } + } + pedestal.removeHeldItemStack(); + pedestal.openHand(); + }else if (pedestal != null && target != null) JewelrycraftUtil.addCursePoints(target, 20); + } + + @SideOnly(Side.CLIENT) + public AxisAlignedBB getRenderBoundingBox() + { + AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(xCoord - 5.5D, yCoord - 5.5D, zCoord - 5.5D, xCoord + 5.5D, yCoord + 5.5D, zCoord + 5.5D); + return bb; + } + + /** + * @return + */ + @Override + public Packet getDescriptionPacket() + { + NBTTagCompound nbttagcompound = new NBTTagCompound(); + writeToNBT(nbttagcompound); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbttagcompound); + } + + /** + * @param net + * @param packet + */ + @Override + public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) + { + readFromNBT(packet.func_148857_g()); + worldObj.func_147479_m(xCoord, yCoord, zCoord); + } +} diff --git a/src/main/java/darkknight/jewelrycraft/tileentity/renders/TileEntityShadowEyeRender.java b/src/main/java/darkknight/jewelrycraft/tileentity/renders/TileEntityShadowEyeRender.java index 53ff9e1..82cffbb 100644 --- a/src/main/java/darkknight/jewelrycraft/tileentity/renders/TileEntityShadowEyeRender.java +++ b/src/main/java/darkknight/jewelrycraft/tileentity/renders/TileEntityShadowEyeRender.java @@ -1,100 +1,104 @@ -package darkknight.jewelrycraft.tileentity.renders; - -import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; -import org.lwjgl.opengl.GL11; -import org.lwjgl.util.glu.GLU; -import org.lwjgl.util.glu.Sphere; -import darkknight.jewelrycraft.model.ModelShadowEye; -import darkknight.jewelrycraft.tileentity.TileEntityShadowEye; -import darkknight.jewelrycraft.util.Variables; - -public class TileEntityShadowEyeRender extends TileEntitySpecialRenderer -{ - ModelShadowEye eye = new ModelShadowEye(); - Sphere shadow = new Sphere(); - - /** - * @param te - * @param x - * @param y - * @param z - * @param scale - */ - @Override - public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) - { - GL11.glPushMatrix(); - GL11.glTranslatef((float)x + 0.5F, (float)y + 1.6F, (float)z + 0.5F); - TileEntityShadowEye eyeS = (TileEntityShadowEye)te; - String texture = "textures/tileentities/ShadowEye" + eyeS.opening + ".png"; - ResourceLocation blockTexture = new ResourceLocation(Variables.MODID, texture); - Minecraft.getMinecraft().renderEngine.bindTexture(blockTexture); - GL11.glPushMatrix(); - GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); - try{ - int block = te.getBlockMetadata(); - if (block == 0) GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F); - else if (block == 1){ - GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); - GL11.glRotatef(180F, 1.0F, 0.0F, 0.0F); - }else if (block == 2){ - GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); - GL11.glRotatef(180F, 1.0F, 0.0F, 1.0F); - } - } - catch(Exception e){} - try{ - EntityPlayer player = te.getWorldObj().getClosestPlayer(te.xCoord, te.yCoord, te.zCoord, 16D); - if (player != null) eye.render(player, te.xCoord, te.yCoord, te.zCoord, te.blockMetadata, eyeS.opening, 0.0625F); - } - catch(Exception e){ - eye.render((Entity)null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); - } - if (eyeS.opening == 4){ - GL11.glPushMatrix(); - GL11.glDisable(GL11.GL_TEXTURE_2D); - GL11.glEnable(GL11.GL_BLEND); - GL11.glBlendFunc(GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - GL11.glColor4f(0.0F, 0.0F, 0.0F, 1F); - GL11.glRotatef(eyeS.timer*10F, 0, 1, 0); - GL11.glRotatef(90.0F, 1, 0, 0); - EntityPlayer player = te.getWorldObj().getClosestPlayer(te.xCoord, te.yCoord, te.zCoord, 9D); - shadow.setNormals(GLU.GLU_NONE); - shadow.draw(9.5F, 6, 6); - GL11.glScalef(-1,-1,-1); - shadow.draw(9.5F, 6, 6); - GL11.glDisable(GL11.GL_BLEND); - GL11.glEnable(GL11.GL_TEXTURE_2D); - GL11.glPopMatrix(); - } - GL11.glPopMatrix(); - GL11.glPopMatrix(); - } - - /** - * @param world - * @param i - * @param j - * @param k - * @param block - */ - public void adjustLightFixture(World world, int i, int j, int k, Block block) - { - Tessellator tess = Tessellator.instance; - float brightness = block.getLightOpacity(world, i, j, k); - int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); - int modulousModifier = skyLight % 65536; - int divModifier = skyLight / 65536; - tess.setColorOpaque_F(brightness, brightness, brightness); - OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, modulousModifier, divModifier); - } -} +package darkknight.jewelrycraft.tileentity.renders; + +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.glu.GLU; +import org.lwjgl.util.glu.Sphere; + +import darkknight.jewelrycraft.model.ModelShadowEye; +import darkknight.jewelrycraft.tileentity.TileEntityShadowEye; +import darkknight.jewelrycraft.util.Variables; + +public class TileEntityShadowEyeRender extends TileEntitySpecialRenderer +{ + ModelShadowEye eye = new ModelShadowEye(); + Sphere shadow = new Sphere(); + + /** + * @param te + * @param x + * @param y + * @param z + * @param scale + */ + @Override + public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) + { + GL11.glPushMatrix(); + GL11.glTranslatef((float)x + 0.5F, (float)y + 1.6F, (float)z + 0.5F); + TileEntityShadowEye eyeS = (TileEntityShadowEye)te; + String texture = "textures/tileentities/ShadowEye" + eyeS.opening + ".png"; + ResourceLocation blockTexture = new ResourceLocation(Variables.MODID, texture); + Minecraft.getMinecraft().renderEngine.bindTexture(blockTexture); + GL11.glPushMatrix(); + GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); + try{ + int block = te.getBlockMetadata(); + if (block == 0) GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F); + else if (block == 1) GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F); + else if (block == 2) GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F); + } + catch(Exception e){} + if (te != null && te.getWorldObj() != null) + { + EntityPlayer player = te.getWorldObj().getClosestPlayer(te.xCoord, te.yCoord, te.zCoord, 16D); + if(player != null) + { + float x1 = (float) (te.xCoord - player.posX) + 0.5F; + float y1 = (float) (te.yCoord - player.posY) + 0.5F; + float z1 = (float) (te.zCoord - player.posZ) + 0.5F; + eyeS.model.render(player, 0, (float)(x1 >= 0 ? Math.atan(z1 / x1) : Math.PI + Math.atan(z1 / x1)), (float)(y1 >= 0 ? Math.atan(y1 / x1) : Math.atan(y1 / x1)), te.blockMetadata, eyeS.opening, 0.0625F); + } + + } + else eyeS.model.render((Entity)null, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F); + + if (eyeS.opening == 4){ + GL11.glPushMatrix(); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glColor4f(0.0F, 0.0F, 0.0F, 1F); + GL11.glRotatef(eyeS.timer*10F, 0, 1, 0); + GL11.glRotatef(90.0F, 1, 0, 0); + shadow.setNormals(GLU.GLU_NONE); + shadow.draw(7.5F, 6, 6); + GL11.glScalef(-1,-1,-1); + shadow.draw(7.5F, 6, 6); + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glPopMatrix(); + } + GL11.glPopMatrix(); + GL11.glPopMatrix(); + } + + /** + * @param world + * @param i + * @param j + * @param k + * @param block + */ + public void adjustLightFixture(World world, int i, int j, int k, Block block) + { + Tessellator tess = Tessellator.instance; + float brightness = block.getLightOpacity(world, i, j, k); + int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); + int modulousModifier = skyLight % 65536; + int divModifier = skyLight / 65536; + tess.setColorOpaque_F(brightness, brightness, brightness); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, modulousModifier, divModifier); + } +} -- cgit v1.2.3