Player Probe.

Don't know if it works yet though.
This commit is contained in:
Ellpeck 2016-07-14 02:11:41 +02:00
parent 9bafff59d4
commit fdfec92f24
8 changed files with 166 additions and 1 deletions

View file

@ -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);
}
}
}
}

View file

@ -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);

View file

@ -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");

View file

@ -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);
}
}
}
}

View file

@ -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");
}
}

View file

@ -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=<Laser stored!>
tooltip.actuallyadditions.laser.connected.desc=<Laser connected!>
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

View file

@ -0,0 +1,6 @@
{
"parent": "actuallyadditions:item/standardItem",
"textures": {
"layer0": "actuallyadditions:items/itemPlayerProbe"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B