Jump to content

onBlockAdded and EntityPlayer


Fifou_BE
 Share

Recommended Posts

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
Link to comment
Share on other sites

If you use Block#onBlockPlacedBy, you'll get the EntityLivingBase who placed the Block as a variable.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

 

30 minutes ago, Fifou_BE said:

te.getTileData()

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

 

30 minutes ago, Fifou_BE said:

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

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.

 

30 minutes ago, Fifou_BE said:

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

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

30 minutes ago, Fifou_BE said:

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

 

30 minutes ago, Fifou_BE said:

sendToServer

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
Link to comment
Share on other sites

1 minute ago, 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.

 

 

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 ^^ 

Link to comment
Share on other sites

1 minute ago, 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.

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.

 

2 minutes ago, 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).

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.

Link to comment
Share on other sites

1 minute ago, 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.

 

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

}

 

 

Link to comment
Share on other sites

5 minutes ago, Fifou_BE said:

Ok so I removed the 

 

5 minutes ago, Fifou_BE said:

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

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.

 

5 minutes ago, Fifou_BE said:

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

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
Link to comment
Share on other sites

Just now, 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.

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

 

 

 

Link to comment
Share on other sites

3 minutes ago, 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 ^^

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.

Link to comment
Share on other sites

8 minutes ago, 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.

 

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 ?

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

28 minutes ago, 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.

 

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
Link to comment
Share on other sites

2 minutes ago, 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 ..

 

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Quote

f(te.getTileData().getString("ownerS") != null)

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.

Link to comment
Share on other sites

14 minutes ago, 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!

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() :/ !

Link to comment
Share on other sites

1 minute ago, 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() :/ !

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! I downloaded the MrCrayfishs Furniture mod for 1.19.3. I also have 1.19.3 for forge and optifine. It's the only mod in my mods folder. It would be nice if anyone could help me. xx This is the crash report: ---- Minecraft Crash Report ---- // My bad. Time: 2023-01-30 13:17:38 Description: Mod loading error has occurred java.lang.Exception: Mod Loading has failed     at net.minecraftforge.logging.CrashReportExtender.dumpModLoadingCrashReport(CrashReportExtender.java:55) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading}     at net.minecraftforge.client.loading.ClientModLoader.completeModLoading(ClientModLoader.java:167) ~[forge-1.19.3-44.1.0-universal.jar%23155!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.lambda$new$2(Minecraft.java:588) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.Util.m_137521_(Util.java:432) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading}     at net.minecraft.client.Minecraft.lambda$new$3(Minecraft.java:582) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.gui.screens.LoadingOverlay.m_86412_(LoadingOverlay.java:137) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:920) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1135) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:713) ~[client-1.19.3-20221207.122022-srg.jar%23150!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.m_239872_(Main.java:212) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:51) ~[1.19.3-forge-44.1.0.jar:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:27) ~[fmlloader-1.19.3-44.1.0.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) ~[modlauncher-10.0.8.jar:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) ~[bootstraplauncher-1.1.2.jar:?] {} A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Thread: Render thread Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {} -- MOD cfm -- Details:     Caused by 0: java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider         at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}         at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}         at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}         at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}         at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}         at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}         at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}         at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}         at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}         at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}         at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}     Mod File: /C:/Users/User/AppData/Roaming/.minecraft/mods/MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar     Failure message: MrCrayfish's Furniture Mod (cfm) has failed to load correctly         java.lang.NoClassDefFoundError: net/minecraft/data/tags/BlockTagsProvider     Mod Version: 7.0.0-pre34     Mod Issue URL: https://github.com/MrCrayfish/MrCrayfishFurnitureMod/issues     Exception message: java.lang.ClassNotFoundException: net.minecraft.data.tags.BlockTagsProvider Stacktrace:     at cpw.mods.cl.ModuleClassLoader.loadClass(ModuleClassLoader.java:141) ~[securejarhandler-2.1.4.jar:?] {}     at java.lang.ClassLoader.loadClass(ClassLoader.java:520) ~[?:?] {}     at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:?] {}     at java.lang.Class.privateGetDeclaredConstructors(Class.java:3373) ~[?:?] {}     at java.lang.Class.getConstructor0(Class.java:3578) ~[?:?] {}     at java.lang.Class.getDeclaredConstructor(Class.java:2754) ~[?:?] {}     at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:68) ~[javafmllanguage-1.19.3-44.1.0.jar%23152!/:?] {}     at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$10(ModContainer.java:121) ~[fmlcore-1.19.3-44.1.0.jar%23151!/:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?] {}     at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) ~[?:?] {}     at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}     at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}     at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}     at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {} -- System Details -- Details:     Minecraft Version: 1.19.3     Minecraft Version ID: 1.19.3     Operating System: Windows 10 (amd64) version 10.0     Java Version: 17.0.3, Microsoft     Java VM Version: OpenJDK 64-Bit Server VM (mixed mode), Microsoft     Memory: 241410776 bytes (230 MiB) / 503316480 bytes (480 MiB) up to 2147483648 bytes (2048 MiB)     CPUs: 4     Processor Vendor: AuthenticAMD     Processor Name: AMD FX-8800P Radeon R7, 12 Compute Cores 4C+8G      Identifier: AuthenticAMD Family 21 Model 96 Stepping 1     Microarchitecture: unknown     Frequency (GHz): 2.10     Number of physical packages: 1     Number of physical CPUs: 4     Number of logical CPUs: 4     Graphics card #0 name: AMD Radeon R7 Graphics     Graphics card #0 vendor: Advanced Micro Devices, Inc. (0x1002)     Graphics card #0 VRAM (MB): 256.00     Graphics card #0 deviceId: 0x9874     Graphics card #0 versionInfo: DriverVersion=27.20.1034.6     Memory slot #0 capacity (MB): 8192.00     Memory slot #0 clockSpeed (GHz): 2.13     Memory slot #0 type: DDR4     Memory slot #1 capacity (MB): 8192.00     Memory slot #1 clockSpeed (GHz): 2.13     Memory slot #1 type: DDR4     Virtual memory max (MB): 18519.90     Virtual memory used (MB): 7647.12     Swap memory total (MB): 2432.00     Swap memory used (MB): 35.46     JVM Flags: 9 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xss1M -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M     ModLauncher: 10.0.8+10.0.8+main.0ef7e830     ModLauncher launch target: forgeclient     ModLauncher naming: srg     ModLauncher services:          mixin-0.8.5.jar mixin PLUGINSERVICE          eventbus-6.0.3.jar eventbus PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar slf4jfixer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar object_holder_definalize PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtime_enum_extender PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar capability_token_subclass PLUGINSERVICE          accesstransformers-8.0.4.jar accesstransformer PLUGINSERVICE          fmlloader-1.19.3-44.1.0.jar runtimedistcleaner PLUGINSERVICE          modlauncher-10.0.8.jar mixin TRANSFORMATIONSERVICE          modlauncher-10.0.8.jar fml TRANSFORMATIONSERVICE      FML Language Providers:          minecraft@1.0         lowcodefml@null         javafml@null     Mod List:          client-1.19.3-20221207.122022-srg.jar             |Minecraft                     |minecraft                     |1.19.3              |COMMON_SET|Manifest: a1:d4:5e:04:4f:d3:d6:e0:7b:37:97:cf:77:b0:de:ad:4a:47:ce:8c:96:49:5f:0a:cf:8c:ae:b2:6d:4b:8a:3f         forge-1.19.3-44.1.0-universal.jar                 |Forge                         |forge                         |44.1.0              |COMMON_SET|Manifest: 84:ce:76:e8:45:35:e4:0e:63:86:df:47:59:80:0f:67:6c:c1:5f:6e:5f:4d:b3:54:47:1a:9f:7f:ed:5e:f2:90         MrCrayfishs-Furniture-Mod-Forge-1.19.3.jar        |MrCrayfish's Furniture Mod    |cfm                           |7.0.0-pre34         |ERROR     |Manifest: NOSIGNATURE     Crash Report UUID: d668c79d-366a-4acb-9754-f4cd52ab88cb     FML: 44.1     Forge: net.minecraftforge:44.1.0
    • thanks for your help. I found that issue: https://github.com/MinecraftForge/MinecraftForge/issues/8498
    • i'm trying to have my friend join my modded server. I gave them all the mods i have installed and the 'mixmatched mod list' keeps poping up.
  • Topics

×
×
  • Create New...

Important Information

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