From a89bfa50016ebcb740a2964c49a831bc1d179101 Mon Sep 17 00:00:00 2001 From: garantiertnicht Weichware Date: Sun, 13 Nov 2016 12:38:17 +0100 Subject: [PATCH] Make the Teleportation Stuff use Vanilla Cooldown rather than Own one (#350) --- .../mod/items/ItemTeleStaff.java | 69 +++++-------------- 1 file changed, 17 insertions(+), 52 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemTeleStaff.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemTeleStaff.java index 58e806e7c..c83e9877e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemTeleStaff.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemTeleStaff.java @@ -12,13 +12,11 @@ package de.ellpeck.actuallyadditions.mod.items; import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; -import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.SoundEvents; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumHand; @@ -33,30 +31,27 @@ public class ItemTeleStaff extends ItemEnergy{ super(500000, 10000, name); } - @Override public ActionResult onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){ if(!world.isRemote){ - if(this.getWaitTime(stack) <= 0){ - RayTraceResult pos = WorldUtil.getNearestPositionWithAir(world, player, 100); - if(pos != null && (pos.typeOfHit == RayTraceResult.Type.BLOCK || player.rotationPitch >= -5)){ - int side = pos.sideHit.ordinal(); - if(side != -1){ - double x = pos.hitVec.xCoord-(side == 4 ? 0.5 : 0)+(side == 5 ? 0.5 : 0); - double y = pos.hitVec.yCoord-(side == 0 ? 2.0 : 0)+(side == 1 ? 0.5 : 0); - double z = pos.hitVec.zCoord-(side == 2 ? 0.5 : 0)+(side == 3 ? 0.5 : 0); - int baseUse = 200; - int use = baseUse+(int)(baseUse*pos.hitVec.distanceTo(new Vec3d(player.posX, player.posY+(player.getEyeHeight()-player.getDefaultEyeHeight()), player.posZ))); - if(this.getEnergyStored(stack) >= use){ - ((EntityPlayerMP)player).connection.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch); - player.dismountRidingEntity(); - world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F); - if(!player.capabilities.isCreativeMode){ - this.extractEnergy(stack, use, false); - this.setWaitTime(stack, 50); - } - return ActionResult.newResult(EnumActionResult.SUCCESS, stack); + RayTraceResult pos = WorldUtil.getNearestPositionWithAir(world, player, 100); + if(pos != null && (pos.typeOfHit == RayTraceResult.Type.BLOCK || player.rotationPitch >= -5)){ + int side = pos.sideHit.ordinal(); + if(side != -1){ + double x = pos.hitVec.xCoord-(side == 4 ? 0.5 : 0)+(side == 5 ? 0.5 : 0); + double y = pos.hitVec.yCoord-(side == 0 ? 2.0 : 0)+(side == 1 ? 0.5 : 0); + double z = pos.hitVec.zCoord-(side == 2 ? 0.5 : 0)+(side == 3 ? 0.5 : 0); + int baseUse = 200; + int use = baseUse+(int)(baseUse*pos.hitVec.distanceTo(new Vec3d(player.posX, player.posY+(player.getEyeHeight()-player.getDefaultEyeHeight()), player.posZ))); + if(this.getEnergyStored(stack) >= use){ + ((EntityPlayerMP)player).connection.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch); + player.dismountRidingEntity(); + world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F); + if(!player.capabilities.isCreativeMode){ + this.extractEnergy(stack, use, false); + player.getCooldownTracker().setCooldown(this, 50); } + return ActionResult.newResult(EnumActionResult.SUCCESS, stack); } } } @@ -65,38 +60,8 @@ public class ItemTeleStaff extends ItemEnergy{ return ActionResult.newResult(EnumActionResult.FAIL, stack); } - @Override - public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){ - int time = this.getWaitTime(stack); - if(time > 0){ - this.setWaitTime(stack, time-1); - } - } - - @Override public EnumRarity getRarity(ItemStack stack){ return EnumRarity.EPIC; } - - private int getWaitTime(ItemStack stack){ - NBTTagCompound compound = stack.getTagCompound(); - if(compound == null){ - return 0; - } - else{ - return compound.getInteger("waitTime"); - } - } - - private void setWaitTime(ItemStack stack, int time){ - NBTTagCompound compound = stack.getTagCompound(); - if(compound == null){ - compound = new NBTTagCompound(); - } - - compound.setInteger("waitTime", time); - - stack.setTagCompound(compound); - } }