2015-05-20 22:39:43 +02:00
|
|
|
package ellpeck.actuallyadditions.items;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-05-25 17:00:54 +02:00
|
|
|
import ellpeck.actuallyadditions.tile.TileEntityPhantomPlacer;
|
2015-05-20 22:39:43 +02:00
|
|
|
import ellpeck.actuallyadditions.tile.TileEntityPhantomface;
|
|
|
|
import ellpeck.actuallyadditions.util.INameableItem;
|
|
|
|
import ellpeck.actuallyadditions.util.KeyUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.ChatComponentText;
|
2015-05-25 17:00:54 +02:00
|
|
|
import net.minecraft.util.ChunkCoordinates;
|
2015-05-20 22:39:43 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.DimensionManager;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class ItemPhantomConnector extends Item implements INameableItem{
|
|
|
|
|
|
|
|
public ItemPhantomConnector(){
|
|
|
|
this.setMaxStackSize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int par7, float par8, float par9, float par10){
|
|
|
|
if(!world.isRemote){
|
2015-05-25 17:00:54 +02:00
|
|
|
//Passing Data to Phantoms
|
2015-05-20 22:39:43 +02:00
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
2015-05-25 17:00:54 +02:00
|
|
|
if(tile != null){
|
|
|
|
//Passing to Face
|
|
|
|
if(tile instanceof TileEntityPhantomface){
|
2015-06-12 19:12:06 +02:00
|
|
|
if(this.checkHasConnection(stack, player, tile)){
|
|
|
|
((TileEntityPhantomface)tile).boundPosition = this.getStoredPosition(stack);
|
|
|
|
((TileEntityPhantomface)tile).boundWorld = this.getStoredWorld(stack);
|
|
|
|
TileEntityPhantomface.updateAround(tile);
|
|
|
|
this.clearStorage(stack);
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connected.desc")));
|
|
|
|
return true;
|
2015-05-25 17:00:54 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//Passing to Placer
|
|
|
|
else if(tile instanceof TileEntityPhantomPlacer){
|
2015-06-12 19:12:06 +02:00
|
|
|
if(this.checkHasConnection(stack, player, tile)){
|
2015-05-25 17:00:54 +02:00
|
|
|
((TileEntityPhantomPlacer)tile).boundPosition = this.getStoredPosition(stack);
|
|
|
|
((TileEntityPhantomPlacer)tile).boundWorld = this.getStoredWorld(stack);
|
2015-06-12 19:12:06 +02:00
|
|
|
tile.markDirty();
|
2015-05-25 17:00:54 +02:00
|
|
|
this.clearStorage(stack);
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("tooltip."+ModUtil.MOD_ID_LOWER+".phantom.connected.desc")));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-25 17:00:54 +02:00
|
|
|
//Storing Connections
|
|
|
|
this.storeConnection(stack, x, y, z, world);
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("tooltip." + ModUtil.MOD_ID_LOWER + ".phantom.stored.desc")));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-05-20 22:39:43 +02:00
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
public boolean checkHasConnection(ItemStack stack, EntityPlayer player, TileEntity tile){
|
2015-05-25 17:00:54 +02:00
|
|
|
if(this.getStoredPosition(stack) != null && this.getStoredWorld(stack) != null){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else{
|
2015-06-12 19:12:06 +02:00
|
|
|
if(tile instanceof TileEntityPhantomPlacer){
|
|
|
|
((TileEntityPhantomPlacer)tile).boundWorld = null;
|
|
|
|
((TileEntityPhantomPlacer)tile).boundPosition = null;
|
|
|
|
}
|
|
|
|
if(tile instanceof TileEntityPhantomface){
|
|
|
|
((TileEntityPhantomface)tile).boundWorld = null;
|
|
|
|
((TileEntityPhantomface)tile).boundPosition = null;
|
|
|
|
}
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("tooltip." + ModUtil.MOD_ID_LOWER + ".phantom.unbound.desc")));
|
2015-05-25 17:00:54 +02:00
|
|
|
return false;
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
|
2015-05-25 17:00:54 +02:00
|
|
|
if(this.getStoredPosition(stack) == null || this.getStoredWorld(stack) == null) this.clearStorage(stack);
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
|
2015-05-22 17:48:50 +02:00
|
|
|
if(KeyUtil.isAltPressed()) this.clearStorage(stack);
|
2015-05-20 22:39:43 +02:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
2015-05-25 17:00:54 +02:00
|
|
|
public ChunkCoordinates getStoredPosition(ItemStack stack){
|
2015-05-20 22:39:43 +02:00
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
if(tag != null){
|
|
|
|
int x = tag.getInteger("XCoordOfTileStored");
|
|
|
|
int y = tag.getInteger("YCoordOfTileStored");
|
|
|
|
int z = tag.getInteger("ZCoordOfTileStored");
|
|
|
|
|
2015-05-25 17:00:54 +02:00
|
|
|
if(x == 0 && y == 0 && z == 0) return null;
|
|
|
|
return new ChunkCoordinates(x, y, z);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public World getStoredWorld(ItemStack stack){
|
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
if(tag != null){
|
|
|
|
return DimensionManager.getWorld(tag.getInteger("WorldOfTileStored"));
|
2015-05-20 22:39:43 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-05-25 17:00:54 +02:00
|
|
|
public void storeConnection(ItemStack stack, int x, int y, int z, World world){
|
2015-05-20 22:39:43 +02:00
|
|
|
NBTTagCompound tag = stack.getTagCompound();
|
|
|
|
if(tag == null) tag = new NBTTagCompound();
|
|
|
|
|
2015-05-25 17:00:54 +02:00
|
|
|
tag.setInteger("XCoordOfTileStored", x);
|
|
|
|
tag.setInteger("YCoordOfTileStored", y);
|
|
|
|
tag.setInteger("ZCoordOfTileStored", z);
|
|
|
|
tag.setInteger("WorldOfTileStored", world.provider.dimensionId);
|
2015-05-20 22:39:43 +02:00
|
|
|
|
|
|
|
stack.setTagCompound(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearStorage(ItemStack stack){
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.epic;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) {
|
2015-05-25 17:00:54 +02:00
|
|
|
ChunkCoordinates coords = this.getStoredPosition(stack);
|
|
|
|
World world = this.getStoredWorld(stack);
|
|
|
|
if(coords != null && world != null){
|
2015-05-20 22:39:43 +02:00
|
|
|
list.add(StatCollector.translateToLocal("tooltip." + ModUtil.MOD_ID_LOWER + ".phantom.boundTo.desc") + ":");
|
2015-05-25 17:00:54 +02:00
|
|
|
list.add("X: " + coords.posX);
|
|
|
|
list.add("Y: " + coords.posY);
|
|
|
|
list.add("Z: " + coords.posZ);
|
|
|
|
list.add(StatCollector.translateToLocal("tooltip." + ModUtil.MOD_ID_LOWER + ".phantom.inWorld.desc") + " " + world.provider.dimensionId);
|
2015-05-20 22:39:43 +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());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return "itemPhantomConnector";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOredictName(){
|
|
|
|
return this.getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getShareTag(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|