Skip to content

Commit 15faa84

Browse files
committed
fix: send side configuration with initial chunk data
1 parent 4894377 commit 15faa84

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ tasks.withType<ProcessResources> {
220220

221221
tasks.withType<JavaCompile> {
222222
options.encoding = "UTF-8"
223-
options.release.set(17)
223+
options.release.set(21)
224224
}
225225

226226
tasks.withType<Jar> {

src/main/java/dev/galacticraft/machinelib/api/block/entity/BaseBlockEntity.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
2727
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory;
2828
import net.minecraft.core.BlockPos;
29-
import net.minecraft.core.HolderLookup;
30-
import net.minecraft.nbt.CompoundTag;
3129
import net.minecraft.network.chat.Component;
3230
import net.minecraft.network.protocol.Packet;
3331
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
@@ -83,12 +81,6 @@ public BlockPos getScreenOpeningData(ServerPlayer player) {
8381
return this.getBlockPos();
8482
}
8583

86-
// we override the update packet to circumvent nbt serialization
87-
@Override
88-
public final @NotNull CompoundTag getUpdateTag(HolderLookup.Provider registryLookup) {
89-
return new CompoundTag();
90-
}
91-
9284
@Override
9385
public final @Nullable Packet<ClientGamePacketListener> getUpdatePacket() {
9486
CustomPacketPayload payload = this.createUpdatePayload();
@@ -130,8 +122,8 @@ protected void broadcastToPlayers(CustomPacketPayload payload) {
130122
/**
131123
* Marks the block entity for re-rendering.
132124
*/
133-
public void markForRerender() {
134-
if (this.level != null) {
125+
public void requestRerender() {
126+
if (this.level != null && this.level.isClientSide) {
135127
this.level.sendBlockUpdated(this.worldPosition, this.getBlockState(), this.getBlockState(), 0);
136128
}
137129
}

src/main/java/dev/galacticraft/machinelib/api/block/entity/ConfiguredBlockEntity.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ public void loadAdditional(CompoundTag tag, HolderLookup.Provider lookup) {
278278
return this.configuration;
279279
}
280280

281+
@Override
282+
public @NotNull CompoundTag getUpdateTag(HolderLookup.Provider registryLookup) {
283+
CompoundTag tag = super.getUpdateTag(registryLookup);
284+
tag.put(Constant.Nbt.CONFIGURATION, this.configuration.createTag());
285+
return tag;
286+
}
287+
281288
@Override
282289
public @NotNull CustomPacketPayload createUpdatePayload() {
283290
return new BaseMachineUpdatePayload(this.worldPosition, this.configuration);
@@ -351,9 +358,8 @@ public void setOption(@NotNull ResourceType type, @NotNull ResourceFlow flow) {
351358
this.flow = flow;
352359

353360
ConfiguredBlockEntity.this.setChanged();
354-
if (ConfiguredBlockEntity.this.level.isClientSide) {
355-
ConfiguredBlockEntity.this.markForRerender();
356-
} else {
361+
ConfiguredBlockEntity.this.requestRerender();
362+
if (ConfiguredBlockEntity.this.level != null && !ConfiguredBlockEntity.this.level.isClientSide) {
357363
ConfiguredBlockEntity.this.broadcastToPlayers(new SideConfigurationUpdatePayload(ConfiguredBlockEntity.this.worldPosition, this.face, type, flow));
358364
}
359365
}

src/main/java/dev/galacticraft/machinelib/impl/network/s2c/BaseMachineUpdatePayload.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void apply(ClientPlayNetworking.Context context) {
5353
if (level != null && level.getBlockEntity(pos) instanceof MachineBlockEntity machine) {
5454
this.config.copyInto(machine.getIOConfig());
5555
machine.setChanged();
56-
machine.markForRerender();
56+
machine.requestRerender();
5757
}
5858
}
5959
}

0 commit comments

Comments
 (0)