mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Spruced up the TeleStaff
This commit is contained in:
parent
e081017ea5
commit
e9d706f127
2 changed files with 46 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue