Jump to content

[1.8.9] Sitting On Custom Chair Issue.


Phonixe

Recommended Posts

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

    }

}

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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.

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

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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