Skip to content

Commit

Permalink
Ensure Crystal Cube block entity updates are persisted (#4549)
Browse files Browse the repository at this point in the history
- fixes #4546 by flagging the containing chunk as containing unsaved
changes
- replaced all manually dispatched client updates in
`CorporeaCrystalCubeBlockEntity` with the vanilla way to send them
  • Loading branch information
TheRealWormbo authored Jan 15, 2024
1 parent 18f46f4 commit e486af6
Showing 1 changed file with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;

import org.jetbrains.annotations.Nullable;
Expand All @@ -31,7 +32,6 @@
import vazkii.botania.api.corporea.CorporeaRequestMatcher;
import vazkii.botania.api.corporea.CorporeaRequestor;
import vazkii.botania.api.corporea.CorporeaSpark;
import vazkii.botania.api.internal.VanillaPacketDispatcher;
import vazkii.botania.client.core.helper.RenderHelper;
import vazkii.botania.common.block.block_entity.BotaniaBlockEntities;

Expand Down Expand Up @@ -62,10 +62,8 @@ public static void serverTick(Level level, BlockPos pos, BlockState state, Corpo
public void setRequestTarget(ItemStack stack) {
if (!stack.isEmpty() && !locked) {
requestTarget = stack.copyWithCount(1);
setChanged();
updateCount();
if (!level.isClientSide) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}
}

}
Expand Down Expand Up @@ -113,12 +111,8 @@ private void setCount(int count) {
int oldCount = this.itemCount;
this.itemCount = count;
if (this.itemCount != oldCount) {
int oldCompValue = this.compValue;
this.compValue = CorporeaHelper.instance().signalStrengthForRequestSize(itemCount);
if (this.compValue != oldCompValue && this.level != null) {
this.level.updateNeighbourForOutputSignal(this.worldPosition, getBlockState().getBlock());
}
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
setChanged();
}
}

Expand Down Expand Up @@ -173,14 +167,20 @@ public void doCorporeaRequest(CorporeaRequestMatcher request, int count, Corpore
public boolean onUsedByWand(@Nullable Player player, ItemStack stack, Direction side) {
if (player == null || player.isShiftKeyDown()) {
this.locked = !this.locked;
if (!level.isClientSide) {
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
}
setChanged();
return true;
}
return false;
}

@Override
public void setChanged() {
super.setChanged();
if (level != null) {
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
}

public static class Hud {
public static void render(GuiGraphics gui, CorporeaCrystalCubeBlockEntity cube) {
PoseStack ps = gui.pose();
Expand Down

0 comments on commit e486af6

Please sign in to comment.