Jump to content

Recommended Posts

Posted

Hello, so i've been trying to create a custom chair that i can sit on, after many attempts I created it but there seems to be an issue when I try to sit on it. Whenever i right click the chair, it teleports me into it and then pushes me out and nothing happens afterwards. However if I log off and log back in I find myself sitting on the chair.

 

Here's the code for the chair block

 

public class Phoerite_Chair extends Block {

 

public static PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

 

public Phoerite_Chair(Material materialIn) {

super(materialIn);

this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));

super.setBlockBounds( 0.0F, 0F, 0.0F, 1.0F, 1.35F, 1.0F);

}

 

@Override

public boolean isOpaqueCube() {

return false;

}

 

@Override

public EnumWorldBlockLayer getBlockLayer() {

return EnumWorldBlockLayer.CUTOUT;

}

 

@Override

public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer,

ItemStack stack) {

 

        if (!worldIn.isRemote)

        {

worldIn.spawnEntityInWorld(new EntityArrow(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D));

        }

super.onBlockPlacedBy(worldIn, pos, state, placer, stack);

}

@Override

public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,EnumFacing side, float hitX, float hitY, float hitZ) {

 

if (!worldIn.isRemote)

{

playerIn.mountEntity(new EntityArrow(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D));

}

return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);

}

 

@Override

public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {

        Entity entity;

        entity = new EntityArrow(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D);

        if (!worldIn.isRemote)

        {

        entity.setDead();

        }

super.onBlockDestroyedByPlayer(worldIn, pos, state);

}

 

@Override

public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {

IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);

return state.withProperty(FACING, placer.getHorizontalFacing());

}

 

   

    @Override

    public int getMetaFromState(IBlockState state) {

   

    return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();

    }

   

    @Override

    public IBlockState getStateFromMeta(int meta) {

   

    return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));

    }

   

    @Override

    protected BlockState createBlockState() {

    return new BlockState(this, new IProperty[] {FACING});

    }

}

 

 

Posted

First of all, you need a custom entity as it needs to have a hitbox of size 0 to not be pushed out of the block. Secondly, you are spawning a NEW entity every time you want to interact with it. This means that you are creating more and more entities but never actually removing them. Instead you need to create a TileEntity and store the entity's UUID in it and retrieve the from the world with the help of that UUID every time you need to interact with the entity.

Posted

Entities have a UUID field.

Get it.

Save it into a field of your TE.

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

Thanks again! But there still seems to be an issue... None of the interractions with the entity work.

Here is the current chair block code :

public class Phoerite_Chair extends Block {

public static PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

public Phoerite_Chair(Material materialIn) {
	super(materialIn);
	this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
	super.setBlockBounds( 0.0F, 0F, 0.0F, 1.0F, 1.35F, 1.0F);
}

@Override
public boolean isOpaqueCube() {
	return false;
}

@Override
public EnumWorldBlockLayer getBlockLayer() {
	return EnumWorldBlockLayer.CUTOUT;
}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
        if (!worldIn.isRemote)
        {
        WorldServer worldserver = (WorldServer) worldIn;	
	worldIn.spawnEntityInWorld(worldserver.getEntityFromUuid(TileEntityChair.ChairUUID));
        }

	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,EnumFacing side, float hitX, float hitY, float hitZ) {

	if (!worldIn.isRemote)
	{
		WorldServer worldserver = (WorldServer) worldIn;
		playerIn.mountEntity(worldserver.getEntityFromUuid(TileEntityChair.ChairUUID));
	}
		return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
}

@Override
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {

        if (!worldIn.isRemote)
        {
        	WorldServer worldserver = (WorldServer) worldIn;
        	worldserver.getEntityFromUuid(TileEntityChair.ChairUUID).setDead();
        }
	super.onBlockDestroyedByPlayer(worldIn, pos, state);
}

@Override
public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
	IBlockState state = super.onBlockPlaced(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer);
	return state.withProperty(FACING, placer.getHorizontalFacing());
}

    @Override
    public int getMetaFromState(IBlockState state) {
    	
    	return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
    }
    
    @Override
    public IBlockState getStateFromMeta(int meta) {
    	
    	return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta));
    }
    
    @Override
    protected BlockState createBlockState() {
    	return new BlockState(this, new IProperty[] {FACING});
    }
}

Posted

I'm setting the UUID Field inside the TE, It is now no longer static but it seems like there is still the same issue, so i'm guessing i'm doing something wrong with setting the UUID field.

 

Here is one of the interractions with the entity :

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
        if (!worldIn.isRemote)
        {
        TileEntityChair id = new TileEntityChair();
        WorldServer worldserver = (WorldServer) worldIn;
	worldIn.spawnEntityInWorld(worldserver.getEntityFromUuid(id.ChairUUID));
        }

	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}

 

And this is the TE :

public class TileEntityChair extends TileEntity {

public UUID ChairUUID;

public void TileEntityChairID(UUID id)
    {
        id = new EntityChair(worldObj).getPersistentID();
        ChairUUID = id;
       
    }

}

Posted

Why the hell do you create a new

TileEntity

and a new

Entity

? Get the existing ones from the world.

 

Also:

You can cache this value in your TE in a field, too, if you want, but you'll have to use a

WeakReference

to avoid memory leaks.

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/

Posted

world.getTileEntity for one....

You were told already how to do the other...

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

Okay, this is embarassing but it still doesn't work  ._.

 

Here's the TE:

public class TileEntityChair extends TileEntity {

public UUID ChairUUID;

public void TileEntityChairID(UUID uuid, World world, int id)
    {
	EntityChair entity = (EntityChair) world.getEntityByID(id);
        uuid = entity.getPersistentID();
        ChairUUID = uuid;
    }

And here's one of the interractions :

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
        if (!worldIn.isRemote)
        {
        TileEntityChair id = (TileEntityChair) worldIn.getTileEntity(pos);
        WorldServer worldserver = (WorldServer) worldIn;
	worldIn.spawnEntityInWorld(worldserver.getEntityFromUuid(id.ChairUUID));
        }

	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}

Posted

You need to create the entity when the block is placed, save its uuid to the tile entity by getting that from the world and retrieve the entity with the uuid from the world when a player sits down or when you need to kill the entity when the block is destroyed.

Posted

u_u

 

Interractions:

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
        if (!worldIn.isRemote)
        {
        Entity entity = new EntityChair(worldIn, (double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D);
	worldIn.spawnEntityInWorld(entity);
        }

	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,EnumFacing side, float hitX, float hitY, float hitZ) {
	if (!worldIn.isRemote)
	{
		TileEntityChair id = (TileEntityChair) worldIn.getTileEntity(pos);
		WorldServer worldserver = (WorldServer) worldIn;
		playerIn.mountEntity(worldserver.getEntityFromUuid(id.ChairUUID));
	}
		return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY, hitZ);
}

@Override
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state) {

        if (!worldIn.isRemote)
        {
        	TileEntityChair id = (TileEntityChair) worldIn.getTileEntity(pos);
        	WorldServer worldserver = (WorldServer) worldIn;
        	worldserver.getEntityFromUuid(id.ChairUUID).setDead();
        }
	super.onBlockDestroyedByPlayer(worldIn, pos, state);
}

 

TE:

public class TileEntityChair extends TileEntity {

public UUID ChairUUID;

public void TileEntityChairID(UUID uuid, World world, int id)
    {
	EntityChair entity = (EntityChair) world.getEntityByID(id);
        uuid = entity.getPersistentID();
        ChairUUID = uuid;
    }

}

Posted

After you spawned the entity, you need to put its uuid into the tile entity. And why the hell do you have that uuid stuff in the constructor?

Posted

Your TE's constructor must take 0 parameters or it will be unable to be recreated when the game is loaded from disk.

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.

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

    • I am trying to make a mod, all it is, a config folder that tells another mod to not require a dependency, pretty simple right.. well, I dont want whoever downloads my mod to have to download 4 other mods and then decide if they want 2 more that they kinda really need.. i want to make my mod basically implement all of these mods, i really dont care how it does it, ive tried putting them in every file location you can think of, ive downloaded intellij, mcreator, and tried vmware but thats eh (had it from school). I downloaded them in hopes theyd create the correct file i needed but honestly im only more lost now. I have gotten my config file to work, if i put all these mods into my own mods folder and the config file into the config and it works (unvbelievably) but i want to share this to everyone else, lets just say this mod will legitimately get 7M downloads.  I tried putting them in a run folder then having it create all the contents in that for a game (mods,config..etc) then i drop the mods in and all the sudden i cant even open the game, like it literally works with my own world i play on, but i cant get it to work on any coding platform, they all have like built in java versions you cant switch, its a nightmare. I am on 1.20.1 I need Java 17 (i dont think the specific versions of 17 matter) I have even tried recreating the mods i want to implement and deleting import things like net.adamsandler.themodsname and replacing it with what mine is. that only creates other problems, where im at right now is i got the thing to start opening then it crashes, closest ive gotten it, then it just says this  exception in thread "main" cpw.mods.niofs.union.unionfilesystem$uncheckedioexception: java.util.zip.zipexception: zip end header not found caused by: java.util.zip.zipexception: zip end header not found basically saying theres something wrong with my java.exe file, so i tried downloading so many different versions of java and putting them all in so many different spots, nothing, someone online says its just a mod that isnt built right so i put the mod into an editor and bunch of errors came up, id post it but i deleted it on accident, i just need help integrating mods
    • Vanilla 1.16.5 Crash Report [#L2KYKaK] - mclo.gs  
    • Hello, probably the last update, if anyone has the same problem or this can be of any help, the answer was pretty simple, textures started rendering just using a Tesselator instead of a VertexConsumer given by a MultibufferSource and a RenderType, pretty simple
    • Finally circling back to this, and I think all of us were half right.  getChunk() does appear to immediately load the chunk, but what changed between 1.16 and 1.18 is that the list of entities is now stored in the server, not per chunk.  So while it was possible to load a chunk in 1.16 and immediately grab an entity out of it, 1.18 loads the chunk and submits a request to load its entities on the next tick (if I understand correctly).  All this to say, you can immediately access the chunk itself, however you have to wait an additional tick for its entities to load in. In my case what this means is that I do have to set up an interface to wait an additional tick before submitting the request to retrieve the entity.  However, other functions do appear to be available immediately.  Just depends on what you're trying to do. Thank you all for the help! 
    • I've already tried it without mods and it works.
  • Topics

×
×
  • Create New...

Important Information

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