2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("ItemTeleStaff.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-01-03 16:05:51 +01:00
|
|
|
* http://ellpeck.de/actaddlicense/
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-01-03 16:05:51 +01:00
|
|
|
* © 2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.items;
|
2015-07-07 20:20:24 +02:00
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
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 20:20:24 +02:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
2015-07-08 18:57:40 +02:00
|
|
|
import net.minecraft.util.Vec3;
|
2015-07-07 20:20:24 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2015-10-01 23:20:31 +02:00
|
|
|
public class ItemTeleStaff extends ItemEnergy{
|
2015-07-07 20:20:24 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public ItemTeleStaff(String name){
|
|
|
|
super(500000, 10000, name);
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 21:13:52 +02:00
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
|
|
|
|
if(!world.isRemote){
|
|
|
|
if(this.getWaitTime(stack) <= 0){
|
2015-11-28 19:02:01 +01:00
|
|
|
MovingObjectPosition pos = WorldUtil.getNearestPositionWithAir(world, player, 100);
|
2015-10-03 10:19:40 +02:00
|
|
|
if(pos != null && (pos.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK || player.rotationPitch >= -5)){
|
2016-01-07 23:42:42 +01:00
|
|
|
int side = pos.sideHit.ordinal();
|
2015-10-03 10:19:40 +02:00
|
|
|
if(side != -1){
|
2016-01-07 23:42:42 +01:00
|
|
|
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 Vec3(player.posX, player.posY+(player.getEyeHeight()-player.getDefaultEyeHeight()), player.posZ)));
|
|
|
|
if(this.getEnergyStored(stack) >= use){
|
|
|
|
((EntityPlayerMP)player).playerNetServerHandler.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch);
|
|
|
|
player.mountEntity(null);
|
|
|
|
world.playSoundAtEntity(player, "mob.endermen.portal", 1.0F, 1.0F);
|
|
|
|
if(!player.capabilities.isCreativeMode){
|
|
|
|
this.extractEnergy(stack, use, false);
|
|
|
|
this.setWaitTime(stack, 50);
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
player.swingItem();
|
|
|
|
return stack;
|
2015-07-07 21:13:52 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 20:20:24 +02:00
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
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);
|
|
|
|
}
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
|
2015-07-07 21:59:57 +02:00
|
|
|
@Override
|
2015-10-03 10:19:40 +02:00
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 23:42:42 +01:00
|
|
|
return EnumRarity.EPIC;
|
2015-07-07 23:41:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int getWaitTime(ItemStack stack){
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
2015-10-02 16:48:01 +02:00
|
|
|
if(compound == null){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return compound.getInteger("waitTime");
|
|
|
|
}
|
2015-07-07 23:41:29 +02:00
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
private void setWaitTime(ItemStack stack, int time){
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
|
|
|
if(compound == null){
|
|
|
|
compound = new NBTTagCompound();
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
2015-10-03 10:19:40 +02:00
|
|
|
|
|
|
|
compound.setInteger("waitTime", time);
|
|
|
|
|
|
|
|
stack.setTagCompound(compound);
|
2015-07-07 20:20:24 +02:00
|
|
|
}
|
|
|
|
}
|