Jump to content

Recommended Posts

Posted (edited)

Hello, i'm trying to do a personal chest in 1.11.2 , it means that when added in world by the player it's his chest, and there is only him who can access it, to do that I apply tag to the tileentity of the personal chest. Everything works fine in single player but I'm having trouble for the multiplayer side and with this function :

 

	@Override
	public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
	    {
	        this.setDefaultFacing(worldIn, pos, state);
	    
		    			TileEntity te = worldIn.getTileEntity(pos);
		    			EntityPlayer playerIn = Minecraft.getMinecraft().player;
		    			System.out.println(playerIn);
				    	if(te != null)
				    	{
				    		te.getTileData().setString("Owner", playerIn.getUniqueID().toString());
				    		te.getTileData().setString("ownerS", playerIn.getName());
				    		int x = te.getPos().getX();
				    		int y = te.getPos().getY();
				    		int z = te.getPos().getZ();
				    		ModEconomy.network.sendToServer(new PacketVaultCreated(playerIn.getName(),playerIn.getUniqueID().toString(),x,y,z));
				    		if(te.getTileData().hasKey("Owner"))
				    		{
					    		this.setBlockUnbreakable();
					    		this.setResistance(20000.0F);
				    		}
		    		}	    	
	    	}

 

But as you can see I'm using 

EntityPlayer playerIn = Minecraft.getMinecraft().player;

 which does not exist in server side, so I searched a bit on google but I can't find a way to recover the EntityPlayer /:

 

So I tought I should recover the entity player of the player who added the block, but I don't know how to do it correctly /: Do you have any hint for me ? :( 

 

Thank you :)

Edited by Fifou_BE
Posted (edited)

 

  On 6/30/2017 at 12:29 PM, Fifou_BE said:

te.getTileData()

Expand  

Why are you using custom tile data on your own TileEntity?

 

  On 6/30/2017 at 12:29 PM, Fifou_BE said:

this.setBlockUnbreakable(); this.setResistance(20000.0F);

Expand  

Blocks are singletons. When this piece of code is executed all your chests will become unbreakable. Even those which are not placed yet. Block::getPlayerRelativeBlockHardness allows you to handle block hardness in cases like this.

 

  On 6/30/2017 at 12:29 PM, Fifou_BE said:

if(te.getTileData().hasKey("Owner"))

Expand  

This condition is redundant as it is always true due to this line above

  On 6/30/2017 at 12:29 PM, Fifou_BE said:

te.getTileData().setString("Owner", playerIn.getUniqueID().toString());

Expand  

 

  On 6/30/2017 at 12:29 PM, Fifou_BE said:

sendToServer

Expand  

Why are you sending anything to the server at this stage? Both Block::onBlockAdded and the suggested Block::onBlockPlacedBy are common code. You do not need to send anything to the server - the server should already have all the data it needs.

 

 

Edited by V0idWa1k3r
Posted
  On 6/30/2017 at 12:59 PM, V0idWa1k3r said:

 

Why are you using custom tile data on your own TileEntity?

 

Blocks are singletons. When this piece of code is executed all your chests will become unbreakable. Even those which are not placed yet. Block::getPlayerRelativeBlockHardness allows you to handle block hardness in cases like this.

 

This condition is redundant as it is always true due to this line above

 

Why are you sending anything to the server at this stage? Both Block::onBlockAdded and the suggested Block::onBlockPlacedBy are common code. You do not need to send anything to the server - the server should already have all the data it needs.

 

 

Expand  

When my block is added on world, it add data to the tile entity in world with some tags such as the owner. It allows only the owner of the tile entity to access it, and destroy it. So if I don't send data to server, it don't link client/server, so the server don't know this tile entity is my tile entity(owner). Hope it's clear ^^ 

Posted
  On 6/30/2017 at 1:06 PM, Fifou_BE said:

When my block is added on world, it add data to the tile entity in world with some tags such as the owner. It allows only the owner of the tile entity to access it, and destroy it.

Expand  

Yes and there is no need to use custom data for that. It is your own tile entity. TileEntity::getTileData is for tile entities that you do not own but want to store some data in. If it is your own tile entity you can and should just declare some fields in that tileentity and set/get them when needed.

 

  On 6/30/2017 at 1:06 PM, Fifou_BE said:

So if I don't send data to server, it don't link client/server, so the server don't know this tile entity is my tile entity(owner).

Expand  

The placement of the block already happens on the server. The server is already aware of the placer as you set it right there. You are literally setting your data on the server and then sending a server -> server packet. That is not a good idea. The client may be the one you need to notify, not the server.

Posted
  On 6/30/2017 at 1:10 PM, V0idWa1k3r said:

Yes and there is no need to use custom data for that. It is your own tile entity. TileEntity::getTileData is for tile entities that you do not own but want to store some data in. If it is your own tile entity you can and should just declare some fields in that tileentity and set/get them when needed.

 

The placement of the block already happens on the server. The server is already aware of the placer as you set it right there. You are literally setting your data on the server and then sending a server -> server packet. That is not a good idea. The client may be the one you need to notify, not the server.

Expand  

 

Ok so I removed the 

 ModEconomy.network.sendToServer(new PacketVaultCreated(playerIn.getName(),playerIn.getUniqueID().toString(),x,y,z));

and when I try to access it, it don't work well. Hmm let me add all my class, like that maybe you can see what I'm trying to do.. I don't say you're not right, but just to be sure.

 

package fr.fifou.economy.blocks;

import javax.annotation.Nullable;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import fr.fifou.economy.ModEconomy;
import fr.fifou.economy.blocks.tileentity.TileEntityBlockVault;
import fr.fifou.economy.gui.GuiHandler;
import fr.fifou.economy.packets.PacketCardChange;
import fr.fifou.economy.packets.PacketVaultCreated;

import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class blockVault extends BlockContainer
{
    public static final PropertyDirection FACING = BlockHorizontal.FACING;
    
	public blockVault() 
	{
		super(Material.IRON);
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
		this.setRegistryName("block_vault");
		this.setUnlocalizedName("block_vault");
		this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);

	}
	
	
	
	  public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
	    {
	    	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2);
  			
	    }
	  
	
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos,IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) 
	{
		TileEntity te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
		if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH))
		{
			if(te.getTileData().hasKey("Owner"))
			{
				String ownerTe = te.getTileData().getString("Owner");
				String ownerWo = playerIn.getUniqueID().toString();
				
				if(ownerWo.equals(ownerTe))
				{
					playerIn.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_NEW, worldIn, pos.getX(), pos.getY(), pos.getZ());
				}
				
			}
		}
         return true;
     }
	
	
	@Override
	public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) 
	{
		TileEntity te = worldIn.getTileEntity(pos);
		if(te.getTileData().hasKey("Owner"))
		{
			String ownerTe = te.getTileData().getString("Owner");
			String ownerWo = playerIn.getUniqueID().toString();
			if(ownerWo.equals(ownerTe))
			{
				this.setResistance(20000.0F);
				this.setHardness(1.0F);
			}
			else
			{
	    		this.setBlockUnbreakable();
	    		this.setResistance(20000.0F);
			}

		}
	}

		
	//FACING
	@Override
	public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
	    {
	   	 this.setDefaultFacing(worldIn, pos, state);
	
			TileEntity te = (TileEntityBlockVault) worldIn.getTileEntity(pos);
			EntityPlayer playerIn = Minecraft.getMinecraft().player;
			System.out.println(playerIn);
			 	if(te != null)
			 	{
			 		te.getTileData().setString("Owner", playerIn.getUniqueID().toString());
			 		te.getTileData().setString("ownerS", playerIn.getName());
			 		int x = te.getPos().getX();
			 		int y = te.getPos().getY();
			 		int z = te.getPos().getZ();
			 		ModEconomy.network.sendToServer(new PacketVaultCreated(playerIn.getName(),playerIn.getUniqueID().toString(),x,y,z));
			 		if(te.getTileData().hasKey("Owner"))
			 		{
			 			 	this.setHardness(1.0F);
				    		this.setResistance(20000.0F);
			 		}
				}	    	
	    }

	    private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
	    {
	        if (!worldIn.isRemote)
	        {
	            IBlockState iblockstate = worldIn.getBlockState(pos.north());
	            IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
	            IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
	            IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
	            EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

	            if (enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
	            {
	                enumfacing = EnumFacing.SOUTH;
	            }
	            else if (enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
	            {
	                enumfacing = EnumFacing.NORTH;
	            }
	            else if (enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
	            {
	                enumfacing = EnumFacing.EAST;
	            }
	            else if (enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
	            {
	                enumfacing = EnumFacing.WEST;
	            }

	            worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
	        }
	    }
	    
	    public static void setState(boolean active, World worldIn, BlockPos pos)
	    {
	        IBlockState iblockstate = worldIn.getBlockState(pos);
	        TileEntity tileentity = worldIn.getTileEntity(pos);

	        if (active)
	        {
	            worldIn.setBlockState(pos, BlocksRegistery.BLOCK_VAULT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
	            worldIn.setBlockState(pos, BlocksRegistery.BLOCK_VAULT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
	        }
	        else
	        {
	            worldIn.setBlockState(pos, BlocksRegistery.BLOCK_VAULT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
	            worldIn.setBlockState(pos, BlocksRegistery.BLOCK_VAULT.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
	        }


	        if (tileentity != null)
	        {
	            tileentity.validate();
	            worldIn.setTileEntity(pos, tileentity);
	        }
	    }
	    
	    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
	    {
	        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
	    }

	    public IBlockState getStateFromMeta(int meta)
	    {
	        EnumFacing enumfacing = EnumFacing.getFront(meta);

	        if (enumfacing.getAxis() == EnumFacing.Axis.Y)
	        {
	            enumfacing = EnumFacing.NORTH;
	        }

	        return this.getDefaultState().withProperty(FACING, enumfacing);
	    }

	    /**
	     * Convert the BlockState into the correct metadata value
	     */
	    public int getMetaFromState(IBlockState state)
	    {
	        return ((EnumFacing)state.getValue(FACING)).getIndex();
	    }

	    /**
	     * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed
	     * blockstate.
	     */
	    public IBlockState withRotation(IBlockState state, Rotation rot)
	    {
	        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
	    }

	    /**
	     * Returns the blockstate with the given mirror of the passed blockstate. If inapplicable, returns the passed
	     * blockstate.
	     */
	    public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
	    {
	        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
	    }

	    protected BlockStateContainer createBlockState()
	    {
	        return new BlockStateContainer(this, new IProperty[] {FACING});
	    }
	
	//OTHERS

	@Override
	public boolean isFullCube(IBlockState state) 
	{
		return false;
	}
	
	@Override
	public boolean isOpaqueCube(IBlockState state) 
	{
		return true;
	}

	  
	  @Override
	  public EnumBlockRenderType getRenderType(IBlockState state)
	  {
	      return EnumBlockRenderType.MODEL;
	  }
	  
	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) 
	{
		return new TileEntityBlockVault();
	}
	  
	@Override
	public void breakBlock(World worldIn, BlockPos pos, IBlockState state) 
	{
		TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
		if(te !=null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH))
		{
			IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH);
			if(inventory != null)
			{
				for(int i=0; i < inventory.getSlots(); i++)
				{
					if(inventory.getStackInSlot(i) != ItemStack.EMPTY)
					{
						EntityItem item = new EntityItem(worldIn, pos.getX() + 0.5, pos.getY()+0.5, pos.getZ() +0.5, inventory.getStackInSlot(i));
						
						float multiplier = 0.1f;
						float motionX = worldIn.rand.nextFloat() - 0.5F;
						float motionY = worldIn.rand.nextFloat() - 0.5F;
						float motionZ = worldIn.rand.nextFloat() - 0.5F;
						
						item.motionX = motionX * multiplier;
						item.motionY = motionY * multiplier;
						item.motionZ = motionZ * multiplier;
						
						worldIn.spawnEntity(item);
					}
				}
			}
		}			
		super.breakBlock(worldIn, pos, state);
	}

}

 

 

Posted (edited)
  On 6/30/2017 at 1:15 PM, Fifou_BE said:

Ok so I removed the 

Expand  

 

  On 6/30/2017 at 1:15 PM, Fifou_BE said:

ModEconomy.network.sendToServer(new PacketVaultCreated(playerIn.getName(),playerIn.getUniqueID().toString(),x,y,z));

Expand  

No you didn't. Not in the class file you've posted. Honestly it looks like you are in a middle of rewriting some code in the class(for example you've added the Block::onBlockPlacedBy but it is empty). You should do it first and post the final code here if you have any issues left.

 

  On 6/30/2017 at 1:15 PM, Fifou_BE said:

if(ownerWo.equals(ownerTe)) { this.setResistance(20000.0F); this.setHardness(1.0F); } else { this.setBlockUnbreakable(); this.setResistance(20000.0F); }

Expand  

As I've said blocks are singletons. Changing their properties like this changes them for all blocks of that type in the world.

Edited by V0idWa1k3r
Posted
  On 6/30/2017 at 1:20 PM, V0idWa1k3r said:

 

No you didn't. Not in the class file you've posted. Honestly it looks like you are in a middle of rewrighting some code in the class(for example you've added the Block::onBlockPlacedBy but it is empty). You should do it first and post the final code here if you have any issues left.

 

As I've said blocks are singletons. Changing their properties like this changes them for all blocks of that type in the world.

Expand  

I didn't remove it, because if I do my code doesn't work anymore. I've posted what I've done since I came here. Just to see if you understand what I'm trying to do ^^ For the part of changing properties like this, it's only for me, this will be modify after but first I wanted to correct the multiplayer crash because of 

EntityPlayer playerIn = Minecraft.getMinecraft().player;

 

then, for the onBlockPlacedBy it was already there because of facing block 

	
	  public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
	    {
	    	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2);
  			
	    }

 

 

 

Posted
  On 6/30/2017 at 1:24 PM, Fifou_BE said:

I didn't remove it, because if I do my code doesn't work anymore. I've posted what I've done since I came here. Just to see if you understand what I'm trying to do ^^

Expand  

We know what you're trying to do. We're trying to tell you that you're doing it wrong and how to fix it, but you keep taking that advice and not doing it.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 6/30/2017 at 1:30 PM, Draco18s said:

We know what you're trying to do. We're trying to tell you that you're doing it wrong and how to fix it, but you keep taking that advice and not doing it.

Expand  

 

Ok so I removed all you told me was wrong.

 

	  public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
	    {
	    	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2);
  			
	    }
	  
	
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos,IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) 
	{
		TileEntity te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
		if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH))
		{
		}
         return true;
     }
	
	
	@Override
	public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) 
	{

	}

 

So, I need to do that in my tile entity then ?

 

	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) 
	{
		compound.setTag("inventory", inventory.serializeNBT());
		compound.setString("owner", player.getUniqueID().toString());
		return super.writeToNBT(compound);
	}

 

But another problem is that I don't understand how to recover the EntityPlayer player here ?

 

Posted

NBT is for storing data when the world is saved, it's not relevant to this issue. When the block is placed, you need to store the placing player in the tileentity. You have access to the block and the placing player in onBlockPlacedBy, you just need to get the tileentity and store the information in there. Then when someone tries to activate the block, you check the tileentity to see if they are the allowed player. You have access to the block and the activating player in onBlockActivated, so you just need to get the tileentity and check the information to respond accordingly.

  • Like 1
Posted (edited)
  On 6/30/2017 at 1:57 PM, Jay Avery said:

NBT is for storing data when the world is saved, it's not relevant to this issue. When the block is placed, you need to store the placing player in the tileentity. You have access to the block and the placing player in onBlockPlacedBy, you just need to get the tileentity and store the information in there. Then when someone tries to activate the block, you check the tileentity to see if they are the allowed player. You have access to the block and the activating player in onBlockActivated, so you just need to get the tileentity and check the information to respond accordingly.

Expand  

 

I've tried something basing my self on TileEntityFlowerPot but I need NBT, because if I close game the data of the tile entity is null ..

 

  public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
	    {
	    	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2);
	    	TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
	    	te.setString(placer.getUniqueID().toString());
	    	System.out.println(te.getOwnerS());
	    	
	    }
	  
	
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos,IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) 
	{
		TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
		if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH))
		{
			if(te.getOwnerS() != null)
			{
				if(te.getOwnerS().equals(playerIn.getUniqueID()))
				{
					System.out.println(te.getOwnerS());
					playerIn.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_NEW, worldIn, pos.getX(), pos.getY(), pos.getZ());
				}
			}
			else
			{
				System.out.println(te.getOwnerS());
			}
		}
         return true;
     }

 

TilEntityBlockVault

 

private static String ownerS;
	
	public TileEntityBlockVault()
	{
		
	}
	
	public TileEntityBlockVault(String ownerData)
	{
		 this.ownerS = ownerData;
	}
	
    public void setString(String string)
    {
        this.ownerS = string;
    }
    
    @Nullable
    public String getOwnerS()
    {
        return this.ownerS;
    }

 

Edited by Fifou_BE
Posted
  On 6/30/2017 at 2:25 PM, Fifou_BE said:

I've tried something basing my self on TileEntityFlowerPot but I need NBT, because if I close game the data of the tile entity is null ..

 

Expand  

Yes, you need NBT, it's just not relevant to this particular issue of making a tileentity which only a certain player can access. NBT is just something you have to do for any tileentity which stores data of some kind.

Posted (edited)

Ok, so is my code correct or do you see some problems ? :)

blockVault


	  public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
	    {
	    	worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing()), 2);
	    	TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
	    	te.setString(placer.getUniqueID().toString());
	    	te.getTileData().setString("ownerS", placer.getUniqueID().toString());
	    	System.out.println(te.getOwnerS());
	    	
	    }
	  
	
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos,IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) 
	{
		TileEntityBlockVault te = (TileEntityBlockVault)worldIn.getTileEntity(pos);
		if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.NORTH))
		{
			if(te.getTileData().getString("ownerS") != null)
			{
				String checkONBT = te.getTileData().getString("ownerS");
				String checkOBA = playerIn.getUniqueID().toString();
				if(checkONBT.equals(checkOBA))
				{
					playerIn.openGui(ModEconomy.instance, GuiHandler.BLOCK_VAULT_NEW, worldIn, pos.getX(), pos.getY(), pos.getZ());
				}
			}
			else
			{
				System.out.println(te.getOwnerS());
			}
		}
         return true;
     }

 

TileEntityBlockVault

 

	ItemStackHandler inventory = new ItemStackHandler(27);
	private static String ownerS;
	
	public TileEntityBlockVault()
	{
		
	}
	
	public TileEntityBlockVault(String ownerData)
	{
		 this.ownerS = ownerData;
	}
	
    public void setString(String string)
    {
        this.ownerS = string;
    }
    
    @Nullable
    public String getOwnerS()
    {
        return this.ownerS;
    }
	
	@Override
	public NBTTagCompound writeToNBT(NBTTagCompound compound) 
	{
		compound.setTag("inventory", inventory.serializeNBT());
		compound.setString("ownerS", this.ownerS);
		return super.writeToNBT(compound);
	}
	
	
	@Override
	public void readFromNBT(NBTTagCompound compound) 
	{
		super.readFromNBT(compound);
		inventory.deserializeNBT(compound.getCompoundTag("inventory"));
		this.ownerS = compound.getString("ownerS");
	}

 

Sorry for being low to understand things ^^

Edited by Fifou_BE
Posted
  Quote
f(te.getTileData().getString("ownerS") != null)
Expand  

You're still using te.getTileData().

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
  On 6/30/2017 at 3:39 PM, Jay Avery said:

You already have a much more convenient way of finding out if your code still has problems: try it and see what happens!

Expand  

That's what I've done, but I prefer to have the advice of someone really qualified ^^ It seems to worked but I should not use te.getTileData().

 

But how am I supposed to get the data from the tile entity then ? I looked trough all the methods and nothing is similar to getTileData() :/ !

Posted
  On 6/30/2017 at 3:55 PM, Fifou_BE said:

That's what I've done, but I prefer to have the advice of someone really qualified ^^ It seems to worked but I should not use te.getTileData().

 

But how am I supposed to get the data from the tile entity then ? I looked trough all the methods and nothing is similar to getTileData() :/ !

Expand  

You have made a method yourself which gives the data from the tileentity: 

    public String getOwnerS()

 

Also, this field should not be static:

	private static String ownerS;

Static means there is one value for the whole class, rather than one value per instance. If someone places a new tileentity, they will become the owner of ALL tileentities of that type. Presumably that's not what you're going for. You also cannot use this. with static fields - your IDE should give you a warning if you do.

Posted (edited)

I've changed all of this, thank you :) I have this prompt on the log but can it be linked to my mod or it's mc ?

 

[18:09:04] [pool-2-thread-1/WARN]: Couldn't look up profile properties for com.mojang.authlib.GameProfile@7bd76e78[id=1180fda0-fbd6-4eaa-a861-61fd3910f6fc,name=Fifou_BE,properties={},legacy=false]
com.mojang.authlib.exceptions.AuthenticationException: The client has sent too many requests within a certain amount of time
	at com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService.makeRequest(YggdrasilAuthenticationService.java:79) ~[YggdrasilAuthenticationService.class:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillGameProfile(YggdrasilMinecraftSessionService.java:180) [YggdrasilMinecraftSessionService.class:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:60) [YggdrasilMinecraftSessionService$1.class:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService$1.load(YggdrasilMinecraftSessionService.java:57) [YggdrasilMinecraftSessionService$1.class:?]
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3524) [guava-17.0.jar:?]
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2317) [guava-17.0.jar:?]
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2280) [guava-17.0.jar:?]
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2195) [guava-17.0.jar:?]
	at com.google.common.cache.LocalCache.get(LocalCache.java:3934) [guava-17.0.jar:?]
	at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3938) [guava-17.0.jar:?]
	at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4821) [guava-17.0.jar:?]
	at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4827) [guava-17.0.jar:?]
	at com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService.fillProfileProperties(YggdrasilMinecraftSessionService.java:170) [YggdrasilMinecraftSessionService.class:?]
	at net.minecraft.client.Minecraft.getProfileProperties(Minecraft.java:3056) [Minecraft.class:?]
	at net.minecraft.client.resources.SkinManager$3.run(SkinManager.java:138) [SkinManager$3.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_131]
	at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_131]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_131]
	at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]

 

Edited by Fifou_BE

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Looking for the best Temu coupon code $100 off? You’re in the right place! We’ve got the ultimate deal that helps you save big on your favorite items. Our exclusive ACS670886 Temu coupon code is perfect for shoppers in the USA, Canada, and Europe. Whether you're a new or existing customer, this code ensures you get maximum benefits. By using the Temu coupon $100 off, you can unlock exciting savings on Temu’s vast collection. Don’t miss this chance to claim your Temu 100 off coupon code today! What Is The Coupon Code For Temu $100 Off? Both new and existing customers can enjoy incredible benefits with our Temu coupon $100 off on the Temu app and website. This $100 off Temu coupon ensures huge savings for everyone! ACS670886 – Get a flat $100 off on selected purchases. ACS670886 – Unlock a $100 coupon pack for multiple uses. ACS670886 – Enjoy a $100 flat discount if you're a new customer. ACS670886 – Existing customers can claim an extra $100 promo code. ACS670886 – This $100 coupon is valid for shoppers in the USA and Canada. Temu Coupon Code $100 Off For New Users In 2025 New users can maximize their savings by applying our Temu coupon $100 off on the Temu app. This Temu coupon code $100 off unlocks amazing deals for first-time shoppers. ACS670886 – Get a flat $100 discount for new users. ACS670886 – Receive a $100 coupon bundle as a welcome offer. ACS670886 – Unlock up to $100 in coupons for multiple uses. ACS670886 – Enjoy free shipping to 68 countries. ACS670886 – Get an extra 30% off on any purchase as a first-time user. How To Redeem The Temu Coupon $100 Off For New Customers? Using the Temu $100 coupon is easy! Follow these steps to redeem your Temu $100 off coupon code for new users: Sign up on the Temu app or website. Browse and add your favorite items to the cart. Enter ACS670886 at checkout. See the $100 discount applied instantly. Complete your purchase and enjoy your savings! Temu Coupon $100 Off For Existing Customers Existing customers can also benefit from our exclusive Temu $100 coupon codes for existing users. Use this Temu coupon $100 off for existing customers free shipping deal and save more! ACS670886 – Get an extra $100 discount for existing users. ACS670886 – Enjoy a $100 coupon bundle for multiple purchases. ACS670886 – Receive a free gift with express shipping across the USA/Canada. ACS670886 – Grab an extra 30% off on top of existing discounts. ACS670886 – Avail free shipping to 68 countries. How To Use The Temu Coupon Code $100 Off For Existing Customers? Redeeming your Temu coupon code $100 off as an existing user is simple. Just follow these steps: Log in to your Temu account. Select your desired products and add them to your cart. Apply ACS670886 at checkout. Your Temu coupon $100 off code will be applied automatically. Confirm your order and enjoy massive savings! Latest Temu Coupon $100 Off First Order First-time buyers get the best deals with our Temu coupon code $100 off first order. This Temu coupon code first order ensures maximum savings. ACS670886 – Flat $100 discount for the first order. ACS670886 – Special $100 Temu coupon code for new customers. ACS670886 – Get up to $100 in coupons for multiple uses. ACS670886 – Free shipping to 68 countries. ACS670886 – Extra 30% off on any first-time purchase. How To Find The Temu Coupon Code $100 Off? Finding a Temu coupon $100 off is easy! Check out the Temu coupon $100 off Reddit section or follow these tips: Subscribe to the Temu newsletter for exclusive deals. Follow Temu’s official social media pages for the latest updates. Visit trusted coupon sites for verified and working codes. Is Temu $100 Off Coupon Legit? Yes, our Temu $100 Off Coupon Legit and verified! Wondering if the Temu 100 off coupon legit? Here’s why: The ACS670886 code is officially tested and confirmed. Valid for all customers in the USA, Canada, and Europe. No expiration date—use it anytime! How Does Temu $100 Off Coupon Work? The Temu coupon code $100 off first-time user works instantly upon applying at checkout. Simply enter the Temu coupon codes 100 off, and the discount is automatically deducted. How To Earn Temu $100 Coupons As A New Customer? To earn a Temu coupon code $100 off, sign up on Temu, make your first purchase, and refer friends. This 100 off Temu coupon code can be unlocked through special promotions. What Are The Advantages Of Using The Temu Coupon $100 Off? $100 discount on the first order $100 coupon bundle for multiple uses 70% discount on popular items Extra 30% off for existing customers Up to 90% off on selected products Free gifts for new users Free delivery to 68 countries Temu $100 Discount Code And Free Gift For New And Existing Customers Enjoy the Temu $100 off coupon code and get amazing benefits! Our $100 off Temu coupon code ensures huge savings. ACS670886 – $100 discount for the first order. ACS670886 – Extra 30% off on any item. ACS670886 – Free gift for new Temu users. ACS670886 – Up to 70% discount on all Temu items. ACS670886 – Free shipping in 68 countries including the USA and UK. Final Note: Use The Latest Temu Coupon Code $100 Off Using the Temu coupon code $100 off is the smartest way to save on Temu! Don’t wait—grab your discount now. Our Temu coupon $100 off is available for all customers, ensuring maximum savings. Get yours today! FAQs Of Temu $100 Off Coupon Q: How can I get the Temu $100 off coupon? A: Use code ACS670886 at checkout to claim your $100 discount. Q: Is the Temu $100 coupon valid for existing customers? A: Yes! Existing users can also apply ACS670886 and enjoy savings. Q: Does the Temu $100 off coupon have an expiration date? A: No, ACS670886 is valid indefinitely. Q: Can I use the Temu coupon on multiple orders? A: Yes! ACS670886 allows multiple redemptions. Q: Is the Temu $100 coupon applicable worldwide? A: Yes, it’s valid in the USA, Canada, Europe, and 68 other countries.
    • I tried both Vanilla and Optfine like you said, and both gave the same result. So I believe the issue is most likely with Minecraft in general and not Forge
    • https://pastebin.com/xWy0mWXA Like I said Modded Java Edition 1.12.2 using Forge Version 14.23.5.2859 Oh yeah and Exit Code: 1  
    • I love GTA V — Minecraft feels like a kids' game to me.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.