From fdfec92f2494f90e191b2bcf2073b6b6e4f319c3 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 14 Jul 2016 02:11:41 +0200 Subject: [PATCH] Player Probe. Don't know if it works yet though. --- .../mod/blocks/BlockPlayerInterface.java | 32 ++++- .../mod/creative/CreativeTab.java | 1 + .../mod/items/InitItems.java | 2 + .../mod/items/ItemPlayerProbe.java | 118 ++++++++++++++++++ .../mod/tile/TileEntityPlayerInterface.java | 3 + .../assets/actuallyadditions/lang/en_US.lang | 5 + .../models/item/itemPlayerProbe.json | 6 + .../textures/items/itemPlayerProbe.png | Bin 0 -> 456 bytes 8 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java create mode 100644 src/main/resources/assets/actuallyadditions/models/item/itemPlayerProbe.json create mode 100644 src/main/resources/assets/actuallyadditions/textures/items/itemPlayerProbe.png diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java index 2985b692c..a40b9613e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockPlayerInterface.java @@ -10,19 +10,33 @@ package de.ellpeck.actuallyadditions.mod.blocks; +import de.ellpeck.actuallyadditions.api.tile.IPhantomTile; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import de.ellpeck.actuallyadditions.mod.util.StringUtil; +import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.profiler.Profiler; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.RayTraceResult; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; -public class BlockPlayerInterface extends BlockContainerBase{ +public class BlockPlayerInterface extends BlockContainerBase implements IHudDisplay{ public BlockPlayerInterface(String name){ super(Material.ROCK, name); @@ -49,10 +63,26 @@ public class BlockPlayerInterface extends BlockContainerBase{ TileEntityPlayerInterface face = (TileEntityPlayerInterface)tile; if(face.connectedPlayer == null){ face.connectedPlayer = player.getUniqueID(); + face.playerName = player.getName(); face.markDirty(); + face.sendUpdate(); } } super.onBlockPlacedBy(world, pos, state, player, stack); } + + @Override + @SideOnly(Side.CLIENT) + public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, Profiler profiler, ScaledResolution resolution){ + TileEntity tile = minecraft.theWorld.getTileEntity(posHit.getBlockPos()); + if(tile != null){ + if(tile instanceof TileEntityPlayerInterface){ + TileEntityPlayerInterface face = (TileEntityPlayerInterface)tile; + String name = face.playerName == null ? "Unknown" : face.playerName; + minecraft.fontRendererObj.drawStringWithShadow("Bound to: "+TextFormatting.RED+name, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE); + minecraft.fontRendererObj.drawStringWithShadow("UUID: "+TextFormatting.DARK_GREEN+face.connectedPlayer, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE); + } + } + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java index accdf5025..a8b81546e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java @@ -136,6 +136,7 @@ public class CreativeTab extends CreativeTabs{ this.add(InitBlocks.blockBlackLotus); this.add(InitBlocks.blockBookletStand); + this.add(InitItems.itemPlayerProbe); this.add(InitItems.itemColorLens); this.add(InitItems.itemExplosionLens); this.add(InitItems.itemDamageLens); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java index 6ed36ad59..d3fa4570c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java @@ -207,10 +207,12 @@ public final class InitItems{ public static Item itemWaterBowl; public static Item itemFilter; + public static Item itemPlayerProbe; public static void init(){ ModUtil.LOGGER.info("Initializing Items..."); + itemPlayerProbe = new ItemPlayerProbe("itemPlayerProbe"); itemFilter = new ItemFilter("itemFilter"); itemWaterBowl = new ItemWaterBowl("itemWaterBowl"); itemSpawnerChanger = new ItemSpawnerChanger("itemSpawnerChanger"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java new file mode 100644 index 000000000..562b0e4cc --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemPlayerProbe.java @@ -0,0 +1,118 @@ +/* + * 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 + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.items; + +import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; +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.TextComponentString; +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(); + if(compound.hasKey("UUID")){ + UUID id = compound.getUniqueId("UUID"); + EntityPlayer player = world.getPlayerEntityByUUID(id); + if(player != null){ + if(player.isSneaking()){ + stack.setTagCompound(new NBTTagCompound()); + entity.addChatMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".playerProbe.disconnect.1")); + player.addChatMessage(new TextComponentTranslation("tooltip."+ModUtil.MOD_ID+".playerProbe.notice")); + } + } + else{ + stack.setTagCompound(new NBTTagCompound()); + entity.addChatMessage(new TextComponentString("tooltip."+ModUtil.MOD_ID+".playerProbe.disconnect.2")); + } + } + } + } + } + + @Override + public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){ + TileEntity tile = world.getTileEntity(pos); + if(tile instanceof TileEntityPlayerInterface){ + if(stack.hasTagCompound()){ + NBTTagCompound compound = stack.getTagCompound(); + if(compound.hasKey("UUID")){ + if(!world.isRemote){ + TileEntityPlayerInterface face = (TileEntityPlayerInterface)tile; + face.connectedPlayer = compound.getUniqueId("UUID"); + face.playerName = compound.getString("Name"); + face.markDirty(); + face.sendUpdate(); + } + return EnumActionResult.SUCCESS; + } + } + } + return EnumActionResult.FAIL; + } + + @Override + public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity, EnumHand hand){ + if(!player.worldObj.isRemote){ + if(entity instanceof EntityPlayer){ + EntityPlayer playerHit = (EntityPlayer)entity; + + if(!playerHit.isSneaking()){ + if(!stack.hasTagCompound()){ + stack.setTagCompound(new NBTTagCompound()); + } + + NBTTagCompound compound = stack.getTagCompound(); + compound.setString("Name", playerHit.getName()); + compound.setUniqueId("UUID", playerHit.getUniqueID()); + } + } + } + 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); + } + } + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java index 96d246e56..df88393cc 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java @@ -25,6 +25,7 @@ public class TileEntityPlayerInterface extends TileEntityInventoryBase implement public static final int DEFAULT_RANGE = 32; private final EnergyStorage storage = new EnergyStorage(30000); public UUID connectedPlayer; + public String playerName; private int oldEnergy; private int range; @@ -85,6 +86,7 @@ public class TileEntityPlayerInterface extends TileEntityInventoryBase implement this.storage.writeToNBT(compound); if(this.connectedPlayer != null && type != NBTType.SAVE_BLOCK){ compound.setUniqueId("Player", this.connectedPlayer); + compound.setString("PlayerName", this.playerName); } } @@ -93,6 +95,7 @@ public class TileEntityPlayerInterface extends TileEntityInventoryBase implement this.storage.readFromNBT(compound); if(compound.hasKey("PlayerLeast") && type != NBTType.SAVE_BLOCK){ this.connectedPlayer = compound.getUniqueId("Player"); + this.playerName = compound.getString("PlayerName"); } } diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index 1694ab5ce..a57599877 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -496,6 +496,7 @@ item.actuallyadditions.itemWaterBowl.name=Bowl of Water item.actuallyadditions.itemFilter.name=Item Filter item.actuallyadditions.itemMiscBiomass.name=Biomass item.actuallyadditions.itemMiscBiocoal.name=Bio Coal +item.actuallyadditions.itemPlayerProbe.name=Player Probe #Tooltips tooltip.actuallyadditions.onSuffix.desc=On @@ -526,6 +527,10 @@ tooltip.actuallyadditions.laser.stored.desc= tooltip.actuallyadditions.laser.connected.desc= tooltip.actuallyadditions.laser.cantConnect.desc=Can't connect: The relays are either part of the same network, the stored relay isn't the same type or doesn't exist anymore or it is too far away! tooltip.actuallyadditions.itemBooklet.desc=Or "Booklet", if you will +tooltip.actuallyadditions.playerProbe.disconnect.1=The player you were probing has broken the connection before you could strap him to the Player Interface! Data will be cleared! +tooltip.actuallyadditions.playerProbe.disconnect.2=The player you were probing has disconnected before you could strap him to the Player Interface! Data will be cleared! +tooltip.actuallyadditions.playerProbe.probing=Probing +tooltip.actuallyadditions.playerProbe.notice=Look out! Someone tried to probe you and strap you to a Player Interface, but they failed! #Gui Information info.actuallyadditions.gui.animals=Animals diff --git a/src/main/resources/assets/actuallyadditions/models/item/itemPlayerProbe.json b/src/main/resources/assets/actuallyadditions/models/item/itemPlayerProbe.json new file mode 100644 index 000000000..8a934a352 --- /dev/null +++ b/src/main/resources/assets/actuallyadditions/models/item/itemPlayerProbe.json @@ -0,0 +1,6 @@ +{ + "parent": "actuallyadditions:item/standardItem", + "textures": { + "layer0": "actuallyadditions:items/itemPlayerProbe" + } +} diff --git a/src/main/resources/assets/actuallyadditions/textures/items/itemPlayerProbe.png b/src/main/resources/assets/actuallyadditions/textures/items/itemPlayerProbe.png new file mode 100644 index 0000000000000000000000000000000000000000..60dfe1b7920ffa18370c816f81e901211cf235ef GIT binary patch literal 456 zcmV;(0XP1MP)N2bZe?^J zG%heMIczh2P5=M_MoC0LR5(v#0D=Gi|C5Zdf`WpA|H;Y8SY<;(La@tuE}Q~oF))OM zh5ZK^0>V%sFaT);iGd7(3ZVjILqLiH0|QYM;?;}}jE#-4Dl|1UCC&g{UETlaia~s$ z4A58L1uFy@q9McmUqyoBznT;mTufI+5WgYXa=iax*jPpIzmt~Ge|s&_|2lGf5JP|l z05McG768(?tuyEU-oB#$$EG#>-`iaTWS9J3Qx^5#L{*5e0jp}${%>i?{STtoHst=F zQxx-mcW2T6Ihj6SOwa(3W)KLn?fk#BIvuPT#0CM7p#%+>lkE0?b9K`H?M+4hvm6Y- zcwa}(|3z8u{~Ll$2pcdV&iVhec!&SxPNpchKhExdW3VM*1M*#U{^vStffa*rm7nqd y=1^-e2C)em098N;LsjDdAO(al2te`=0|Nl$A@;)Bsrq050000