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;
|
|
|
|
|
2018-05-10 11:38:58 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
2016-07-14 02:11:41 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface;
|
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;
|
2017-06-17 00:48:49 +02:00
|
|
|
import net.minecraft.client.util.ITooltipFlag;
|
2016-07-14 02:11:41 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2016-07-14 02:11:41 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2016-07-14 02:11:41 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
2021-02-27 13:24:45 +01:00
|
|
|
import net.minecraft.util.Direction;
|
2021-02-26 22:15:48 +01:00
|
|
|
import net.minecraft.util.Hand;
|
2016-07-14 02:11:41 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public class ItemPlayerProbe extends ItemBase {
|
2016-07-14 02:11:41 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
public ItemPlayerProbe(String name) {
|
2016-07-14 02:11:41 +02:00
|
|
|
super(name);
|
|
|
|
this.setMaxStackSize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
|
|
|
|
if (!world.isRemote) {
|
|
|
|
if (stack.hasTagCompound()) {
|
2021-02-26 22:15:48 +01:00
|
|
|
CompoundNBT compound = stack.getTagCompound();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (compound.hasKey("UUIDMost")) {
|
2016-07-14 02:11:41 +02:00
|
|
|
UUID id = compound.getUniqueId("UUID");
|
2021-02-26 22:15:48 +01:00
|
|
|
PlayerEntity player = world.getPlayerEntityByUUID(id);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (player != null) {
|
|
|
|
if (player.isSneaking()) {
|
2016-09-25 20:44:40 +02:00
|
|
|
ItemPhantomConnector.clearStorage(stack, "UUIDLeast", "UUIDMost", "Name");
|
2019-05-02 09:10:29 +02:00
|
|
|
entity.sendMessage(new TextComponentTranslation("tooltip." + ActuallyAdditions.MODID + ".playerProbe.disconnect.1"));
|
|
|
|
player.sendMessage(new TextComponentTranslation("tooltip." + ActuallyAdditions.MODID + ".playerProbe.notice"));
|
2017-06-17 00:48:49 +02:00
|
|
|
//TheAchievements.GET_UNPROBED.get(player);
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
2019-05-02 09:10:29 +02:00
|
|
|
} else {
|
2016-12-30 20:09:05 +01:00
|
|
|
ItemPhantomConnector.clearStorage(stack, "UUIDLeast", "UUIDMost", "Name");
|
2019-05-02 09:10:29 +02:00
|
|
|
entity.sendMessage(new TextComponentTranslation("tooltip." + ActuallyAdditions.MODID + ".playerProbe.disconnect.2"));
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 13:24:45 +01:00
|
|
|
public EnumActionResult onItemUse(PlayerEntity player, World world, BlockPos pos, Hand hand, Direction facing, float hitX, float hitY, float hitZ) {
|
2016-11-19 21:11:17 +01:00
|
|
|
ItemStack stack = player.getHeldItem(hand);
|
2016-07-14 02:11:41 +02:00
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
2019-05-02 09:10:29 +02:00
|
|
|
if (tile instanceof TileEntityPlayerInterface) {
|
|
|
|
if (stack.hasTagCompound()) {
|
2021-02-26 22:15:48 +01:00
|
|
|
CompoundNBT compound = stack.getTagCompound();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (compound.hasKey("UUIDMost")) {
|
|
|
|
if (!world.isRemote) {
|
|
|
|
TileEntityPlayerInterface face = (TileEntityPlayerInterface) tile;
|
2016-07-14 02:11:41 +02:00
|
|
|
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
|
2021-02-26 22:15:48 +01:00
|
|
|
public boolean itemInteractionForEntity(ItemStack aStack, PlayerEntity player, EntityLivingBase entity, Hand hand) {
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!player.world.isRemote) {
|
2016-07-14 13:41:29 +02:00
|
|
|
ItemStack stack = player.getHeldItemMainhand();
|
2019-05-02 09:10:29 +02:00
|
|
|
if (StackUtil.isValid(stack) && stack.getItem() == this) {
|
2021-02-26 22:15:48 +01:00
|
|
|
if (entity instanceof PlayerEntity) {
|
|
|
|
PlayerEntity playerHit = (PlayerEntity) entity;
|
2016-07-14 02:11:41 +02:00
|
|
|
|
2019-05-02 09:10:29 +02:00
|
|
|
if (!playerHit.isSneaking()) {
|
|
|
|
if (!stack.hasTagCompound()) {
|
2021-02-26 22:15:48 +01:00
|
|
|
stack.setTagCompound(new CompoundNBT());
|
2016-07-14 13:41:29 +02:00
|
|
|
}
|
2016-07-14 02:11:41 +02:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
CompoundNBT compound = stack.getTagCompound();
|
2016-07-14 13:41:29 +02:00
|
|
|
compound.setString("Name", playerHit.getName());
|
|
|
|
compound.setUniqueId("UUID", playerHit.getUniqueID());
|
|
|
|
return true;
|
|
|
|
}
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-05-02 09:10:29 +02:00
|
|
|
public void addInformation(ItemStack stack, @Nullable World playerIn, List<String> tooltip, ITooltipFlag advanced) {
|
|
|
|
if (stack.hasTagCompound()) {
|
2016-07-14 02:11:41 +02:00
|
|
|
String name = stack.getTagCompound().getString("Name");
|
2019-05-02 09:10:29 +02:00
|
|
|
if (name != null) {
|
|
|
|
tooltip.add(StringUtil.localize("tooltip." + ActuallyAdditions.MODID + ".playerProbe.probing") + ": " + name);
|
2016-07-14 02:11:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|