Make the Teleportation Stuff use Vanilla Cooldown rather than Own one (#350)

This commit is contained in:
garantiertnicht Weichware 2016-11-13 12:38:17 +01:00 committed by Ellpeck
parent 83e85b4ac3
commit a89bfa5001

View file

@ -12,13 +12,11 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy; import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
@ -33,11 +31,9 @@ public class ItemTeleStaff extends ItemEnergy{
super(500000, 10000, name); super(500000, 10000, name);
} }
@Override @Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){ public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(!world.isRemote){ if(!world.isRemote){
if(this.getWaitTime(stack) <= 0){
RayTraceResult pos = WorldUtil.getNearestPositionWithAir(world, player, 100); RayTraceResult pos = WorldUtil.getNearestPositionWithAir(world, player, 100);
if(pos != null && (pos.typeOfHit == RayTraceResult.Type.BLOCK || player.rotationPitch >= -5)){ if(pos != null && (pos.typeOfHit == RayTraceResult.Type.BLOCK || player.rotationPitch >= -5)){
int side = pos.sideHit.ordinal(); int side = pos.sideHit.ordinal();
@ -53,50 +49,19 @@ public class ItemTeleStaff extends ItemEnergy{
world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F); world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
if(!player.capabilities.isCreativeMode){ if(!player.capabilities.isCreativeMode){
this.extractEnergy(stack, use, false); this.extractEnergy(stack, use, false);
this.setWaitTime(stack, 50); player.getCooldownTracker().setCooldown(this, 50);
} }
return ActionResult.newResult(EnumActionResult.SUCCESS, stack); return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
} }
} }
} }
} }
}
player.swingArm(hand); player.swingArm(hand);
return ActionResult.newResult(EnumActionResult.FAIL, stack); 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 @Override
public EnumRarity getRarity(ItemStack stack){ public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC; 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);
}
} }