From 5c33896dd214ffd89e2170a06b4e431e9edaca7e Mon Sep 17 00:00:00 2001 From: makeo Date: Tue, 8 Dec 2015 00:08:04 +0100 Subject: [PATCH] -Added enchantment handling --- .../common/events/EventHandlerEntity.java | 62 ++++++++++++++----- .../gadomancy/coremod/GadomancyCore.java | 6 +- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java b/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java index 0081967..e79527c 100644 --- a/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java +++ b/src/main/java/makeo/gadomancy/common/events/EventHandlerEntity.java @@ -13,6 +13,8 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.boss.IBossDisplayData; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.server.MinecraftServer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChunkCoordinates; @@ -25,6 +27,8 @@ import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; import net.minecraftforge.event.entity.player.EntityItemPickupEvent; import thaumcraft.common.items.armor.Hover; +import java.util.List; + /** * This class is part of the Gadomancy Mod * Gadomancy is Open Source and distributed under the @@ -34,7 +38,6 @@ import thaumcraft.common.items.armor.Hover; * Created by HellFirePvP @ 31.10.2015 15:28 */ public class EventHandlerEntity { - /*@SubscribeEvent(priority = EventPriority.LOWEST) public void on(EntityEvent.EntityConstructing e) { if (e.entity instanceof EntityPlayer) { @@ -43,17 +46,46 @@ public class EventHandlerEntity { }*/ public static int onGetFortuneLevel(EntityLivingBase entity) { - return 400; + return getRealEnchantmentLevel(Enchantment.fortune.effectId, entity.getHeldItem()) + 1000; } public static int onGetEnchantmentLevel(int enchantmentId, ItemStack stack) { - return 0; + if(stack != null && Enchantment.fortune.effectId == enchantmentId) { + MinecraftServer server = MinecraftServer.getServer(); + if(server != null) { + for(EntityPlayer player : (List)server.getConfigurationManager().playerEntityList) { + if(player.getHeldItem() == stack) { + return onGetFortuneLevel(player); + } + } + } + } + return getRealEnchantmentLevel(enchantmentId, stack); + } + + private static int getRealEnchantmentLevel(int enchantmentId, ItemStack stack) { + if (stack == null) { + return 0; + } else { + NBTTagList nbttaglist = stack.getEnchantmentTagList(); + if (nbttaglist == null) { + return 0; + } else { + for (int j = 0; j < nbttaglist.tagCount(); ++j) { + short id = nbttaglist.getCompoundTagAt(j).getShort("id"); + if (id == enchantmentId) { + return nbttaglist.getCompoundTagAt(j).getShort("lvl"); + } + } + return 0; + } + } } @SubscribeEvent public void on(EnderTeleportEvent e) { - if(!(e.entityLiving instanceof EntityPlayer) && !(e.entityLiving instanceof IBossDisplayData)) { - if(TileBlockProtector.isSpotProtected(e.entityLiving.worldObj, e.entityLiving)) { + if (!(e.entityLiving instanceof EntityPlayer) && !(e.entityLiving instanceof IBossDisplayData)) { + if (TileBlockProtector.isSpotProtected(e.entityLiving.worldObj, e.entityLiving)) { e.setCanceled(true); } } @@ -61,26 +93,26 @@ public class EventHandlerEntity { @SubscribeEvent public void on(LivingSetAttackTargetEvent targetEvent) { - if(targetEvent.target instanceof EntityPlayer) { + if (targetEvent.target instanceof EntityPlayer) { FamiliarAIController.notifyTargetEvent(targetEvent.entityLiving, (EntityPlayer) targetEvent.target); } } @SubscribeEvent public void on(LivingDeathEvent event) { - if(!event.entity.worldObj.isRemote && event.entityLiving instanceof EntityPlayer) { + if (!event.entity.worldObj.isRemote && event.entityLiving instanceof EntityPlayer) { TCMazeHandler.closeSession((EntityPlayer) event.entityLiving, false); } } @SubscribeEvent public void on(EntityItemPickupEvent event) { - if(!event.entityPlayer.worldObj.isRemote) { - if(event.item != null && event.item instanceof EntityPermNoClipItem) { + if (!event.entityPlayer.worldObj.isRemote) { + if (event.item != null && event.item instanceof EntityPermNoClipItem) { EntityPermNoClipItem item = (EntityPermNoClipItem) event.item; ChunkCoordinates master = (ChunkCoordinates) item.getDataWatcher().getWatchedObject(ModConfig.entityNoClipItemDatawatcherMasterId).getObject(); TileEntity te = event.entityPlayer.worldObj.getTileEntity(master.posX, master.posY, master.posZ); - if(te == null || !(te instanceof TileAuraPylon)) return; + if (te == null || !(te instanceof TileAuraPylon)) return; ((TileAuraPylon) te).informItemPickup(); } } @@ -88,14 +120,14 @@ public class EventHandlerEntity { @SubscribeEvent public void on(LivingEvent.LivingUpdateEvent event) { - if(event.entityLiving == null || !(event.entityLiving instanceof EntityPlayer)) return; - EntityPlayer player = (EntityPlayer)event.entity; - if ((event.entity.worldObj.provider.dimensionId == ModConfig.dimOuterId) && ((player.ticksExisted & 7) == 0) && ((player.capabilities.isFlying) || (Hover.getHover(player.getEntityId())))){ + if (event.entityLiving == null || !(event.entityLiving instanceof EntityPlayer)) return; + EntityPlayer player = (EntityPlayer) event.entity; + if ((event.entity.worldObj.provider.dimensionId == ModConfig.dimOuterId) && ((player.ticksExisted & 7) == 0) && ((player.capabilities.isFlying) || (Hover.getHover(player.getEntityId())))) { player.capabilities.isFlying = false; Hover.setHover(player.getEntityId(), false); - if(!((EntityPlayer) event.entityLiving).worldObj.isRemote) { + if (!((EntityPlayer) event.entityLiving).worldObj.isRemote) { String msg = StatCollector.translateToLocal("tc.break.fly"); - if(player.capabilities.isCreativeMode) { + if (player.capabilities.isCreativeMode) { msg += " " + StatCollector.translateToLocal("gadomancy.eldritch.noflyCreative"); } player.addChatMessage(new ChatComponentText(EnumChatFormatting.ITALIC + "" + EnumChatFormatting.GRAY + msg)); diff --git a/src/main/java/makeo/gadomancy/coremod/GadomancyCore.java b/src/main/java/makeo/gadomancy/coremod/GadomancyCore.java index 421e5ec..213c8cb 100644 --- a/src/main/java/makeo/gadomancy/coremod/GadomancyCore.java +++ b/src/main/java/makeo/gadomancy/coremod/GadomancyCore.java @@ -13,12 +13,8 @@ import java.util.Map; *

* Created by makeo @ 07.12.2015 21:17 */ -@IFMLLoadingPlugin.TransformerExclusions({"makeo.gadomancy.api", "makeo.gadomancy.client", "makeo.gadomancy.common"}) +@IFMLLoadingPlugin.TransformerExclusions({"makeo.gadomancy.coremod"}) public class GadomancyCore implements IFMLLoadingPlugin, IFMLCallHook { - public GadomancyCore() { - System.out.println("ITSSSS AA LIIEEEEEE"); - } - @Override public Void call() throws Exception { return null;