2015-11-28 18:25:46 -08:00
|
|
|
package WayofTime.bloodmagic.item;
|
|
|
|
|
2016-03-17 13:00:44 -07:00
|
|
|
import WayofTime.bloodmagic.BloodMagic;
|
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
|
|
|
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
|
2016-03-16 01:10:33 -07:00
|
|
|
import WayofTime.bloodmagic.client.IVariantProvider;
|
2016-03-17 13:00:44 -07:00
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
2015-11-28 18:25:46 -08:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-03-17 13:00:44 -07:00
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2015-11-28 18:25:46 -08:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2016-03-16 01:10:33 -07:00
|
|
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
2015-11-28 18:25:46 -08:00
|
|
|
|
2016-03-17 13:00:44 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-03-22 21:10:05 -04:00
|
|
|
public class ItemTelepositionFocus extends ItemBindableBase implements IVariantProvider
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
|
|
|
public static String[] names = { "weak", "enhanced", "reinforced", "demonic" };
|
2015-11-28 18:25:46 -08:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public ItemTelepositionFocus()
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
super();
|
|
|
|
|
|
|
|
setUnlocalizedName(Constants.Mod.MODID + ".focus.");
|
2016-01-18 22:34:12 -08:00
|
|
|
setRegistryName(Constants.BloodMagicItem.TELEPOSITION_FOCUS.getRegName());
|
2015-11-28 18:25:46 -08:00
|
|
|
setCreativeTab(BloodMagic.tabBloodMagic);
|
|
|
|
setMaxStackSize(1);
|
|
|
|
setHasSubtypes(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public String getUnlocalizedName(ItemStack stack)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
return super.getUnlocalizedName(stack) + names[stack.getItemDamage()];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2015-12-30 15:34:40 -05:00
|
|
|
public void getSubItems(Item id, CreativeTabs creativeTab, List<ItemStack> list)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
for (int i = 0; i < names.length; i++)
|
|
|
|
list.add(new ItemStack(id, 1, i));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-03-17 13:00:44 -07:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
|
2015-12-30 15:34:40 -05:00
|
|
|
{
|
2016-02-03 23:14:26 -08:00
|
|
|
if (player.isSneaking())
|
2015-12-30 23:00:49 -05:00
|
|
|
{
|
2016-03-17 13:00:44 -07:00
|
|
|
RayTraceResult mop = getMovingObjectPositionFromPlayer(world, player, false);
|
2015-12-30 23:00:49 -05:00
|
|
|
|
2016-03-17 13:00:44 -07:00
|
|
|
if (mop != null && mop.typeOfHit == RayTraceResult.Type.BLOCK)
|
2016-02-03 23:14:26 -08:00
|
|
|
{
|
|
|
|
setBlockPos(stack, world, mop.getBlockPos());
|
2015-12-30 23:00:49 -05:00
|
|
|
}
|
|
|
|
}
|
2015-11-28 18:25:46 -08:00
|
|
|
|
2016-03-17 13:00:44 -07:00
|
|
|
return ActionResult.newResult(EnumActionResult.FAIL, stack);
|
2015-11-28 18:25:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
2015-12-30 15:34:40 -05:00
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
|
|
|
|
{
|
2016-01-08 16:14:45 -08:00
|
|
|
tooltip.addAll(Arrays.asList(TextHelper.cutLongString(TextHelper.localize("tooltip.BloodMagic.telepositionFocus." + names[stack.getItemDamage()]))));
|
2015-11-28 18:25:46 -08:00
|
|
|
|
|
|
|
super.addInformation(stack, player, tooltip, advanced);
|
|
|
|
|
2015-12-30 23:00:49 -05:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
2015-11-28 18:25:46 -08:00
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
BlockPos coords = getBlockPos(stack);
|
|
|
|
|
2015-12-30 23:00:49 -05:00
|
|
|
if (coords != null && tag != null)
|
|
|
|
{
|
2016-01-07 15:52:02 -08:00
|
|
|
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.telepositionFocus.coords", coords.getX(), coords.getY(), coords.getZ()));
|
|
|
|
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.telepositionFocus.dimension", tag.getInteger(Constants.NBT.DIMENSION_ID)));
|
2015-12-30 23:00:49 -05:00
|
|
|
}
|
2015-11-28 18:25:46 -08:00
|
|
|
}
|
|
|
|
|
2016-03-16 01:10:33 -07:00
|
|
|
@Override
|
2016-03-16 18:41:06 -04:00
|
|
|
public List<Pair<Integer, String>> getVariants()
|
|
|
|
{
|
2016-03-16 01:10:33 -07:00
|
|
|
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
|
|
|
|
ret.add(new ImmutablePair<Integer, String>(0, "type=weak"));
|
|
|
|
ret.add(new ImmutablePair<Integer, String>(1, "type=enhanced"));
|
|
|
|
ret.add(new ImmutablePair<Integer, String>(2, "type=reinforced"));
|
|
|
|
ret.add(new ImmutablePair<Integer, String>(3, "type=demonic"));
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public World getWorld(ItemStack stack)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
return DimensionManager.getWorld(stack.getTagCompound().getInteger(Constants.NBT.DIMENSION_ID));
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public BlockPos getBlockPos(ItemStack stack)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
|
|
|
return new BlockPos(stack.getTagCompound().getInteger(Constants.NBT.X_COORD), stack.getTagCompound().getInteger(Constants.NBT.Y_COORD), stack.getTagCompound().getInteger(Constants.NBT.Z_COORD));
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public ItemStack setBlockPos(ItemStack stack, World world, BlockPos pos)
|
|
|
|
{
|
2016-02-12 12:49:32 -08:00
|
|
|
stack = NBTHelper.checkNBT(stack);
|
2015-11-28 18:25:46 -08:00
|
|
|
NBTTagCompound itemTag = stack.getTagCompound();
|
|
|
|
itemTag.setInteger(Constants.NBT.X_COORD, pos.getX());
|
|
|
|
itemTag.setInteger(Constants.NBT.Y_COORD, pos.getY());
|
|
|
|
itemTag.setInteger(Constants.NBT.Z_COORD, pos.getZ());
|
2016-03-17 13:00:44 -07:00
|
|
|
itemTag.setInteger(Constants.NBT.DIMENSION_ID, world.provider.getDimension());
|
2015-11-28 18:25:46 -08:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
}
|