2015-10-20 00:22:36 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("ItemLaserWrench.java") is part of the Actually Additions mod for Minecraft.
|
2015-10-20 00:22:36 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-10-20 00:22:36 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-10-20 00:22:36 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.items;
|
2015-10-20 00:22:36 +02:00
|
|
|
|
2016-07-30 17:07:32 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
2017-06-17 00:48:49 +02:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2015-10-20 00:22:36 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.EnumActionResult;
|
2016-01-07 21:41:28 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-05-27 18:54:17 +02:00
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.text.TextFormatting;
|
2015-10-20 00:22:36 +02:00
|
|
|
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
|
2016-11-19 21:11:17 +01:00
|
|
|
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing par7, float par8, float par9, float par10){
|
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2016-06-15 17:42:55 +02:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if(tile instanceof TileEntityLaserRelay){
|
2017-02-13 19:07:53 +01:00
|
|
|
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
|
2016-06-15 17:42:55 +02:00
|
|
|
if(!world.isRemote){
|
2015-10-20 00:22:36 +02:00
|
|
|
if(ItemPhantomConnector.getStoredPosition(stack) == null){
|
2016-01-07 21:41:28 +01:00
|
|
|
ItemPhantomConnector.storeConnection(stack, pos.getX(), pos.getY(), pos.getZ(), world);
|
2018-05-10 11:38:58 +02:00
|
|
|
player.sendStatusMessage(new TextComponentTranslation("tooltip."+ActuallyAdditions.MODID+".laser.stored.desc"), true);
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
else{
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos savedPos = ItemPhantomConnector.getStoredPosition(stack);
|
2016-05-16 22:52:27 +02:00
|
|
|
if(savedPos != null){
|
|
|
|
TileEntity savedTile = world.getTileEntity(savedPos);
|
2017-02-13 19:07:53 +01:00
|
|
|
if(savedTile instanceof TileEntityLaserRelay){
|
|
|
|
int distanceSq = (int)savedPos.distanceSq(pos);
|
|
|
|
TileEntityLaserRelay savedRelay = (TileEntityLaserRelay)savedTile;
|
2015-10-21 00:22:50 +02:00
|
|
|
|
2017-02-13 19:07:53 +01:00
|
|
|
int lowestRange = Math.min(relay.getMaxRange(), savedRelay.getMaxRange());
|
|
|
|
int range = lowestRange*lowestRange;
|
2017-03-29 12:12:31 +02:00
|
|
|
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedRelay.type == relay.type && distanceSq <= range && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, relay.type, world, false, true)){
|
2017-02-13 19:07:53 +01:00
|
|
|
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
|
2015-10-21 19:14:57 +02:00
|
|
|
|
2017-02-13 19:07:53 +01:00
|
|
|
((TileEntityLaserRelay)savedTile).sendUpdate();
|
|
|
|
relay.sendUpdate();
|
|
|
|
|
2018-05-10 11:38:58 +02:00
|
|
|
player.sendStatusMessage(new TextComponentTranslation("tooltip."+ActuallyAdditions.MODID+".laser.connected.desc"), true);
|
2017-02-13 19:07:53 +01:00
|
|
|
|
|
|
|
return EnumActionResult.SUCCESS;
|
|
|
|
}
|
2016-05-16 22:52:27 +02:00
|
|
|
}
|
2017-02-13 19:07:53 +01:00
|
|
|
|
2018-05-10 11:38:58 +02:00
|
|
|
player.sendMessage(new TextComponentTranslation("tooltip."+ActuallyAdditions.MODID+".laser.cantConnect.desc"));
|
2017-02-13 19:07:53 +01:00
|
|
|
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-15 17:42:55 +02:00
|
|
|
return EnumActionResult.SUCCESS;
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
2016-03-18 23:47:22 +01:00
|
|
|
return EnumActionResult.FAIL;
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
|
2015-10-23 16:54:33 +02:00
|
|
|
@Override
|
|
|
|
public boolean getShareTag(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-21 18:31:35 +02:00
|
|
|
@Override
|
2017-06-17 00:48:49 +02:00
|
|
|
public void addInformation(ItemStack stack, World playerIn, List<String> list, ITooltipFlag advanced){
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos coords = ItemPhantomConnector.getStoredPosition(stack);
|
2015-10-21 18:31:35 +02:00
|
|
|
if(coords != null){
|
2018-05-10 11:38:58 +02:00
|
|
|
list.add(StringUtil.localize("tooltip."+ActuallyAdditions.MODID+".boundTo.desc")+":");
|
2015-10-27 20:58:42 +01:00
|
|
|
list.add("X: "+coords.getX());
|
|
|
|
list.add("Y: "+coords.getY());
|
|
|
|
list.add("Z: "+coords.getZ());
|
2018-05-10 11:38:58 +02:00
|
|
|
list.add(TextFormatting.ITALIC+StringUtil.localize("tooltip."+ActuallyAdditions.MODID+".clearStorage.desc"));
|
2015-10-21 18:31:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-20 00:22:36 +02:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 21:41:28 +01:00
|
|
|
return EnumRarity.EPIC;
|
2015-10-20 00:22:36 +02:00
|
|
|
}
|
|
|
|
}
|