Skip to content

Commit

Permalink
Add writeCustomData() overload (GregTechCEu#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude authored Oct 9, 2024
1 parent 586828f commit 2ad39ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
public interface ISyncedTileEntity {

Consumer<PacketBuffer> NO_OP = buf -> {};

/**
* Used to sync data from Server -> Client.
* Called during initial loading of the chunk or when many blocks change at once.
Expand Down Expand Up @@ -68,6 +70,27 @@ public interface ISyncedTileEntity {
*/
void writeCustomData(int discriminator, @NotNull Consumer<@NotNull PacketBuffer> dataWriter);

/**
* Used to send an empty anonymous Server -> Client packet.
* <p>
* Data is received in {@link #receiveCustomData(int, PacketBuffer)};
* <p>
* Typically used to signal to the client that a rendering update is needed
* when sending a server-side state update.
* <p>
* <em>Should be called manually</em>.
* <p>
* This method is called <strong>Server-Side</strong>.
* <p>
* Equivalent to {@link net.minecraft.tileentity.TileEntity#getUpdatePacket}
*
* @param discriminator the discriminator determining the packet sent.
* @see gregtech.api.capability.GregtechDataCodes
*/
default void writeCustomData(int discriminator) {
writeCustomData(discriminator, NO_OP);
}

/**
* Used to receive an anonymous Server -> Client packet.
* Called when receiving a packet for the location this TileEntity is currently in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void createFakeGui() {
this.guiContainerCache = fakeModularUIContainer;
if (getWorld().isRemote)
this.guiCache = new FakeModularGui(ui, fakeModularUIContainer);
this.writeCustomData(CREATE_FAKE_UI, buffer -> {});
this.writeCustomData(CREATE_FAKE_UI);
} catch (Exception e) {
GTLog.logger.error(e);
}
Expand Down

0 comments on commit 2ad39ab

Please sign in to comment.