mirror of
https://github.com/GTNewHorizons/IguanaTweaksTConstruct.git
synced 2026-11-26 06:43:05 +00:00
Add fake player leveling prevention (untested)
This commit is contained in:
1 parent
89c235ce4a
commit
0d791f29dd
2 files changed
+18
-9
No files matched your search
@@ -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)
|
||||
|
||||
+14
-8
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user