ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemLaserWrench.java

139 lines
5.9 KiB
Java
Raw Normal View History

/*
2016-05-16 22:52:27 +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
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
2016-08-09 20:56:09 +02:00
import de.ellpeck.actuallyadditions.mod.network.PacketHandlerHelper;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.tile.TileEntityLaserRelay;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
2016-03-18 23:47:22 +01:00
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
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;
import net.minecraft.world.World;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemLaserWrench extends ItemBase{
public ItemLaserWrench(String name){
super(name);
this.setMaxStackSize(1);
}
@Override
2016-03-18 23:47:22 +01:00
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing par7, float par8, float par9, float par10){
TileEntity tile = world.getTileEntity(pos);
if(tile instanceof TileEntityLaserRelay){
if(!world.isRemote){
if(ItemPhantomConnector.getStoredPosition(stack) == null){
ItemPhantomConnector.storeConnection(stack, pos.getX(), pos.getY(), pos.getZ(), world);
2016-05-27 18:54:17 +02:00
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.stored.desc"));
}
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);
int distanceSq = (int)savedPos.distanceSq(pos);
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
if(ItemPhantomConnector.getStoredWorld(stack) == world && savedTile instanceof TileEntityLaserRelay && ((TileEntityLaserRelay)savedTile).type == relay.type && distanceSq <= TileEntityLaserRelay.MAX_DISTANCE*TileEntityLaserRelay.MAX_DISTANCE && ActuallyAdditionsAPI.connectionHandler.addConnection(savedPos, pos, relay.type, world)){
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
2015-10-21 00:22:50 +02:00
((TileEntityLaserRelay)savedTile).sendUpdate();
relay.sendUpdate();
2016-05-27 18:54:17 +02:00
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.connected.desc"));
2016-05-16 22:52:27 +02:00
}
else{
2016-05-27 18:54:17 +02:00
player.addChatComponentMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".laser.cantConnect.desc"));
ItemPhantomConnector.clearStorage(stack, "XCoordOfTileStored", "YCoordOfTileStored", "ZCoordOfTileStored", "WorldOfTileStored");
2016-05-16 22:52:27 +02:00
}
}
}
}
return EnumActionResult.SUCCESS;
}
2016-03-18 23:47:22 +01:00
return EnumActionResult.FAIL;
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(!world.isRemote && player.isSneaking()){
PlayerData.PlayerSave save = PlayerData.getDataFromPlayer(player);
int currMode = save.theCompound.getInteger("LaserWrenchMode");
if(currMode+1 >= WrenchMode.values().length){
currMode = 0;
}
else{
currMode++;
}
save.theCompound.setInteger("LaserWrenchMode", currMode);
if(player instanceof EntityPlayerMP){
2016-08-09 20:56:09 +02:00
PacketHandlerHelper.sendPlayerDataToClientPacket(player, save.theCompound, false);
}
player.addChatComponentMessage(new TextComponentString("Mode changed to "+WrenchMode.values()[currMode].name+"!"));
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}
2015-10-23 16:54:33 +02:00
@Override
public boolean getShareTag(){
return true;
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld){
2016-01-08 13:31:58 +01:00
BlockPos coords = ItemPhantomConnector.getStoredPosition(stack);
if(coords != null){
2016-04-20 21:39:03 +02:00
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".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());
2016-04-20 21:39:03 +02:00
list.add(TextFormatting.ITALIC+StringUtil.localize("tooltip."+ModUtil.MOD_ID+".clearStorage.desc"));
}
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.EPIC;
}
public enum WrenchMode{
ALWAYS_PARTICLES("always show particles"),
NO_PARTICLES("never show particles"),
HOLDING_PARTICLES("show particles when holding a Laser Wrench");
2016-06-17 23:50:38 +02:00
public final String name;
WrenchMode(String name){
this.name = name;
}
}
}