2015-10-20 00:22:36 +02:00
|
|
|
/*
|
|
|
|
* This file ("ItemLaserWrench.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
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-10-20 00:22:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package ellpeck.actuallyadditions.items;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-12-03 20:15:07 +01:00
|
|
|
import ellpeck.actuallyadditions.items.base.ItemBase;
|
2015-10-20 00:22:36 +02:00
|
|
|
import ellpeck.actuallyadditions.misc.LaserRelayConnectionHandler;
|
|
|
|
import ellpeck.actuallyadditions.tile.TileEntityLaserRelay;
|
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
2015-12-23 01:43:49 +01:00
|
|
|
import ellpeck.actuallyadditions.util.Position;
|
2015-10-21 18:31:35 +02:00
|
|
|
import ellpeck.actuallyadditions.util.StringUtil;
|
2015-10-20 00:22:36 +02:00
|
|
|
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.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.ChatComponentText;
|
2015-10-21 18:31:35 +02:00
|
|
|
import net.minecraft.util.EnumChatFormatting;
|
2015-10-20 00:22:36 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2015-10-21 18:31:35 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public class ItemLaserWrench extends ItemBase{
|
2015-10-20 00:22:36 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public ItemLaserWrench(String name){
|
|
|
|
super(name);
|
2015-10-20 00:22:36 +02:00
|
|
|
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){
|
2015-10-21 19:14:57 +02:00
|
|
|
if(!world.isRemote){
|
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
|
|
|
if(tile instanceof TileEntityLaserRelay){
|
2015-10-20 00:22:36 +02:00
|
|
|
if(ItemPhantomConnector.getStoredPosition(stack) == null){
|
|
|
|
ItemPhantomConnector.storeConnection(stack, x, y, z, world);
|
2015-10-21 19:14:57 +02:00
|
|
|
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".laser.stored.desc")));
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
else{
|
2015-12-23 01:43:49 +01:00
|
|
|
Position savedPos = ItemPhantomConnector.getStoredPosition(stack);
|
|
|
|
Position otherPos = new Position(x, y, z);
|
|
|
|
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedPos.getTileEntity(world) instanceof TileEntityLaserRelay && LaserRelayConnectionHandler.getInstance().addConnection(savedPos, otherPos)){
|
2015-10-21 18:31:35 +02:00
|
|
|
ItemPhantomConnector.clearStorage(stack);
|
2015-10-21 00:22:50 +02:00
|
|
|
|
2015-12-23 01:43:49 +01:00
|
|
|
((TileEntityLaserRelay)savedPos.getTileEntity(world)).sendUpdate();
|
|
|
|
((TileEntityLaserRelay)otherPos.getTileEntity(world)).sendUpdate();
|
2015-10-21 19:14:57 +02:00
|
|
|
|
|
|
|
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".laser.connected.desc")));
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
else{
|
2015-10-21 19:14:57 +02:00
|
|
|
player.addChatComponentMessage(new ChatComponentText(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".laser.cantConnect.desc")));
|
2015-10-26 22:28:49 +01:00
|
|
|
ItemPhantomConnector.clearStorage(stack);
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-23 16:54:33 +02:00
|
|
|
@Override
|
|
|
|
public boolean getShareTag(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
|
|
|
|
if(ItemPhantomConnector.getStoredPosition(stack) == null){
|
|
|
|
ItemPhantomConnector.clearStorage(stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-21 18:31:35 +02:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld){
|
2015-12-23 01:43:49 +01:00
|
|
|
Position coords = ItemPhantomConnector.getStoredPosition(stack);
|
2015-10-21 18:31:35 +02:00
|
|
|
if(coords != null){
|
2015-10-27 20:58:42 +01:00
|
|
|
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".boundTo.desc")+":");
|
|
|
|
list.add("X: "+coords.getX());
|
|
|
|
list.add("Y: "+coords.getY());
|
|
|
|
list.add("Z: "+coords.getZ());
|
|
|
|
list.add(EnumChatFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".clearStorage.desc"));
|
2015-10-21 18:31:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 00:22:36 +02:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return EnumRarity.epic;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconReg){
|
2015-12-03 20:15:07 +01:00
|
|
|
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName());
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-28 14:46:04 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-10-20 00:22:36 +02:00
|
|
|
public IIcon getIcon(ItemStack stack, int pass){
|
|
|
|
return this.itemIcon;
|
|
|
|
}
|
|
|
|
}
|