Jump to content

Recommended Posts

Posted (edited)

So I'm attempting to create a chess game in java that uses tileentities for each piece. I have one block that you place and when you right click it, it creates the board and chess pieces. However, I cannot find out how to bring the chess pieces I made into the world. I know you do worldln.setBlockState() but I can't find out how to access the block i created and set its properties as a tile entity. Any help would be appreciated. Also from a design perspective, one person told me to use the master slave pattern and have my block that creates the board hold all the blocks, but I don't know how to communicate a block back to the original board creator block. Thank you!

 

Edit: If anyone could give any advice on this it would be extremely helpful. Thank you!!!

Edited by sun-toast
Posted

urblock.getStateForPlacement or getDefualtState (you can still mess around with it) , and in your block class override hasTileEntity and return an instance of your custom te in createTileEntity.

You can save the position of the master, and use world.getTileEntity to get the master te.

Posted (edited)

This is nostalgic... Reminded me of that time back in middle school where we were asked to make a chess game in Java as a class assignment.

 

Back on topic. If you really want to reference the chess controller from every single chess piece, then I guess you could make a tile entity for each of them (or even make the chess pieces into entities, which is something I would do since you can create the animation of chess pieces sliding across the board). From that point on, just send all interactions on the chess pieces to the chess controller and let it handle the logic. Note that the chess piece should only store the BlockPos of the chess controller, and fetch the actual tile entity of it when it is actually needed.

 

On a side note, I think that with the new way block properties are handled after the flattening, it is possible to store the chess controller's BlockPos as a property instead of creating a tile entity for it. Not sure if that is a good idea from the design perspective though.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted (edited)

Howdy

Quote

However, I cannot find out how to bring the chess pieces I made into the world. I know you do worldln.setBlockState() but I can't find out how to access the block i created and set its properties as a tile entity.

Your chess piece is a block with tileEntity?

Your master knows the location of each chess piece, so the basic algorithm is

1) Master places the chess piece at [x,y,z] using setBlockState

2) Master then retrieves the tileentity at [x,y,z] by asking the world for it (world.getTileEntity()) and casting it to the known entity type

3) Master sets the tileentity properties (I imagine - telling each slave what type of piece it is, as well as the [x,y,z] of the master) by calling the appropriate method in the tileentity.

 

Vanilla uses late initialisation for TileEntities anyway via read (from NBT) so constructing an empty TileEntity isn't a problem

 

-TGG

 

 

 

Edited by TheGreyGhost
Posted
3 hours ago, DavidM said:

On a side note, I think that with the new way block properties are handled after the flattening, it is possible to store the chess controller's BlockPos as a property instead of creating a tile entity for it. Not sure if that is a good idea from the design perspective though.

BTW block properties don't work like that; each block still has a blockstate for every possible combination of the properties that you attach to it, it just assigns a unique integer to each blockstate combination behind the scenes.

 

So for example - a block with a FACING (four directions), a POWERED (on or off), and a SPEED (slow, medium, fast, ludicrous) would have 4*2*4 = 32 different combinations.  If you tried to store a BlockPos it would try to make X * Y * Z combinations i.e. 2^32 * 256 * 2^32. 

 

But you could for sure make each space on the chess board into a chess piece using blockstates (no tileentities) and have the master control the blockstate at each chess board location.  If you don't need animated figures then that's quite a bit simpler than using TileEntity and TileEntityRenderer

 

 

  • Like 1

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



×
×
  • Create New...

Important Information

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