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

    • DAFTAR & LOGIN BIGO4D Bigo4D adalah situs togel online yang menjadi pilihan banyak pemain di Indonesia. Dengan berbagai keunggulan yang dimilikinya, Bigo4D mampu menjadi situs togel terbesar di pasaran saat ini. Dalam artikel ini, kami akan membahas secara lengkap tentang Bigo4d dan alasan-alasannya menjadi situs togel favorit banyak pemain.
    • Slot Gacor >> Mudah Maxwin Bersama Djarum4D   Slot gacor adalah salah satu jenis permainan judi online yang sangat populer di Indonesia. Bermain slot gacor berarti bermain permainan slot dengan kemungkinan keluaran yang lebih tinggi daripada slot tradisional. Dalam artikel ini, kami akan membahas secara lengkap tentang slot gacor, mulai dari pengertian dasar, cara bermain, strategi pemain, serta aspek keamanan dan etika dalam bermain.
    • DAFTAR & LOGIN TAYO4D   Slot gacor online adalah permainan yang menarik dan menghasilkan keuntungan untuk banyak pemain di seluruh dunia. Dalam artikel ini, kita akan membahas tentang cara memilih dan memainkan slot gacor online terbaik.
    • Tayo4D : Bandar Online Togel Dan Slot Terbesar Di Indonesia     Pemain taruhan Tayo4D yang berkualitas memerlukan platform yang aman, terpercaya, dan mudah digunakan. Dalam era teknologi ini, banyak situs online yang menawarkan layanan taruhan togel 4D, tetapi memilih yang tepat menjadi tuntas. Berikut adalah cara untuk membuat artikel yang membahas tentang situs online terpercaya untuk permainan taruhan togel 4D.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
  • Topics

×
×
  • Create New...

Important Information

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