Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey guys, do you know how is the best way to store values from the tile entity in a block / itemstack, so they can be re-add when the block is placed again?

  • Author

Well, currently I'm using that, but the player can still get the block when it is broke in creative. How can I check if it is creative or not?

 

I mean, is there any problem by using !Minecraft.getMinecraft().thePlayer.capabilities.isCreativeMode in the breakBlock(World worldIn, BlockPos pos, IBlockState state) method?

  • Author

In order to get the tile entity (!= null), I'm using the breakBlock(), instead of dropBlockAsItemWithChance(), or harvestBlock(), both return a null tile entity.

 

So, I'm setting the tag in an itemstack and spawning it before the super.breakBlock(). When I do this, it will spawn an extra block, so I need to override the getItemDropped() to null. However, when I do that, it will always drop an item, even in creative.

  • Author

Nice. But I still have a problem. When I destroy the tile entity in survival, it is not completely destroyed, I can still collide with it, and when I right click it, the block returns. Am I doing something wrong?

 

 

 

@Override

public Item getItemDropped(IBlockState state, Random rand, int fortune)

{

return null;

}

 

@Override

public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest)

{

if (willHarvest)

return true;

return super.removedByPlayer(world, pos, player, willHarvest);

}

 

@Override

public void harvestBlock(World world, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te)

{

super.harvestBlock(world, player, pos, state, te);

world.setBlockToAir(pos);

}

 

@Override

public List<ItemStack> getDrops(IBlockAccess worldIn, BlockPos pos, IBlockState state, int fortune)

{

List<ItemStack> drops = super.getDrops(worldIn, pos, state, fortune);

 

TileEntity tileEntity = worldIn.getTileEntity(pos);

if (tileEntity instanceof MyTile)

{

MyTile myTile= (MyTile) tileEntity;

drops.add(this.getThisBlockWithTag(myTile, pos));

for (ItemStack itemStack : myTile.getInventory())

drops.add(itemStack);

}

return drops;

}

 

private ItemStack getThisBlockWithTag(MyTile myTile, BlockPos pos)

{

ItemStack stack = new ItemStack(BlockRegistry.myBlock);

if (myTile != null)

{

NBTTagCompound compound = new NBTTagCompound();

compound.setByte("var1", (byte) myTile.getVar1());

 

[...]

 

stack.setTagCompound(compound);

}

return stack;

}

 

 

 

 

  • Author

Thanks, that makes sense and I would not notice that, haha.

 

Well, now it's working right. I was using debug, so I've closed mc and tried again. Weird

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.