2016-07-14 02:11:41 +02:00
|
|
|
/*
|
|
|
|
* This file ("ItemPlayerProbe.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://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2016-07-14 02:11:41 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package de.ellpeck.actuallyadditions.mod.items;
|
|
|
|
|
2016-08-06 17:50:54 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
|
2016-07-14 02:11:41 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
2016-11-16 20:31:16 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-07-14 02:11:41 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.EnumHand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
public class ItemPlayerProbe extends ItemBase{
|
|
|
|
|
|
|
|
public ItemPlayerProbe(String name){
|
|
|
|
super(name);
|
|
|
|
this.setMaxStackSize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected){
|
|
|
|
if(!world.isRemote){
|
|
|
|
if(stack.hasTagCompound()){
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
2016-07-14 13:41:29 +02:00
|
|
|
if(compound.hasKey("UUIDMost")){
|
2016-07-14 02:11:41 +02:00
|
|
|
UUID id = compound.getUniqueId("UUID");
|
|
|
|
EntityPlayer player = world.getPlayerEntityByUUID(id);
|
|
|
|
if(player != null){
|
|
|
|
if(player.isSneaking()){
|
2016-09-25 20:44:40 +02:00
|
|
|
ItemPhantomConnector.clearStorage(stack, "UUIDLeast", "UUIDMost", "Name");
|
2016-11-26 21:32:27 +01:00
|
|
|
entity.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".playerProbe.disconnect.1"));
|
|
|
|
player.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".playerProbe.notice"));
|
2016-08-06 17:50:54 +02:00
|
|
|
TheAchievements.GET_UNPROBED.get(player);
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2016-12-30 20:09:05 +01:00
|
|
|
ItemPhantomConnector.clearStorage(stack, "UUIDLeast", "UUIDMost", "Name");
|
2016-11-26 21:32:27 +01:00
|
|
|
entity.sendMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".playerProbe.disconnect.2"));
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-11-19 21:11:17 +01:00
|
|
|
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){
|
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2016-07-14 02:11:41 +02:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if(tile instanceof TileEntityPlayerInterface){
|
|
|
|
if(stack.hasTagCompound()){
|
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
2016-07-14 13:41:29 +02:00
|
|
|
if(compound.hasKey("UUIDMost")){
|
2016-07-14 02:11:41 +02:00
|
|
|
if(!world.isRemote){
|
|
|
|
TileEntityPlayerInterface face = (TileEntityPlayerInterface)tile;
|
|
|
|
face.connectedPlayer = compound.getUniqueId("UUID");
|
|
|
|
face.playerName = compound.getString("Name");
|
|
|
|
face.markDirty();
|
|
|
|
face.sendUpdate();
|
2016-07-14 13:41:29 +02:00
|
|
|
|
2016-12-30 20:09:05 +01:00
|
|
|
ItemPhantomConnector.clearStorage(stack, "UUIDLeast", "UUIDMost", "Name");
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
|
|
|
return EnumActionResult.SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return EnumActionResult.FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-14 13:41:29 +02:00
|
|
|
public boolean itemInteractionForEntity(ItemStack aStack, EntityPlayer player, EntityLivingBase entity, EnumHand hand){
|
2016-11-26 21:32:27 +01:00
|
|
|
if(!player.world.isRemote){
|
2016-07-14 13:41:29 +02:00
|
|
|
ItemStack stack = player.getHeldItemMainhand();
|
2016-11-16 20:31:16 +01:00
|
|
|
if(StackUtil.isValid(stack) && stack.getItem() == this){
|
2016-07-14 13:41:29 +02:00
|
|
|
if(entity instanceof EntityPlayer){
|
|
|
|
EntityPlayer playerHit = (EntityPlayer)entity;
|
2016-07-14 02:11:41 +02:00
|
|
|
|
2016-07-14 13:41:29 +02:00
|
|
|
if(!playerHit.isSneaking()){
|
|
|
|
if(!stack.hasTagCompound()){
|
|
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
|
|
}
|
2016-07-14 02:11:41 +02:00
|
|
|
|
2016-07-14 13:41:29 +02:00
|
|
|
NBTTagCompound compound = stack.getTagCompound();
|
|
|
|
compound.setString("Name", playerHit.getName());
|
|
|
|
compound.setUniqueId("UUID", playerHit.getUniqueID());
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld){
|
|
|
|
if(stack.hasTagCompound()){
|
|
|
|
String name = stack.getTagCompound().getString("Name");
|
|
|
|
if(name != null){
|
|
|
|
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID+".playerProbe.probing")+": "+name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|