From e9d706f127aecfa8e836a7a4825e1d2fc63aa516 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 7 Jul 2015 23:41:29 +0200 Subject: [PATCH] Spruced up the TeleStaff --- .../config/values/ConfigIntValues.java | 5 +- .../items/ItemTeleStaff.java | 58 ++++++++++++++----- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/main/java/ellpeck/actuallyadditions/config/values/ConfigIntValues.java b/src/main/java/ellpeck/actuallyadditions/config/values/ConfigIntValues.java index fb1e0f949..6c54b2694 100644 --- a/src/main/java/ellpeck/actuallyadditions/config/values/ConfigIntValues.java +++ b/src/main/java/ellpeck/actuallyadditions/config/values/ConfigIntValues.java @@ -100,8 +100,9 @@ public enum ConfigIntValues{ DRILL_THREE_BY_THREE_EXTRA_USE("3x3 Upgrade: Extra Energy Use", ConfigCategories.DRILL_VALUES, 10, 0, 10000, "How much extra Energy the 3x3 Upgrade uses"), DRILL_FIVE_BY_FIVE_EXTRA_USE("5x5 Upgrade: Extra Energy Use", ConfigCategories.DRILL_VALUES, 30, 0, 10000, "How much extra Energy the 5x5 Upgrade uses"), - TELE_STAFF_REACH("TeleStaff: Range", ConfigCategories.MACHINE_VALUES, 100, 5, 150, "How far the TeleStaff can teleport you"), - TELE_STAFF_ENERGY_USE("TeleStaff: Energy Use per Block", ConfigCategories.MACHINE_VALUES, 200, 1, 5000, "How much energy the TeleStaff uses per Block you teleport"); + TELE_STAFF_REACH("TeleStaff: Range", ConfigCategories.MACHINE_VALUES, 100, 5, 200, "How far the TeleStaff can teleport you"), + TELE_STAFF_ENERGY_USE("TeleStaff: Energy Use per Block", ConfigCategories.MACHINE_VALUES, 200, 1, 5000, "How much energy the TeleStaff uses per Block you teleport"), + TELE_STAFF_WAIT_TIME("TeleStaff: Wait Time", ConfigCategories.MACHINE_VALUES, 30, 0, 500, "The time the TeleStaff takes between Teleports"); public final String name; public final String category; diff --git a/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java b/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java index a0945f6c1..da938cd5c 100644 --- a/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java +++ b/src/main/java/ellpeck/actuallyadditions/items/ItemTeleStaff.java @@ -7,10 +7,12 @@ import ellpeck.actuallyadditions.util.INameableItem; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.WorldUtil; import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.EnumRarity; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; @@ -20,6 +22,7 @@ public class ItemTeleStaff extends ItemEnergy implements INameableItem{ private static final int reach = ConfigIntValues.TELE_STAFF_REACH.getValue(); private static final int energyUsedPerBlock = ConfigIntValues.TELE_STAFF_ENERGY_USE.getValue(); + private static final int waitTime = ConfigIntValues.TELE_STAFF_WAIT_TIME.getValue(); public ItemTeleStaff(){ super(500000, 10000, 1); @@ -46,28 +49,53 @@ public class ItemTeleStaff extends ItemEnergy implements INameableItem{ this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName()); } + @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); + } + } + + private void setWaitTime(ItemStack stack, int time){ + NBTTagCompound compound = stack.getTagCompound(); + if(compound == null) compound = new NBTTagCompound(); + + compound.setInteger("waitTime", time); + } + + private int getWaitTime(ItemStack stack){ + NBTTagCompound compound = stack.getTagCompound(); + if(compound == null) return 0; + else return compound.getInteger("waitTime"); + } + @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){ - MovingObjectPosition pos = WorldUtil.getMovingObjectPosWithReachDistance(world, player, (double)reach); - if(pos != null){ - int side = pos.sideHit; - if(side != -1){ - ForgeDirection forgeSide = ForgeDirection.getOrientation(side); - if(forgeSide != ForgeDirection.UNKNOWN){ - 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 use = energyUsedPerBlock+(int)(energyUsedPerBlock*pos.hitVec.distanceTo(player.getPosition(1.0F))); - if(this.getEnergyStored(stack) >= use){ - player.swingItem(); - if(!world.isRemote){ - ((EntityPlayerMP)player).playerNetServerHandler.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch); - if(!player.capabilities.isCreativeMode) this.extractEnergy(stack, use, false); + if(!world.isRemote){ + if(this.getWaitTime(stack) <= 0){ + MovingObjectPosition pos = WorldUtil.getMovingObjectPosWithReachDistance(world, player, (double)reach); + if(pos != null){ + int side = pos.sideHit; + if(side != -1){ + ForgeDirection forgeSide = ForgeDirection.getOrientation(side); + if(forgeSide != ForgeDirection.UNKNOWN){ + 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 use = energyUsedPerBlock+(int)(energyUsedPerBlock*pos.hitVec.distanceTo(player.getPosition(1.0F))); + if(this.getEnergyStored(stack) >= use){ + ((EntityPlayerMP)player).playerNetServerHandler.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch); + world.playSoundAtEntity(player, "mob.endermen.portal", 1.0F, 1.0F); + if(!player.capabilities.isCreativeMode) this.extractEnergy(stack, use, false); + } } } } + this.setWaitTime(stack, waitTime); } } + player.swingItem(); return stack; } }