From 0d791f29dd308c15849e43030bbd3ead288ee1e8 Mon Sep 17 00:00:00 2001 From: Bernhard Bonigl Date: Mon, 28 Jul 2014 10:02:44 +0200 Subject: [PATCH] Add fake player leveling prevention (untested) --- .../leveling/LevelingActiveToolMod.java | 5 ++++- .../handlers/LevelingEventHandler.java | 22 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingActiveToolMod.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingActiveToolMod.java index 5d1e2f6..11be90c 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingActiveToolMod.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/LevelingActiveToolMod.java @@ -7,6 +7,7 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.FakePlayer; import tconstruct.library.ActiveToolMod; import tconstruct.library.tools.HarvestTool; import tconstruct.library.tools.ToolCore; @@ -25,6 +26,8 @@ public class LevelingActiveToolMod extends ActiveToolMod { @Override public boolean beforeBlockBreak(ToolCore tool, ItemStack stack, int x, int y, int z, EntityLivingBase entity) { if (!(entity instanceof EntityPlayer)) return false; + // nope, you don't use an autonomous activator! + if(entity instanceof FakePlayer) return false; // why are you breaking this block with that tool! It's not a harvest tool derp! if(!(tool instanceof HarvestTool)) return false; @@ -46,7 +49,7 @@ public class LevelingActiveToolMod extends ActiveToolMod { strong = strength >= 1.0f; effective = harvestTool.isEffective(block.getMaterial()); - Log.trace("Tool is [harvestable: '" + harvestable + "', effective: '" + effective + "', strong: '" + strong + "']"); + //Log.trace("Tool is [harvestable: '" + harvestable + "', effective: '" + effective + "', strong: '" + strong + "']"); // only give xp if the use makes sense if(harvestable && effective && strong) diff --git a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java index 6744927..60ab755 100644 --- a/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java +++ b/src/main/java/iguanaman/iguanatweakstconstruct/leveling/handlers/LevelingEventHandler.java @@ -12,6 +12,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.entity.living.LivingHurtEvent; import net.minecraftforge.event.entity.player.UseHoeEvent; import tconstruct.items.tools.Hammer; @@ -35,21 +36,26 @@ public class LevelingEventHandler { if (event.source.getEntity() instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer) event.source.getEntity(); - ItemStack stack = player.getCurrentEquippedItem(); - if (stack != null && stack.hasTagCompound()) - if (stack.getItem() instanceof Weapon || stack.getItem() instanceof Shortbow && event.source.damageType.equals("arrow")) - { - long xp = Math.round(event.ammount); - if (event.entityLiving instanceof EntityAnimal) xp = Math.round(event.ammount / 4f); + // fake player? + if(!(player instanceof FakePlayer)) + { + ItemStack stack = player.getCurrentEquippedItem(); + if (stack != null && stack.hasTagCompound()) + if (stack.getItem() instanceof Weapon || stack.getItem() instanceof Shortbow && event.source.damageType.equals("arrow")) { + long xp = Math.round(event.ammount); + if (event.entityLiving instanceof EntityAnimal) xp = Math.round(event.ammount / 4f); - if (xp > 0) LevelingLogic.addXP(stack, player, xp); - } + if (xp > 0) LevelingLogic.addXP(stack, player, xp); + } + } } } @SubscribeEvent public void onUseHoe(UseHoeEvent event) { EntityPlayer player = event.entityPlayer; + // no fake players + if(player instanceof FakePlayer) return; ItemStack stack = event.current; if (stack != null && stack.hasTagCompound() && stack.getItem() instanceof ToolCore) LevelingLogic.addXP(stack, player, 1L);