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!

 

For a section of my mod that I am working on at the moment, I need to be able to apply tile entities to a block upon clicking with an item. However, in the onItemUse function, whenever I try to call world.setBlockTileEntity(x, y, z, TileEntityBlockCover) it claims that the final variable is undefined, and I do not know what/how it should be defined as it is a tile entity.

 

Also, if it is useful, I aim to be able to click on any block with this item, and if the block I click on does not already have a TE, I want my TE applied to it to render/use NBT/ do whatever.

 

Thanks in advance!

Luis  :D

I'm not sure about this but don't u have to add .class to TileEntityBlockCover?

 

Like this:

 

world.setBlockTileEntity(x, y, z, TileEntityBlockCover.class)

 

The method takes a tile entity object, not the class itself. Meaning, you need to instatiate (create) a new object of your tile entity. Like this:

 

world.setBlockTileEntity(x, y, z, new TileEntityBlockCover(parameters));

 

Replace parameters with whatever your TileEntityBlockCover's constructor's parameters are.

  • Author

I have made a block with a tileentity, etc. I will upload my code for u to see as soon as I can.

Thanks but I know how tile entities on blocks work. What I am trying to achieve here is when an item is used on any block, vanilla or modded, it creates my TileEntityBlockCover which I can later use in rendering...

 

Thanks anyway!

 


 

The method takes a tile entity object, not the class itself. Meaning, you need to instatiate (create) a new object of your tile entity. Like this:

 

world.setBlockTileEntity(x, y, z, new TileEntityBlockCover(parameters));

 

Replace parameters with whatever your TileEntityBlockCover's constructor's parameters are.

 

Thanks! I will try this tomorrow and see if it does what I need :P

  • Author

The method takes a tile entity object, not the class itself. Meaning, you need to instatiate (create) a new object of your tile entity. Like this:

 

world.setBlockTileEntity(x, y, z, new TileEntityBlockCover(parameters));

 

Replace parameters with whatever your TileEntityBlockCover's constructor's parameters are.

 

I tried this method, but the TE gets removed from the world after a tick, when I want it to stay. I am unsure if this is a problem with the fact this TE is not assigned to any block, and that I just want it placed upon an item clicking on a block.

 

Also, using some System.out.println I know that the TE is being placed, just not staying in the world at all...

The method takes a tile entity object, not the class itself. Meaning, you need to instatiate (create) a new object of your tile entity. Like this:

 

world.setBlockTileEntity(x, y, z, new TileEntityBlockCover(parameters));

 

Replace parameters with whatever your TileEntityBlockCover's constructor's parameters are.

 

I tried this method, but the TE gets removed from the world after a tick, when I want it to stay. I am unsure if this is a problem with the fact this TE is not assigned to any block, and that I just want it placed upon an item clicking on a block.

 

Also, using some System.out.println I know that the TE is being placed, just not staying in the world at all...

You shouldn't need to be doing that. Instead, set the block to BlockCover and watch as the TE is created automatically.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

  • Author

The method takes a tile entity object, not the class itself. Meaning, you need to instatiate (create) a new object of your tile entity. Like this:

 

world.setBlockTileEntity(x, y, z, new TileEntityBlockCover(parameters));

 

Replace parameters with whatever your TileEntityBlockCover's constructor's parameters are.

 

I tried this method, but the TE gets removed from the world after a tick, when I want it to stay. I am unsure if this is a problem with the fact this TE is not assigned to any block, and that I just want it placed upon an item clicking on a block.

 

Also, using some System.out.println I know that the TE is being placed, just not staying in the world at all...

You shouldn't need to be doing that. Instead, set the block to BlockCover and watch as the TE is created automatically.

 

I want the block to stay as its original block, and keep all its old features, just look different. Essentially an item that changes the look of any block it is clicked on...

The method takes a tile entity object, not the class itself. Meaning, you need to instatiate (create) a new object of your tile entity. Like this:

 

world.setBlockTileEntity(x, y, z, new TileEntityBlockCover(parameters));

 

Replace parameters with whatever your TileEntityBlockCover's constructor's parameters are.

 

I tried this method, but the TE gets removed from the world after a tick, when I want it to stay. I am unsure if this is a problem with the fact this TE is not assigned to any block, and that I just want it placed upon an item clicking on a block.

 

Also, using some System.out.println I know that the TE is being placed, just not staying in the world at all...

You shouldn't need to be doing that. Instead, set the block to BlockCover and watch as the TE is created automatically.

 

I want the block to stay as its original block, and keep all its old features, just look different. Essentially an item that changes the look of any block it is clicked on...

You can't do that without modifying the block. Which means you'd have to modify every block. Just create your own block/TE, put the ID/metadata in an NBT tag, and redefine all the block functions to emulate whichever block. (like return Block.blocksList[((myTE) w.getTileEntity(x,y,z)).theID].whateverFunction(...). Unfortunately most functions will then not work because the coords are not passed in and you can't access your TE without coords.)

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

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.