From a6a3bfa6f313adba5afe6eb4a0da049a8d641cfc Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Fri, 5 Jun 2015 01:53:14 +0100 Subject: Stuff! --- .../jewelrycraft/events/EntityEventHandler.java | 975 +++++++++++---------- .../jewelrycraft/events/PlayerRenderHandler.java | 435 ++++----- 2 files changed, 722 insertions(+), 688 deletions(-) (limited to 'src/main/java/darkknight/jewelrycraft/events') diff --git a/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java b/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java index 7157759..786a8ae 100644 --- a/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java +++ b/src/main/java/darkknight/jewelrycraft/events/EntityEventHandler.java @@ -1,488 +1,489 @@ -package darkknight.jewelrycraft.events; - -import java.io.EOFException; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Random; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.item.EntityItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.server.MinecraftServer; -import net.minecraft.util.AxisAlignedBB; -import net.minecraft.util.ChatComponentText; -import net.minecraft.util.MathHelper; -import net.minecraftforge.client.event.EntityViewRenderEvent; -import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.item.ItemTossEvent; -import net.minecraftforge.event.entity.living.LivingAttackEvent; -import net.minecraftforge.event.entity.living.LivingDeathEvent; -import net.minecraftforge.event.entity.living.LivingDropsEvent; -import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; -import net.minecraftforge.event.entity.player.PlayerEvent; -import net.minecraftforge.event.world.WorldEvent; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import darkknight.jewelrycraft.JewelrycraftMod; -import darkknight.jewelrycraft.api.Curse; -import darkknight.jewelrycraft.api.IJewelryItem; -import darkknight.jewelrycraft.config.ConfigHandler; -import darkknight.jewelrycraft.damage.DamageSourceList; -import darkknight.jewelrycraft.entities.EntityHalfHeart; -import darkknight.jewelrycraft.entities.EntityHeart; -import darkknight.jewelrycraft.item.ItemBaseJewelry; -import darkknight.jewelrycraft.item.ItemList; -import darkknight.jewelrycraft.network.PacketClearColorCache; -import darkknight.jewelrycraft.network.PacketRequestPlayerInfo; -import darkknight.jewelrycraft.network.PacketSendServerPlayersInfo; -import darkknight.jewelrycraft.potions.PotionList; -import darkknight.jewelrycraft.util.BlockUtils; -import darkknight.jewelrycraft.util.JewelryNBT; -import darkknight.jewelrycraft.util.JewelrycraftUtil; -import darkknight.jewelrycraft.util.PlayerUtils; -import darkknight.jewelrycraft.util.Variables; - -/** - * Code taken from OpenBlocks - */ -public class EntityEventHandler -{ - int updateTime = 0, totalUnavailableCurses = 0; - boolean addedCurses = false; - - /** - * @param event - */ - @SubscribeEvent - public void onEntityJoinWorld(EntityJoinWorldEvent event) - { - if (event.entity instanceof EntityPlayerMP) JewelrycraftMod.netWrapper.sendTo(new PacketClearColorCache(), (EntityPlayerMP)event.entity); - if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - final Entity entity = event.entity; - if (!event.world.isRemote && entity instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)entity; - NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - boolean shouldGiveManual = ItemList.guide != null && !persistTag.getBoolean("givenGuide"); - if (shouldGiveManual){ - ItemStack manual = new ItemStack(ItemList.guide); - if (!player.inventory.addItemStackToInventory(manual)) BlockUtils.dropItemStackInWorld(player.worldObj, player.posX, player.posY, player.posZ, manual); - persistTag.setBoolean("givenGuide", true); - } - boolean render = persistTag.getBoolean("fancyRender"); - JewelrycraftMod.fancyRender = render; - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(event.world) && !persistTag.hasKey(curse.getName())) persistTag.setInteger(curse.getName(), 0); - for(Curse curse: Curse.getCurseList()) - if (!curse.canCurseBeActivated(event.world)){ - Curse.availableCurses.remove(curse); - persistTag.setInteger(curse.getName(), 0); - totalUnavailableCurses++; - }else if (!Curse.availableCurses.contains(curse)) Curse.availableCurses.add(curse); - persistTag.setBoolean("sendInfo", true); - } - } - - /** - * @param event - */ - @SubscribeEvent - public void onEntityUpdate(LivingUpdateEvent event) - { - Entity entity = event.entity; - EntityLivingBase entityLiving = event.entityLiving; - if (entityLiving.isPotionActive(PotionList.stun)){ - entityLiving.motionX *= 0D; - entityLiving.motionZ *= 0D; - entityLiving.motionY *= 0D; - entityLiving.isSwingInProgress = false; - entityLiving.moveForward = 0F; - entityLiving.moveStrafing = 0F; - entityLiving.setAIMoveSpeed(0F); - entityLiving.limbSwing = 0F; - entityLiving.limbSwingAmount = 0F; - entityLiving.swingProgressInt = 0; - entityLiving.rotationPitch = entity.prevRotationPitch; - entityLiving.rotationYaw = entity.prevRotationYaw; - entityLiving.worldObj.spawnParticle("spell", entityLiving.posX, entityLiving.posY + entityLiving.getEyeHeight(), entityLiving.posZ, 0.0D, 0.3D, 0.0D); - } - if (entityLiving.isPotionActive(PotionList.stun) && entityLiving.getActivePotionEffect(PotionList.stun).getDuration() == 0) entityLiving.removePotionEffect(PotionList.stun.id); - if (entity instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)entity; - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - playerInfo.setBoolean("fancyRender", JewelrycraftMod.fancyRender); - if (updateTime > 0) updateTime--; - for(int i = 0; i < 18; i++) - if (playerInfo.hasKey("ext" + i)){ - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - if (item != null){ - if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).action(item, player); - if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onWearAction(item, player); - } - } - if (!player.worldObj.isRemote){ - if (playerInfo.hasKey("reselectCurses") && !playerInfo.getBoolean("reselectCurses")){ - playerInfo.setInteger("curseTime", playerInfo.getInteger("curseTime") - 10000); - if (playerInfo.getInteger("curseTime") <= 0) playerInfo.setBoolean("reselectCurses", true); - } - if (playerInfo.hasKey("playerCursePointsChanged") && playerInfo.getBoolean("playerCursePointsChanged")){ - int points = playerInfo.getInteger("cursePoints"); - for(int i = 1; i <= Variables.MAX_CURSES; i++) - if (points > (i - 1) * 1750) addCurse(player, playerInfo, i); - if (!playerInfo.hasKey("curseTime") || !playerInfo.hasKey("reselectCurses") || playerInfo.getBoolean("reselectCurses")){ - playerInfo.setInteger("curseTime", 23000); - playerInfo.setBoolean("reselectCurses", false); - } - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - if (addedCurses){ - JewelrycraftMod.netWrapper.sendToAll(new PacketSendServerPlayersInfo()); - // player.openGui(JewelrycraftMod.instance, 4, player.worldObj, 0, 0, 0); - addedCurses = false; - } - } - if (playerInfo.getBoolean("playerCursePointsChanged")) playerInfo.setBoolean("playerCursePointsChanged", false); - if (updateTime == 0){ - JewelrycraftMod.netWrapper.sendToAll(new PacketSendServerPlayersInfo()); - updateTime = 200; - } - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.action(player.worldObj, player); - } - } - } - - @SubscribeEvent - public void onEntityLivingDropItems(LivingDropsEvent event) - { - if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)event.source.getEntity(); - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.entityDropItems(player, event.entityLiving, event.drops); - } - } - - /** - * @param event - */ - @SubscribeEvent - public void onEntityAttacked(LivingAttackEvent event) - { - EntityLivingBase entity = event.entityLiving; - if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityLivingBase && ((EntityLivingBase)event.source.getEntity()).isPotionActive(PotionList.stun)) event.setCanceled(true); - if (entity instanceof EntityPlayer && !(event.source.getEntity() instanceof EntityPlayer)){ - EntityPlayer player = (EntityPlayer)entity; - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - if (!player.worldObj.isRemote) for(int i = 0; i < 18; i++) - if (playerInfo.hasKey("ext" + i)){ - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - if (item != null && item.getItem() instanceof ItemBaseJewelry && ((ItemBaseJewelry)item.getItem()).onPlayerAttackedCacellable(item, player, event.source, event.ammount)){ - event.setCanceled(true); - break; - } - if (playerInfo.getBoolean("negateDamage")){ - playerInfo.setBoolean("negateDamage", false); - event.setCanceled(true); - break; - } - if (item != null){ - if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onPlayerAttacked(item, player, event.source, event.ammount); - if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onPlayerAttackedAction(item, player, event.source, event.ammount); - } - } - if (player.getHealth() != player.prevHealth){ - if (playerInfo.getFloat("WhiteHeart") > 0){ - playerInfo.setFloat("WhiteHeart", 0f); - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - } - if (playerInfo.getFloat("BlueHeart") > 0){ - float damage = playerInfo.getFloat("BlueHeart") - event.ammount; - if (damage >= 0){ - playerInfo.setFloat("BlueHeart", damage); - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - player.heal(event.ammount); - }else{ - playerInfo.setFloat("BlueHeart", 0f); - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - player.heal(Math.abs(damage)); - } - }else if (playerInfo.getFloat("BlackHeart") > 0){ - AxisAlignedBB axisalignedbb = player.boundingBox.expand(2.0D, 0.0D, 2.0D); - List enemies = player.worldObj.getEntitiesWithinAABBExcludingEntity(player, axisalignedbb); - if (enemies != null && !enemies.isEmpty()){ - Iterator iterator = enemies.iterator(); - while (iterator.hasNext()){ - Entity enemy = (Entity)iterator.next(); - enemy.attackEntityFrom(DamageSourceList.blackHeart, 5f * event.ammount); - } - } - float damage = playerInfo.getFloat("BlackHeart") - event.ammount; - if (damage >= 0){ - playerInfo.setFloat("BlackHeart", damage); - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - player.heal(event.ammount); - }else{ - playerInfo.setFloat("BlackHeart", 0f); - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - player.heal(Math.abs(damage)); - } - } - } - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.attackedAction(player.worldObj, player); - }else if (event.source.getEntity() instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)event.source.getEntity(); - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - for(int i = 0; i < 18; i++) - if (playerInfo.hasKey("ext" + i)){ - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - if (item != null && item.getItem() instanceof ItemBaseJewelry && ((ItemBaseJewelry)item.getItem()).onEntityAttackedCacellable(item, player, entity, event.ammount)){ - event.setCanceled(true); - break; - } - if (playerInfo.getBoolean("weakDamage")){ - playerInfo.setBoolean("weakDamage", false); - event.setCanceled(true); - break; - } - if (item != null){ - if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onEntityAttacked(item, player, entity, event.ammount); - if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onEntityAttackedByPlayer(item, player, entity, event.ammount); - } - } - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.attackedByPlayerAction(entity.worldObj, player, entity); - } - } - - /** - * @param event - */ - @SubscribeEvent - public void onPlayerRespawn(PlayerEvent.Clone event) - { - EntityPlayer player = event.entityPlayer; - if (!player.worldObj.isRemote){ - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - if (playerInfo.hasKey("cursePoints")){ - int points = playerInfo.getInteger("cursePoints"); - for(int i = 1; i <= Variables.MAX_CURSES; i++) - if (points > (i - 1) * 1750) addCurse(player, playerInfo, i); - if (!playerInfo.hasKey("curseTime") || !playerInfo.hasKey("reselectCurses") || playerInfo.getBoolean("reselectCurses")){ - playerInfo.setInteger("curseTime", 23000); - playerInfo.setBoolean("reselectCurses", false); - } - } - playerInfo.setFloat("BlueHeart", 0f); - playerInfo.setFloat("BlackHeart", 0f); - playerInfo.setFloat("WhiteHeart", 0f); - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.respawnAction(player.worldObj, player); - for(int i = 0; i < 18; i++) - if (playerInfo.hasKey("ext" + i)){ - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - if (item != null){ - if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onPlayerRespawn(item, event); - if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onPlayerRespawnAction(item, event); - } - } - } - if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - if (!player.worldObj.isRemote){ - JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - if (addedCurses){ - JewelrycraftMod.netWrapper.sendToAll(new PacketSendServerPlayersInfo()); - // player.openGui(JewelrycraftMod.instance, 4, player.worldObj, 0, 0, 0); - addedCurses = false; - } - } - } - - /** - * @param player - * @param playerInfo - * @param curse - */ - public void addCurse(EntityPlayer player, NBTTagCompound playerInfo, int curseNo) - { - if (ConfigHandler.CURSES_ENABLED && Curse.availableCurses.size() > 0 && curseNo > Curse.getCurseList().size() - Curse.availableCurses.size() - totalUnavailableCurses){ - int no = JewelrycraftUtil.rand.nextInt(Curse.availableCurses.size()); - Curse cur = Curse.availableCurses.get(no); - playerInfo.setInteger(cur.getName(), 1); - Curse.availableCurses.remove(cur); - addedCurses = true; - } - } - - @SubscribeEvent - public void itemToss(ItemTossEvent event) - { - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(event.player, Variables.MODID); - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(event.player.worldObj) && playerInfo.getInteger(curse.getName()) > 0 && curse.itemToss()){ - EntityItem entityitem = new EntityItem(event.player.worldObj, event.player.posX + 0.5D, event.player.posY + 0.5D, event.player.posZ + 0.5D, event.entityItem.getEntityItem()); - entityitem.motionX = 0; - entityitem.motionZ = 0; - entityitem.motionY = 0.11000000298023224D; - event.player.worldObj.spawnEntityInWorld(entityitem); - MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText("<" + event.player.getDisplayName() + "> This is MY item! MINE! I will NEVER give it to you! Mine! Mine! MINE!")); - event.setCanceled(true); - } - } - - /** - * @param event - */ - @SubscribeEvent - public void playerFileSave(PlayerEvent.SaveToFile event) - { - if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - } - - /** - * @param event - */ - @SubscribeEvent - public void onEntityDead(LivingDeathEvent event) - { - final Entity entity = event.entity; - Random rand = new Random(); - String[] types = {"Red", "Blue", "White", "Black"}; - if (!entity.worldObj.isRemote && !(entity instanceof EntityPlayer) && entity instanceof EntityLiving){ - EntityLiving live = (EntityLiving)entity; - String type = types[rand.nextInt(4)]; - if (rand.nextInt(6) == 0 && live.getCreatureAttribute() != JewelrycraftUtil.HEART){ - if (type == "White"){ - EntityHeart h = new EntityHalfHeart(live.worldObj); - h.setType(type); - h.setLocationAndAngles(live.posX, live.posY, live.posZ, MathHelper.wrapAngleTo180_float(rand.nextFloat() * 360.0F), 0.0F); - live.worldObj.spawnEntityInWorld(h); - }else{ - for(int i = 1; i <= 1 + rand.nextInt(1 + (int)(live.getMaxHealth() / 20)); i++){ - EntityHeart[] hearts = {new EntityHeart(live.worldObj), new EntityHalfHeart(entity.worldObj)}; - EntityHeart h = hearts[rand.nextInt(2)]; - h.setType(type); - h.setLocationAndAngles(live.posX, live.posY, live.posZ, MathHelper.wrapAngleTo180_float(rand.nextFloat() * 360.0F), 0.0F); - live.worldObj.spawnEntityInWorld(h); - } - } - } - if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)event.source.getEntity(); - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.entityDeathAction(player.worldObj, event.entityLiving, player); - } - } - if (entity instanceof EntityPlayer){ - EntityPlayer player = (EntityPlayer)entity; - NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); - playerInfo.setFloat("BlueHeart", 0f); - playerInfo.setFloat("BlackHeart", 0f); - playerInfo.setFloat("WhiteHeart", 0f); - if (playerInfo.hasKey("reselectCurses") && playerInfo.getBoolean("reselectCurses")){ - if (ConfigHandler.CURSES_ENABLED) for(Curse l: Curse.getCurseList()){ - if (l.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(l.getName()) == 1){ - playerInfo.setInteger(l.getName(), 0); - if (!Curse.availableCurses.contains(l)) Curse.availableCurses.add(l); - }else if (l.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(l.getName()) >= 2) playerInfo.setInteger(l.getName(), 1); - } - if (entity.worldObj.isRemote) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - } - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.playerDeathAction(player.worldObj, player); - for(int i = 0; i < 18; i++) - if (playerInfo.hasKey("ext" + i)){ - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - if (item != null){ - if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onPlayerDead(item, player, event.source); - if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onPlayerDeadAction(item, player, event.source); - } - } - } - if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); - } - - /** - * @param event - */ - @SubscribeEvent - public void onWorldLoad(WorldEvent.Load event) - { - if (!event.world.isRemote){ - new File(JewelrycraftMod.dir + File.separator + Variables.MODID).mkdirs(); - JewelrycraftMod.liquidsConf = new File(JewelrycraftMod.dir + File.separator + Variables.MODID, "JLP" + event.world.getWorldInfo().getWorldName() + ".cfg"); - try{ - if (!JewelrycraftMod.liquidsConf.exists()) JewelrycraftMod.liquidsConf.createNewFile(); - } - catch(IOException e){ - e.printStackTrace(); - } - } - if (FMLCommonHandler.instance().getEffectiveSide().isServer()) try{ - if (JewelrycraftMod.liquidsConf.exists()) JewelrycraftMod.saveData = CompressedStreamTools.readCompressed(new FileInputStream(JewelrycraftMod.liquidsConf)); - } - catch(EOFException e){ - e.printStackTrace(); - } - catch(IOException e){ - e.printStackTrace(); - } - } - - /** - * @param event - */ - @SubscribeEvent - public void onWorldSave(WorldEvent.Save event) - { - if (FMLCommonHandler.instance().getEffectiveSide().isServer()) try{ - if (JewelrycraftMod.liquidsConf.exists()) CompressedStreamTools.writeCompressed(JewelrycraftMod.saveData, new FileOutputStream(JewelrycraftMod.liquidsConf)); - } - catch(EOFException e){ - e.printStackTrace(); - } - catch(IOException e){ - e.printStackTrace(); - } - } - - /** - * @param event - */ - @SubscribeEvent - @SideOnly (Side.CLIENT) - public void fogColors(EntityViewRenderEvent.FogColors event) - {} - - /** - * @param event - */ - @SubscribeEvent - @SideOnly (Side.CLIENT) - public void fogDensity(EntityViewRenderEvent.FogDensity event) - {} - - /** - * @param event - */ - @SubscribeEvent - @SideOnly (Side.CLIENT) - public void renderFog(EntityViewRenderEvent.RenderFogEvent event) - {} +package darkknight.jewelrycraft.events; + +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Random; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.MathHelper; +import net.minecraft.util.WeightedRandom; +import net.minecraftforge.client.event.EntityViewRenderEvent; +import net.minecraftforge.event.entity.EntityJoinWorldEvent; +import net.minecraftforge.event.entity.item.ItemTossEvent; +import net.minecraftforge.event.entity.living.LivingAttackEvent; +import net.minecraftforge.event.entity.living.LivingDeathEvent; +import net.minecraftforge.event.entity.living.LivingDropsEvent; +import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.event.world.WorldEvent; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.api.Curse; +import darkknight.jewelrycraft.api.IJewelryItem; +import darkknight.jewelrycraft.config.ConfigHandler; +import darkknight.jewelrycraft.damage.DamageSourceList; +import darkknight.jewelrycraft.entities.EntityHalfHeart; +import darkknight.jewelrycraft.entities.EntityHeart; +import darkknight.jewelrycraft.item.ItemBaseJewelry; +import darkknight.jewelrycraft.item.ItemList; +import darkknight.jewelrycraft.network.PacketClearColorCache; +import darkknight.jewelrycraft.network.PacketRequestPlayerInfo; +import darkknight.jewelrycraft.network.PacketSendServerPlayersInfo; +import darkknight.jewelrycraft.potions.PotionList; +import darkknight.jewelrycraft.random.WeightedRandomCurse; +import darkknight.jewelrycraft.util.BlockUtils; +import darkknight.jewelrycraft.util.JewelrycraftUtil; +import darkknight.jewelrycraft.util.PlayerUtils; +import darkknight.jewelrycraft.util.Variables; + +/** + * Code taken from OpenBlocks + */ +public class EntityEventHandler +{ + int updateTime = 0, totalUnavailableCurses = 0; + boolean addedCurses = false; + Random rand = new Random(); + + /** + * @param event + */ + @SubscribeEvent + public void onEntityJoinWorld(EntityJoinWorldEvent event) + { + if (event.entity instanceof EntityPlayerMP) JewelrycraftMod.netWrapper.sendTo(new PacketClearColorCache(), (EntityPlayerMP)event.entity); + if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + final Entity entity = event.entity; + if (!event.world.isRemote && entity instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)entity; + NBTTagCompound persistTag = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + boolean shouldGiveManual = ItemList.guide != null && !persistTag.getBoolean("givenGuide"); + if (shouldGiveManual){ + ItemStack manual = new ItemStack(ItemList.guide); + if (!player.inventory.addItemStackToInventory(manual)) BlockUtils.dropItemStackInWorld(player.worldObj, player.posX, player.posY, player.posZ, manual); + persistTag.setBoolean("givenGuide", true); + } + boolean render = persistTag.getBoolean("fancyRender"); + JewelrycraftMod.fancyRender = render; + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(event.world) && !persistTag.hasKey(curse.getName())) persistTag.setInteger(curse.getName(), 0); + for(Curse curse: Curse.getCurseList()) + if (!curse.canCurseBeActivated(event.world)){ + Curse.availableCurses.remove(curse); + persistTag.setInteger(curse.getName(), 0); + totalUnavailableCurses++; + }else if (!Curse.availableCurses.contains(curse)) Curse.availableCurses.add(curse); + persistTag.setBoolean("sendInfo", true); + } + } + + /** + * @param event + */ + @SubscribeEvent + public void onEntityUpdate(LivingUpdateEvent event) + { + Entity entity = event.entity; + EntityLivingBase entityLiving = event.entityLiving; + if (entityLiving.isPotionActive(PotionList.stun)){ + entityLiving.motionX *= 0D; + entityLiving.motionZ *= 0D; + entityLiving.motionY *= 0D; + entityLiving.isSwingInProgress = false; + entityLiving.moveForward = 0F; + entityLiving.moveStrafing = 0F; + entityLiving.setAIMoveSpeed(0F); + entityLiving.limbSwing = 0F; + entityLiving.limbSwingAmount = 0F; + entityLiving.swingProgressInt = 0; + entityLiving.rotationPitch = entity.prevRotationPitch; + entityLiving.rotationYaw = entity.prevRotationYaw; + entityLiving.worldObj.spawnParticle("spell", entityLiving.posX, entityLiving.posY + entityLiving.getEyeHeight(), entityLiving.posZ, 0.0D, 0.3D, 0.0D); + } + if (entityLiving.isPotionActive(PotionList.stun) && entityLiving.getActivePotionEffect(PotionList.stun).getDuration() == 0) entityLiving.removePotionEffect(PotionList.stun.id); + if (entity instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)entity; + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + playerInfo.setBoolean("fancyRender", JewelrycraftMod.fancyRender); + if (updateTime > 0) updateTime--; + for(int i = 0; i < 18; i++) + if (playerInfo.hasKey("ext" + i)){ + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + if (item != null){ + if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).action(item, player); + if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onWearAction(item, player); + } + } + if (!player.worldObj.isRemote){ + if (playerInfo.hasKey("reselectCurses") && !playerInfo.getBoolean("reselectCurses")){ + playerInfo.setInteger("curseTime", playerInfo.getInteger("curseTime") - 10000); + if (playerInfo.getInteger("curseTime") <= 0) playerInfo.setBoolean("reselectCurses", true); + } + if (playerInfo.hasKey("playerCursePointsChanged") && playerInfo.getBoolean("playerCursePointsChanged")){ + int points = playerInfo.getInteger("cursePoints"); + for(int i = 1; i <= Variables.MAX_CURSES; i++) + if (points > (i - 1) * 1750) addCurse(player, playerInfo, i); + if (!playerInfo.hasKey("curseTime") || !playerInfo.hasKey("reselectCurses") || playerInfo.getBoolean("reselectCurses")){ + playerInfo.setInteger("curseTime", 23000); + playerInfo.setBoolean("reselectCurses", false); + } + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + if (addedCurses){ + JewelrycraftMod.netWrapper.sendToAll(new PacketSendServerPlayersInfo()); + // player.openGui(JewelrycraftMod.instance, 4, player.worldObj, 0, 0, 0); + addedCurses = false; + } + } + if (playerInfo.getBoolean("playerCursePointsChanged")) playerInfo.setBoolean("playerCursePointsChanged", false); + if (updateTime == 0){ + JewelrycraftMod.netWrapper.sendToAll(new PacketSendServerPlayersInfo()); + updateTime = 200; + } + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.action(player.worldObj, player); + } + } + } + + @SubscribeEvent + public void onEntityLivingDropItems(LivingDropsEvent event) + { + if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)event.source.getEntity(); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.entityDropItems(player, event.entityLiving, event.drops); + } + } + + /** + * @param event + */ + @SubscribeEvent + public void onEntityAttacked(LivingAttackEvent event) + { + EntityLivingBase entity = event.entityLiving; + if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityLivingBase && ((EntityLivingBase)event.source.getEntity()).isPotionActive(PotionList.stun)) event.setCanceled(true); + if (entity instanceof EntityPlayer && !(event.source.getEntity() instanceof EntityPlayer)){ + EntityPlayer player = (EntityPlayer)entity; + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + if (!player.worldObj.isRemote) for(int i = 0; i < 18; i++) + if (playerInfo.hasKey("ext" + i)){ + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + if (item != null && item.getItem() instanceof ItemBaseJewelry && ((ItemBaseJewelry)item.getItem()).onPlayerAttackedCacellable(item, player, event.source, event.ammount)){ + event.setCanceled(true); + break; + } + if (playerInfo.getBoolean("negateDamage")){ + playerInfo.setBoolean("negateDamage", false); + event.setCanceled(true); + break; + } + if (item != null){ + if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onPlayerAttacked(item, player, event.source, event.ammount); + if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onPlayerAttackedAction(item, player, event.source, event.ammount); + } + } + if (player.getHealth() != player.prevHealth){ + if (playerInfo.getFloat("WhiteHeart") > 0){ + playerInfo.setFloat("WhiteHeart", 0f); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + } + if (playerInfo.getFloat("BlueHeart") > 0){ + float damage = playerInfo.getFloat("BlueHeart") - event.ammount; + if (damage >= 0){ + playerInfo.setFloat("BlueHeart", damage); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + player.heal(event.ammount); + }else{ + playerInfo.setFloat("BlueHeart", 0f); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + player.heal(Math.abs(damage)); + } + }else if (playerInfo.getFloat("BlackHeart") > 0){ + AxisAlignedBB axisalignedbb = player.boundingBox.expand(2.0D, 0.0D, 2.0D); + List enemies = player.worldObj.getEntitiesWithinAABBExcludingEntity(player, axisalignedbb); + if (enemies != null && !enemies.isEmpty()){ + Iterator iterator = enemies.iterator(); + while (iterator.hasNext()){ + Entity enemy = (Entity)iterator.next(); + enemy.attackEntityFrom(DamageSourceList.blackHeart, 5f * event.ammount); + } + } + float damage = playerInfo.getFloat("BlackHeart") - event.ammount; + if (damage >= 0){ + playerInfo.setFloat("BlackHeart", damage); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + player.heal(event.ammount); + }else{ + playerInfo.setFloat("BlackHeart", 0f); + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + player.heal(Math.abs(damage)); + } + } + } + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.attackedAction(player.worldObj, player); + }else if (event.source.getEntity() instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)event.source.getEntity(); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + for(int i = 0; i < 18; i++) + if (playerInfo.hasKey("ext" + i)){ + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + if (item != null && item.getItem() instanceof ItemBaseJewelry && ((ItemBaseJewelry)item.getItem()).onEntityAttackedCacellable(item, player, entity, event.ammount)){ + event.setCanceled(true); + break; + } + if (playerInfo.getBoolean("weakDamage")){ + playerInfo.setBoolean("weakDamage", false); + event.setCanceled(true); + break; + } + if (item != null){ + if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onEntityAttacked(item, player, entity, event.ammount); + if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onEntityAttackedByPlayer(item, player, entity, event.ammount); + } + } + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.attackedByPlayerAction(entity.worldObj, player, entity); + } + } + + /** + * @param event + */ + @SubscribeEvent + public void onPlayerRespawn(PlayerEvent.Clone event) + { + EntityPlayer player = event.entityPlayer; + if (!player.worldObj.isRemote){ + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + if (playerInfo.hasKey("cursePoints")){ + int points = playerInfo.getInteger("cursePoints"); + for(int i = 1; i <= Variables.MAX_CURSES; i++) + if (points > (i - 1) * 1750) addCurse(player, playerInfo, i); + if (!playerInfo.hasKey("curseTime") || !playerInfo.hasKey("reselectCurses") || playerInfo.getBoolean("reselectCurses")){ + playerInfo.setInteger("curseTime", 23000); + playerInfo.setBoolean("reselectCurses", false); + } + } + playerInfo.setFloat("BlueHeart", 0f); + playerInfo.setFloat("BlackHeart", 0f); + playerInfo.setFloat("WhiteHeart", 0f); + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.respawnAction(player.worldObj, player); + for(int i = 0; i < 18; i++) + if (playerInfo.hasKey("ext" + i)){ + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + if (item != null){ + if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onPlayerRespawn(item, event); + if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onPlayerRespawnAction(item, event); + } + } + } + if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + if (!player.worldObj.isRemote){ + JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + if (addedCurses){ + JewelrycraftMod.netWrapper.sendToAll(new PacketSendServerPlayersInfo()); + // player.openGui(JewelrycraftMod.instance, 4, player.worldObj, 0, 0, 0); + addedCurses = false; + } + } + } + + /** + * @param player + * @param playerInfo + * @param curse + */ + public void addCurse(EntityPlayer player, NBTTagCompound playerInfo, int curseNo) + { + if (ConfigHandler.CURSES_ENABLED && Curse.availableCurses.size() > 0 && curseNo > Curse.getCurseList().size() - Curse.availableCurses.size() - totalUnavailableCurses){ + Curse cur = ((WeightedRandomCurse)WeightedRandom.getRandomItem(rand, JewelrycraftUtil.getCurses(player.worldObj, player, rand))).getCurse(rand); + playerInfo.setInteger(cur.getName(), 1); + Curse.availableCurses.remove(cur); + addedCurses = true; + } + } + + @SubscribeEvent + public void itemToss(ItemTossEvent event) + { + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(event.player, Variables.MODID); + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(event.player.worldObj) && playerInfo.getInteger(curse.getName()) > 0 && curse.itemToss()){ + EntityItem entityitem = new EntityItem(event.player.worldObj, event.player.posX + 0.5D, event.player.posY + 0.5D, event.player.posZ + 0.5D, event.entityItem.getEntityItem()); + entityitem.motionX = 0; + entityitem.motionZ = 0; + entityitem.motionY = 0.11000000298023224D; + event.player.worldObj.spawnEntityInWorld(entityitem); + MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText("<" + event.player.getDisplayName() + "> This is MY item! MINE! I will NEVER give it to you! Mine! Mine! MINE!")); + event.setCanceled(true); + } + } + + /** + * @param event + */ + @SubscribeEvent + public void playerFileSave(PlayerEvent.SaveToFile event) + { + if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + } + + /** + * @param event + */ + @SubscribeEvent + public void onEntityDead(LivingDeathEvent event) + { + final Entity entity = event.entity; + Random rand = new Random(); + String[] types = {"Red", "Blue", "White", "Black"}; + if (!entity.worldObj.isRemote && !(entity instanceof EntityPlayer) && entity instanceof EntityLiving){ + EntityLiving live = (EntityLiving)entity; + String type = types[rand.nextInt(4)]; + if (rand.nextInt(6) == 0 && live.getCreatureAttribute() != JewelrycraftUtil.HEART){ + if (type == "White"){ + EntityHeart h = new EntityHalfHeart(live.worldObj); + h.setType(type); + h.setLocationAndAngles(live.posX, live.posY, live.posZ, MathHelper.wrapAngleTo180_float(rand.nextFloat() * 360.0F), 0.0F); + live.worldObj.spawnEntityInWorld(h); + }else{ + for(int i = 1; i <= 1 + rand.nextInt(1 + (int)(live.getMaxHealth() / 20)); i++){ + EntityHeart[] hearts = {new EntityHeart(live.worldObj), new EntityHalfHeart(entity.worldObj)}; + EntityHeart h = hearts[rand.nextInt(2)]; + h.setType(type); + h.setLocationAndAngles(live.posX, live.posY, live.posZ, MathHelper.wrapAngleTo180_float(rand.nextFloat() * 360.0F), 0.0F); + live.worldObj.spawnEntityInWorld(h); + } + } + } + if (event.source.getEntity() != null && event.source.getEntity() instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)event.source.getEntity(); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.entityDeathAction(player.worldObj, event.entityLiving, player); + } + } + if (entity instanceof EntityPlayer){ + EntityPlayer player = (EntityPlayer)entity; + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID); + playerInfo.setFloat("BlueHeart", 0f); + playerInfo.setFloat("BlackHeart", 0f); + playerInfo.setFloat("WhiteHeart", 0f); + if (playerInfo.hasKey("reselectCurses") && playerInfo.getBoolean("reselectCurses")){ + if (ConfigHandler.CURSES_ENABLED) for(Curse l: Curse.getCurseList()){ + if (l.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(l.getName()) == 1){ + playerInfo.setInteger(l.getName(), 0); + if (!Curse.availableCurses.contains(l)) Curse.availableCurses.add(l); + }else if (l.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(l.getName()) >= 2) playerInfo.setInteger(l.getName(), 1); + } + if (entity.worldObj.isRemote) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + } + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0) curse.playerDeathAction(player.worldObj, player); + for(int i = 0; i < 18; i++) + if (playerInfo.hasKey("ext" + i)){ + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + if (item != null){ + if (item.getItem() instanceof ItemBaseJewelry) ((ItemBaseJewelry)item.getItem()).onPlayerDead(item, player, event.source); + if (item.getItem() instanceof IJewelryItem) ((IJewelryItem)item.getItem()).onPlayerDeadAction(item, player, event.source); + } + } + } + if (event.entity instanceof EntityPlayer && !(event.entity instanceof EntityPlayerMP)) JewelrycraftMod.netWrapper.sendToServer(new PacketRequestPlayerInfo()); + } + + /** + * @param event + */ + @SubscribeEvent + public void onWorldLoad(WorldEvent.Load event) + { + if (!event.world.isRemote){ + new File(JewelrycraftMod.dir + File.separator + Variables.MODID).mkdirs(); + JewelrycraftMod.liquidsConf = new File(JewelrycraftMod.dir + File.separator + Variables.MODID, "JLP" + event.world.getWorldInfo().getWorldName() + ".cfg"); + try{ + if (!JewelrycraftMod.liquidsConf.exists()) JewelrycraftMod.liquidsConf.createNewFile(); + } + catch(IOException e){ + e.printStackTrace(); + } + } + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) try{ + if (JewelrycraftMod.liquidsConf.exists()) JewelrycraftMod.saveData = CompressedStreamTools.readCompressed(new FileInputStream(JewelrycraftMod.liquidsConf)); + } + catch(EOFException e){ + e.printStackTrace(); + } + catch(IOException e){ + e.printStackTrace(); + } + } + + /** + * @param event + */ + @SubscribeEvent + public void onWorldSave(WorldEvent.Save event) + { + if (FMLCommonHandler.instance().getEffectiveSide().isServer()) try{ + if (JewelrycraftMod.liquidsConf.exists()) CompressedStreamTools.writeCompressed(JewelrycraftMod.saveData, new FileOutputStream(JewelrycraftMod.liquidsConf)); + } + catch(EOFException e){ + e.printStackTrace(); + } + catch(IOException e){ + e.printStackTrace(); + } + } + + /** + * @param event + */ + @SubscribeEvent + @SideOnly (Side.CLIENT) + public void fogColors(EntityViewRenderEvent.FogColors event) + {} + + /** + * @param event + */ + @SubscribeEvent + @SideOnly (Side.CLIENT) + public void fogDensity(EntityViewRenderEvent.FogDensity event) + {} + + /** + * @param event + */ + @SubscribeEvent + @SideOnly (Side.CLIENT) + public void renderFog(EntityViewRenderEvent.RenderFogEvent event) + {} } \ No newline at end of file diff --git a/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java b/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java index 9eb783f..5da4b7a 100644 --- a/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java +++ b/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java @@ -1,201 +1,234 @@ -package darkknight.jewelrycraft.events; - -import java.nio.FloatBuffer; -import java.util.Iterator; -import net.minecraft.block.Block; -import net.minecraft.block.BlockAir; -import net.minecraft.client.Minecraft; -import net.minecraft.client.model.ModelBiped; -import net.minecraft.client.model.ModelRenderer; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.Vec3; -import net.minecraftforge.client.event.RenderHandEvent; -import net.minecraftforge.client.event.RenderPlayerEvent; -import org.lwjgl.BufferUtils; -import org.lwjgl.opengl.GL11; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import darkknight.jewelrycraft.api.Curse; -import darkknight.jewelrycraft.config.ConfigHandler; -import darkknight.jewelrycraft.item.render.BraceletRender; -import darkknight.jewelrycraft.item.render.EarringsRender; -import darkknight.jewelrycraft.item.render.NecklaceRender; -import darkknight.jewelrycraft.item.render.RingRender; -import darkknight.jewelrycraft.util.JewelryNBT; - -public class PlayerRenderHandler -{ - EarringsRender earrings = new EarringsRender(); - BraceletRender bracelet = new BraceletRender(); - NecklaceRender necklace = new NecklaceRender(); - RingRender ring = new RingRender(); - public static NBTTagCompound playersInfo = new NBTTagCompound(); - float size = 0.055F; - - @SubscribeEvent - public void renderScreen(RenderPlayerEvent.Specials.Post event) - { - GL11.glPushMatrix(); - ModelBiped main = event.renderer.modelBipedMain; - ModelRenderer rightArm = event.renderer.modelBipedMain.bipedRightArm; - ModelRenderer leftArm = event.renderer.modelBipedMain.bipedLeftArm; - ModelRenderer head = event.renderer.modelBipedMain.bipedHead; - ModelRenderer body = event.renderer.modelBipedMain.bipedBody; - Iterator players = event.entityPlayer.worldObj.playerEntities.iterator(); - if (playersInfo != null){ - while (players.hasNext()){ - int[] gemColor = {-1, -1, -1, -1}; - int[] ingotColor = {-1, -1, -1, -1}; - int gem = -1; - int ingot = -1; - EntityPlayer player = players.next(); - NBTTagCompound playerInfo = (NBTTagCompound)playersInfo.getTag(player.getDisplayName()); - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0 && event.entityPlayer.getDisplayName().equals(player.getDisplayName()) && playerInfo.getInteger("cursePoints") > 0) curse.playerRender(player, event); - int no = 0; - ModelRenderer arm = rightArm; - if (player.inventory.getCurrentItem() != null && Block.getBlockFromItem(player.inventory.getCurrentItem().getItem()) instanceof BlockAir){ - GL11.glDisable(GL11.GL_LIGHT1); - FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(4); - Vec3 lightPos = Vec3.createVectorHelper(0.0D, 2.0D, 1.0D).normalize(); - colorBuffer.clear(); - colorBuffer.put((float)lightPos.xCoord).put((float)lightPos.yCoord).put((float)lightPos.zCoord).put(-1F); - colorBuffer.flip(); - GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, colorBuffer); - colorBuffer.clear(); - colorBuffer.put(0.03f).put(0.03f).put(0.03f).put(1.0F); - colorBuffer.flip(); - GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, colorBuffer); - // GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, setColorBuffer(0.0F, 0.0F, 0.0F, 1.0F)); GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, setColorBuffer(var2, var2, var2, 1.0F)); - } - for(int i = 0; i <= 9; i++) - if (playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ - gem = -1; - ingot = -1; - if (no > 4) arm = leftArm; - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - GL11.glPushMatrix(); - if (arm.rotateAngleX == 0.0F && arm.rotateAngleY == 0.0F && arm.rotateAngleZ == 0.0F){ - if (arm.rotationPointX != 0.0F || arm.rotationPointY != 0.0F || arm.rotationPointZ != 0.0F) GL11.glTranslatef(arm.rotationPointX * size, arm.rotationPointY * size, arm.rotationPointZ * size); - }else{ - GL11.glTranslatef(arm.rotationPointX * size, arm.rotationPointY * size, arm.rotationPointZ * size); - if (arm.rotateAngleZ != 0.0F) GL11.glRotatef(arm.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); - if (arm.rotateAngleY != 0.0F) GL11.glRotatef(arm.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); - if (arm.rotateAngleX != 0.0F) GL11.glRotatef(arm.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); - } - if (JewelryNBT.ingot(item) != null) ingot = JewelryNBT.ingotColor(item); - if (JewelryNBT.gem(item) != null) gem = JewelryNBT.gemColor(item); - if (no <= 4) GL11.glTranslatef(0.64F + 0.05F * no, -1.15F, 0.07F); - else GL11.glTranslatef(0.59F + 0.05F * no, -1.15F, 0.07F); - GL11.glScalef(0.1f, 0.15f, 0.1f); - ring.doRender(event.entityPlayer, 0F, 0F, (float)ingot, (float)gem, 0F); - GL11.glPopMatrix(); - no++; - } - for(int i = 10; i <= 13; i++) - if (playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - if (JewelryNBT.gem(item) != null) gemColor[i - 10] = JewelryNBT.gemColor(item); - if (JewelryNBT.ingot(item) != null) ingotColor[i - 10] = JewelryNBT.ingotColor(item); - } - if ((playerInfo.hasKey("ext10") || playerInfo.hasKey("ext11")) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ - GL11.glPushMatrix(); - GL11.glColor4f(1, 1, 1, 1); - if (rightArm.rotateAngleX == 0.0F && rightArm.rotateAngleY == 0.0F && rightArm.rotateAngleZ == 0.0F){ - if (rightArm.rotationPointX != 0.0F || rightArm.rotationPointY != 0.0F || rightArm.rotationPointZ != 0.0F) GL11.glTranslatef(rightArm.rotationPointX * size, rightArm.rotationPointY * size, rightArm.rotationPointZ * size); - }else{ - GL11.glTranslatef(rightArm.rotationPointX * size, rightArm.rotationPointY * size, rightArm.rotationPointZ * size); - if (rightArm.rotateAngleZ != 0.0F) GL11.glRotatef(rightArm.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); - if (rightArm.rotateAngleY != 0.0F) GL11.glRotatef(rightArm.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); - if (rightArm.rotateAngleX != 0.0F) GL11.glRotatef(rightArm.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); - } - GL11.glScalef(0.05f, 0.03f, 0.05f); - bracelet.doRender(event.entityPlayer, (float)ingotColor[0], (float)gemColor[0], (float)ingotColor[1], (float)gemColor[1], 0.0F); - GL11.glPopMatrix(); - } - if ((playerInfo.hasKey("ext12") || playerInfo.hasKey("ext13")) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ - GL11.glPushMatrix(); - GL11.glColor4f(1, 1, 1, 1); - if (leftArm.rotateAngleX == 0.0F && leftArm.rotateAngleY == 0.0F && leftArm.rotateAngleZ == 0.0F){ - if (leftArm.rotationPointX != 0.0F || leftArm.rotationPointY != 0.0F || leftArm.rotationPointZ != 0.0F) GL11.glTranslatef(leftArm.rotationPointX * size, leftArm.rotationPointY * size, leftArm.rotationPointZ * size); - }else{ - GL11.glTranslatef(leftArm.rotationPointX * size + 0.2F, leftArm.rotationPointY * size, leftArm.rotationPointZ * size); - if (leftArm.rotateAngleZ != 0.0F) GL11.glRotatef(leftArm.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); - if (leftArm.rotateAngleY != 0.0F) GL11.glRotatef(leftArm.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); - if (leftArm.rotateAngleX != 0.0F) GL11.glRotatef(leftArm.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); - } - GL11.glScalef(0.05f, 0.03f, 0.05f); - bracelet.doRender(event.entityPlayer, (float)ingotColor[2], (float)gemColor[2], (float)ingotColor[3], (float)gemColor[3], 0F); - GL11.glPopMatrix(); - } - no = 0; - for(int i = 14; i <= 16; i++) - if (playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ - gem = -1; - ingot = -1; - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - GL11.glPushMatrix(); - if (body.rotateAngleX == 0.0F && body.rotateAngleY == 0.0F && body.rotateAngleZ == 0.0F){ - if (body.rotationPointX != 0.0F || body.rotationPointY != 0.0F || body.rotationPointZ != 0.0F) GL11.glTranslatef(body.rotationPointX * size, body.rotationPointY * size, body.rotationPointZ * size); - }else{ - GL11.glTranslatef(body.rotationPointX * size, body.rotationPointY * size, body.rotationPointZ * size); - if (body.rotateAngleZ != 0.0F) GL11.glRotatef(body.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); - if (body.rotateAngleY != 0.0F) GL11.glRotatef(body.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); - if (body.rotateAngleX != 0.0F) GL11.glRotatef(body.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); - } - GL11.glScalef(0.0625f, 0.0625f, 0.0625f); - if (JewelryNBT.gem(item) != null) gem = JewelryNBT.gemColor(item); - if (JewelryNBT.ingot(item) != null) ingot = JewelryNBT.ingotColor(item); - if (no > 0){ - GL11.glRotatef(no == 1 ? 25f : -25f, 0F, 0f, 1f); - GL11.glRotatef(no == 1 ? -5f : -10f, 1F, 0f, 0f); - } - necklace.doRender(event.entityPlayer, 0F, 0F, (float)ingot, (float)gem, 0F); - GL11.glPopMatrix(); - no++; - } - if (playerInfo.hasKey("ext17") && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ - gem = -1; - ingot = -1; - NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext17"); - ItemStack item = ItemStack.loadItemStackFromNBT(nbt); - GL11.glPushMatrix(); - if (head.rotateAngleX == 0.0F && head.rotateAngleY == 0.0F && head.rotateAngleZ == 0.0F){ - if (head.rotationPointX != 0.0F || head.rotationPointY != 0.0F || head.rotationPointZ != 0.0F) GL11.glTranslatef(head.rotationPointX * size, head.rotationPointY * size, head.rotationPointZ * size); - }else{ - GL11.glTranslatef(head.rotationPointX * size, head.rotationPointY * size, head.rotationPointZ * size); - if (head.rotateAngleZ != 0.0F) GL11.glRotatef(head.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); - if (head.rotateAngleY != 0.0F) GL11.glRotatef(head.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); - if (head.rotateAngleX != 0.0F) GL11.glRotatef(head.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); - } - GL11.glScalef(0.0625f, 0.0625f, 0.0625f); - GL11.glTranslatef(0.0F, 1.0F, -2.0F); - if (JewelryNBT.gem(item) != null) gem = JewelryNBT.gemColor(item); - if (JewelryNBT.ingot(item) != null) ingot = JewelryNBT.ingotColor(item); - earrings.doRender(event.entityPlayer, 0F, 0F, (float)ingot, (float)gem, 0F); - GL11.glPopMatrix(); - } - } - } - GL11.glPopMatrix(); - } - - float rot = 0F; - - @SubscribeEvent - public void renderHand(RenderHandEvent event) - { - if (playersInfo != null){ - EntityPlayer player = Minecraft.getMinecraft().thePlayer; - if (player != null){ - NBTTagCompound playerInfo = (NBTTagCompound)playersInfo.getTag(player.getDisplayName()); - if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) - if (curse.canCurseBeActivated(player.worldObj) && curse != null && playerInfo != null && playerInfo.hasKey(curse.getName()) && playerInfo.getInteger(curse.getName()) > 0 && playerInfo.hasKey("cursePoints") && playerInfo.getInteger("cursePoints") > 0) curse.playerHandRender(player, event); - } - } - } -} +package darkknight.jewelrycraft.events; + +import java.nio.FloatBuffer; +import java.util.Iterator; +import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBiped; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.Vec3; +import net.minecraftforge.client.event.RenderHandEvent; +import net.minecraftforge.client.event.RenderPlayerEvent; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import darkknight.jewelrycraft.api.Curse; +import darkknight.jewelrycraft.config.ConfigHandler; +import darkknight.jewelrycraft.item.render.BraceletRender; +import darkknight.jewelrycraft.item.render.EarringsRender; +import darkknight.jewelrycraft.item.render.NecklaceRender; +import darkknight.jewelrycraft.item.render.RingRender; +import darkknight.jewelrycraft.util.JewelryNBT; + +public class PlayerRenderHandler +{ + EarringsRender earrings = new EarringsRender(); + BraceletRender bracelet = new BraceletRender(); + NecklaceRender necklace = new NecklaceRender(); + RingRender ring = new RingRender(); + public static NBTTagCompound playersInfo = new NBTTagCompound(); + float size = 0.055F; + + @SubscribeEvent + public void renderScreen(RenderPlayerEvent.Specials.Post event) + { + GL11.glPushMatrix(); + ModelBiped main = event.renderer.modelBipedMain; + ModelRenderer rightArm = event.renderer.modelBipedMain.bipedRightArm; + ModelRenderer leftArm = event.renderer.modelBipedMain.bipedLeftArm; + ModelRenderer head = event.renderer.modelBipedMain.bipedHead; + ModelRenderer body = event.renderer.modelBipedMain.bipedBody; + Iterator players = event.entityPlayer.worldObj.playerEntities.iterator(); + float rotAngleX = 0F, rotAngleY = 0F, rotAngleZ = 0F; + if (playersInfo != null){ + while (players.hasNext()){ + int[] gemColor = {-1, -1, -1, -1}; + int[] ingotColor = {-1, -1, -1, -1}; + int gem = -1; + int ingot = -1; + EntityPlayer player = players.next(); + NBTTagCompound playerInfo = (NBTTagCompound)playersInfo.getTag(player.getDisplayName()); + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && playerInfo.getInteger(curse.getName()) > 0 && event.entityPlayer.getDisplayName().equals(player.getDisplayName()) && playerInfo.getInteger("cursePoints") > 0) curse.playerRender(player, event); + int no = 0; + ModelRenderer arm = rightArm; + if (player.inventory.getCurrentItem() != null && Block.getBlockFromItem(player.inventory.getCurrentItem().getItem()) instanceof BlockAir){ + GL11.glDisable(GL11.GL_LIGHT1); + FloatBuffer colorBuffer = BufferUtils.createFloatBuffer(4); + Vec3 lightPos = Vec3.createVectorHelper(0.0D, 2.0D, 1.0D).normalize(); + colorBuffer.clear(); + colorBuffer.put((float)lightPos.xCoord).put((float)lightPos.yCoord).put((float)lightPos.zCoord).put(-1F); + colorBuffer.flip(); + GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, colorBuffer); + colorBuffer.clear(); + colorBuffer.put(0.03f).put(0.03f).put(0.03f).put(1.0F); + colorBuffer.flip(); + GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, colorBuffer); + } + for(int i = 0; i <= 9; i++) + if (playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ + gem = -1; + ingot = -1; + if (no > 4) arm = leftArm; + float s = 0.055F; + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + if (Loader.isModLoaded("alpaca")) arm = body; + GL11.glPushMatrix(); + if (arm.rotateAngleX == 0.0F && arm.rotateAngleY == 0.0F && arm.rotateAngleZ == 0.0F){ + if ((arm.rotationPointX + rotAngleX) != 0.0F || (arm.rotationPointY + rotAngleY) != 0.0F || (arm.rotationPointZ + rotAngleZ) != 0.0F) GL11.glTranslatef((arm.rotationPointX + rotAngleX) * s, (arm.rotationPointY + rotAngleY) * s, (arm.rotationPointZ + rotAngleZ) * s); + }else if(!Loader.isModLoaded("alpaca")){ + GL11.glTranslatef((arm.rotationPointX + rotAngleX) * s, (arm.rotationPointY + rotAngleY) * s, (arm.rotationPointZ + rotAngleZ) * s); + if (arm.rotateAngleZ != 0.0F) GL11.glRotatef(arm.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); + if (arm.rotateAngleY != 0.0F) GL11.glRotatef(arm.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); + if (arm.rotateAngleX != 0.0F) GL11.glRotatef(arm.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); + } + if (JewelryNBT.ingot(item) != null) ingot = JewelryNBT.ingotColor(item); + if (JewelryNBT.gem(item) != null) gem = JewelryNBT.gemColor(item); + float scale = 0.1f; + if (Loader.isModLoaded("alpaca")){ + if (no <= 4){ + GL11.glTranslatef(0.35F, -4.35F, -2.8F + 0.15F * no); + GL11.glRotatef(90f, 0F, 1F, 0F); + } + else{ + GL11.glTranslatef(-0.35F, -4.35F, 1.48F + 0.15F * no); + GL11.glRotatef(-90f, 0F, 1F, 0F); + } + scale = 0.3F; + } + else{ + if (no <= 4) GL11.glTranslatef(0.64F + 0.05F * no, -1.15F, 0.07F); + else GL11.glTranslatef(0.59F + 0.05F * no, -1.15F, 0.07F); + } + GL11.glScalef(scale, scale + scale/2, scale); + ring.doRender(event.entityPlayer, 0F, 0F, (float)ingot, (float)gem, 0F); + GL11.glPopMatrix(); + no++; + } + for(int i = 10; i <= 13; i++) + if (playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + if (JewelryNBT.gem(item) != null) gemColor[i - 10] = JewelryNBT.gemColor(item); + if (JewelryNBT.ingot(item) != null) ingotColor[i - 10] = JewelryNBT.ingotColor(item); + } + if ((playerInfo.hasKey("ext10") || playerInfo.hasKey("ext11")) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + if (Loader.isModLoaded("alpaca")) + { + rightArm = body; + GL11.glTranslatef(0.0F, 0.05F, 0.0F); + GL11.glRotatef(-30F, 0.0F, 1.0F, 0.0F); + } + if (rightArm.rotateAngleX == 0.0F && rightArm.rotateAngleY == 0.0F && rightArm.rotateAngleZ == 0.0F){ + if ((rightArm.rotationPointX + rotAngleX) != 0.0F || (rightArm.rotationPointY + rotAngleY) != 0.0F || (rightArm.rotationPointZ + rotAngleZ) != 0.0F) GL11.glTranslatef((rightArm.rotationPointX + rotAngleX) * size, (rightArm.rotationPointY + rotAngleY) * size, (rightArm.rotationPointZ + rotAngleZ) * size); + }else if(!Loader.isModLoaded("alpaca")){ + GL11.glTranslatef((rightArm.rotationPointX + rotAngleX) * size, (rightArm.rotationPointY + rotAngleY) * size, (rightArm.rotationPointZ + rotAngleZ) * size); + if (rightArm.rotateAngleZ != 0.0F) GL11.glRotatef(rightArm.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); + if (rightArm.rotateAngleY != 0.0F) GL11.glRotatef(rightArm.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); + if (rightArm.rotateAngleX != 0.0F) GL11.glRotatef(rightArm.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); + } + GL11.glScalef(0.05f, 0.03f, 0.05f); + bracelet.doRender(event.entityPlayer, (float)ingotColor[0], (float)gemColor[0], (float)ingotColor[1], (float)gemColor[1], 0.0F); + GL11.glPopMatrix(); + } + if ((playerInfo.hasKey("ext12") || playerInfo.hasKey("ext13")) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + if (Loader.isModLoaded("alpaca")) + { + leftArm = body; + GL11.glTranslatef(-0.1F, 0.0F, 0.1F); + GL11.glRotatef(-140F, 0.0F, 1.0F, 0.0F); + } + if (leftArm.rotateAngleX == 0.0F && leftArm.rotateAngleY == 0.0F && leftArm.rotateAngleZ == 0.0F){ + if ((leftArm.rotationPointX + rotAngleX) != 0.0F || (leftArm.rotationPointY + rotAngleY) != 0.0F || (leftArm.rotationPointZ + rotAngleZ) != 0.0F) GL11.glTranslatef((leftArm.rotationPointX + rotAngleX) * size, (leftArm.rotationPointY + rotAngleY) * size, (leftArm.rotationPointZ + rotAngleZ) * size); + }else if(!Loader.isModLoaded("alpaca")){ + GL11.glTranslatef((leftArm.rotationPointX + rotAngleX) * size + 0.2F, (leftArm.rotationPointY + rotAngleY) * size, (leftArm.rotationPointZ + rotAngleZ) * size); + if (leftArm.rotateAngleZ != 0.0F) GL11.glRotatef(leftArm.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); + if (leftArm.rotateAngleY != 0.0F) GL11.glRotatef(leftArm.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); + if (leftArm.rotateAngleX != 0.0F) GL11.glRotatef(leftArm.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); + } + GL11.glScalef(0.05f, 0.03f, 0.05f); + bracelet.doRender(event.entityPlayer, (float)ingotColor[2], (float)gemColor[2], (float)ingotColor[3], (float)gemColor[3], 0F); + GL11.glPopMatrix(); + } + no = 0; + for(int i = 14; i <= 16; i++) + if (playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ + gem = -1; + ingot = -1; + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext" + i); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + GL11.glPushMatrix(); + if (body.rotateAngleX == 0.0F && body.rotateAngleY == 0.0F && body.rotateAngleZ == 0.0F){ + if (body.rotationPointX != 0.0F || body.rotationPointY != 0.0F || body.rotationPointZ != 0.0F) GL11.glTranslatef(body.rotationPointX * size, body.rotationPointY * size, body.rotationPointZ * size); + }else if(!Loader.isModLoaded("alpaca")){ + GL11.glTranslatef(body.rotationPointX * size, body.rotationPointY * size, body.rotationPointZ * size); + if (body.rotateAngleZ != 0.0F) GL11.glRotatef(body.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); + if (body.rotateAngleY != 0.0F) GL11.glRotatef(body.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); + if (body.rotateAngleX != 0.0F) GL11.glRotatef(body.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); + } + if (Loader.isModLoaded("alpaca")) GL11.glTranslatef(0.0F, 0.55F, -0.28F); + GL11.glScalef(0.0625f, 0.0625f, 0.0625f); + if (JewelryNBT.gem(item) != null) gem = JewelryNBT.gemColor(item); + if (JewelryNBT.ingot(item) != null) ingot = JewelryNBT.ingotColor(item); + if (no > 0){ + GL11.glRotatef(no == 1 ? 25f : -25f, 0F, 0f, 1f); + GL11.glRotatef(no == 1 ? -5f : -10f, 1F, 0f, 0f); + } + necklace.doRender(event.entityPlayer, 0F, 0F, (float)ingot, (float)gem, 0F); + GL11.glPopMatrix(); + no++; + } + if (playerInfo.hasKey("ext17") && event.entityPlayer.getDisplayName().equals(player.getDisplayName())){ + gem = -1; + ingot = -1; + NBTTagCompound nbt = (NBTTagCompound)playerInfo.getTag("ext17"); + ItemStack item = ItemStack.loadItemStackFromNBT(nbt); + GL11.glPushMatrix(); + float s = 0.0625F; + if (Loader.isModLoaded("alpaca")) head = body; + if (head.rotateAngleX == 0.0F && head.rotateAngleY == 0.0F && head.rotateAngleZ == 0.0F){ + if (head.rotationPointX != 0.0F || head.rotationPointY != 0.0F || head.rotationPointZ != 0.0F) GL11.glTranslatef(head.rotationPointX * size, head.rotationPointY * size, head.rotationPointZ * size); + }else if(!Loader.isModLoaded("alpaca")){ + GL11.glTranslatef(head.rotationPointX * size, head.rotationPointY * size, head.rotationPointZ * size); + if (head.rotateAngleZ != 0.0F) GL11.glRotatef(head.rotateAngleZ * (180F / (float)Math.PI), 0.0F, 0.0F, 1.0F); + if (head.rotateAngleY != 0.0F) GL11.glRotatef(head.rotateAngleY * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); + if (head.rotateAngleX != 0.0F) GL11.glRotatef(head.rotateAngleX * (180F / (float)Math.PI), 1.0F, 0.0F, 0.0F); + } + if (Loader.isModLoaded("alpaca")) GL11.glTranslatef(0.0F, 0.7F, -0.2F); + GL11.glScalef(s, s, s); + GL11.glTranslatef(0.0F, 1.0F, -2.0F); + if (JewelryNBT.gem(item) != null) gem = JewelryNBT.gemColor(item); + if (JewelryNBT.ingot(item) != null) ingot = JewelryNBT.ingotColor(item); + earrings.doRender(event.entityPlayer, 0F, 0F, (float)ingot, (float)gem, 0F); + GL11.glPopMatrix(); + } + } + } + GL11.glPopMatrix(); + } + + float rot = 0F; + + @SubscribeEvent + public void renderHand(RenderHandEvent event) + { + if (playersInfo != null){ + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + if (player != null){ + NBTTagCompound playerInfo = (NBTTagCompound)playersInfo.getTag(player.getDisplayName()); + if (ConfigHandler.CURSES_ENABLED) for(Curse curse: Curse.getCurseList()) + if (curse.canCurseBeActivated(player.worldObj) && curse != null && playerInfo != null && playerInfo.hasKey(curse.getName()) && playerInfo.getInteger(curse.getName()) > 0 && playerInfo.hasKey("cursePoints") && playerInfo.getInteger("cursePoints") > 0) curse.playerHandRender(player, event); + } + } + } +} -- cgit v1.2.3