Jump to content

Recommended Posts

Posted

Block:

public boolean onBlockEventReceived(World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam)
{
super.onBlockEventReceived(worldIn, pos, state, eventID, eventParam);
TileEntity tileentity = worldIn.getTileEntity(pos);
return tileentity == null ? false : tileentity.receiveClientEvent(eventID, eventParam);
}

TileEntity (example is from chest)

public boolean receiveClientEvent(int id, int type)
{
if (id == 1)
{
	this.numPlayersUsing = type;
	return true;
}
else
{
	return super.receiveClientEvent(id, type);
}
}

 

So there is this thing, used in few vanilla classes. Now, I tried to utilize it somehow, but didn't get far.

onBlockEventReceived is never called, no matter what I do, same goes (obviously) for receiveClientEvent.

Logically - they don't get called because there is no event for them to call.

How to add event to block for those methods to use, I can't find any vanilla declaration.

 

Also - how exacly does it work?

Is it like: client performs some action with id and value and sends action to server or other way around, thet you can update client int values using those methods?

 

This might be useful for e.g Buttons in my GuiContainer and/or sending changing values - depending on what does it do (the question above).

 

Thanks.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Nice, thanks.

 

Would you please validate my knowledge:

 

getDescriptionPacket() and onDataPacket(...) are called initially when client loads tileEntity, only once.

1. When else is it being called and can I force it?

 

receiveClientEvent() can be used to transport any integer to block/tileEntity.

2. Can/should it be called anywhere at any time? 3. I am guessing packet goes to everyone who loaded given BlockPos?

 

4. For any other synchronization I implement my own packet which will send x/y/z and data, or is there some other way I don't know about?

 

5. What exacly markDirty does? Tells Minecraft that chunk changed - what next? Is it "chunk changed, save it to disk" (still not sure)?

 

6. Should I know anything else regarding tileEntities (it's nice to know as much as possible)?

 

Thanks :D

1.7.10 is no longer supported by forge, you are on your own.

Posted

Next part of MC in my head.

 

As I was diggin into code I actually hit this part:

- TEs are recreated when metadata changes unless you override shouldRefresh in the TE

 

I did some debugging:

- Printing worldObj.loadedTileEntityList and worldObj.tickableTileEntities sizes()

- Checking vanilla/breakpoints

- Printing when TE's constructor is called.

 

Results:

1. When shouldRefresh returns true both client and server will construct new TE - yet, that TE will NEVER be added to world's TE lists and will actually be discarded. I belive it is simply making sure that if in this pos there was no TE it would be set (but is not, since there is "old" TE), correct?

2. Sometimes Client constructs 2 TE for one server TE. Probably some synchronization stuff?

3. When shouldRefresh returns false - server STILL constructs new TE, only client doesn't.

 

Now what I want to know is to understand what the author of shouldRefresh docs had in mind saying:

/**
     * Called from Chunk.setBlockIDWithMetadata, determines if this tile entity should be re-created when the ID, or Metadata changes.
     * Use with caution as this will leave straggler TileEntities, or create conflicts with other TileEntities if not used properly.
     *
     * @param world Current world
     * @param pos Tile's world position
     * @param oldID The old ID of the block
     * @param newID The new ID of the block (May be the same)
     * @return True to remove the old tile entity, false to keep it in tact {and create a new one if the new values specify to}
     */

 

"if this tile entity should be re-created" - it doesn't seem to be recreated in any situation :C - when exacly that happens? "old" TE is never replaced by new one (new one is constructed), so what is "recreation" in this case?

 

"this will leave straggler TileEntities" - when?

 

"True to remove the old tile entity, false to keep it in tact" "create a new one if the new values specify to" - what?

 

EDIT

Indeed - when that will return false - server's TE is removed, client's one stays!

Where exacly is "danger" is bad usage of  this method? What can happen (aside client synchronization problems)?

 

Thanks :D

1.7.10 is no longer supported by forge, you are on your own.

Posted

While I'm not sure exactly what the documentation is implying, I override shouldRefresh to return false for ALL of my TileEntities so that they behave identically to vanilla - if you look at the base implementation, NO vanilla TE will ever return true.

 

It's a mystery why the default behavior for modded TEs is opposite that of vanilla (per diesieben: "SOMETHING had to be chosen for the default..."), but I know people have run into unexpected issues because of it: their TE data suddenly disappearing after setting a state property, for example, so clearly the server side must also be getting refreshed, though your experiment seems to suggest otherwise.

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 all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

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