2015-07-07 20:20:24 +02:00
|
|
|
package ellpeck.actuallyadditions.items;
|
|
|
|
|
2015-07-07 21:59:57 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-07-07 21:13:52 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-07-07 20:20:24 +02:00
|
|
|
import ellpeck.actuallyadditions.util.INameableItem;
|
2015-07-07 21:59:57 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
2015-07-07 20:20:24 +02:00
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
2015-07-07 21:59:57 +02:00
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
2015-07-07 23:41:29 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
2015-07-07 20:20:24 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2015-07-07 21:13:52 +02:00
|
|
|
import net.minecraft.item.EnumRarity;
|
2015-07-07 20:20:24 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-07-07 23:41:29 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-07-07 21:59:57 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
2015-07-07 20:20:24 +02:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
public class ItemTeleStaff extends ItemEnergy implements INameableItem{
|
|
|
|
|
2015-07-07 23:06:53 +02:00
|
|
|
private static final int reach = ConfigIntValues.TELE_STAFF_REACH.getValue();
|
2015-07-07 21:13:52 +02:00
|
|
|
private static final int energyUsedPerBlock = ConfigIntValues.TELE_STAFF_ENERGY_USE.getValue();
|
2015-07-07 23:41:29 +02:00
|
|
|
private static final int waitTime = ConfigIntValues.TELE_STAFF_WAIT_TIME.getValue();
|
2015-07-07 20:20:24 +02:00
|
|
|
|
|
|
|
public ItemTeleStaff(){
|
2015-07-07 21:59:57 +02:00
|
|
|
super(500000, 10000, 1);
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 21:13:52 +02:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.epic;
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:20:24 +02:00
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return "itemTeleStaff";
|
|
|
|
}
|
|
|
|
|
2015-07-07 21:59:57 +02:00
|
|
|
@Override
|
|
|
|
public IIcon getIcon(ItemStack stack, int pass){
|
|
|
|
return this.itemIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconReg){
|
|
|
|
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName());
|
|
|
|
}
|
|
|
|
|
2015-07-07 23:41:29 +02:00
|
|
|
@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");
|
|
|
|
}
|
|
|
|
|
2015-07-07 20:20:24 +02:00
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
|
2015-07-07 23:41:29 +02:00
|
|
|
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);
|
|
|
|
}
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-07 23:41:29 +02:00
|
|
|
this.setWaitTime(stack, waitTime);
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-07 23:41:29 +02:00
|
|
|
player.swingItem();
|
2015-07-07 20:20:24 +02:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
}
|