Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.Constants;

import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -57,7 +58,25 @@ public void addPacketsFrom(SyncedTileEntityBase syncedTileEntityBase) {
private void notifyWorld() {
@SuppressWarnings("deprecation")
IBlockState blockState = getBlockType().getStateFromMeta(getBlockMetadata());
world.notifyBlockUpdate(getPos(), blockState, blockState, 0);
if (canNotifyWorld()) {
world.notifyBlockUpdate(getPos(), blockState, blockState, 0);
}
}

private boolean canNotifyWorld() {
// short circuit with packet size to avoid too many hash lookups and instanceof casts
if (updates.size() > 10 && getWorld() instanceof WorldServer server) {
int x = getPos().getX() >> 4;
int z = getPos().getZ() >> 4;
if (server.getPlayerChunkMap().contains(x, z)) {
return true;
} else {
// cannot send, so clear
updates.clear();
return false;
}
}
return false;
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/gregtech/api/network/PacketDataList.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

/**
* An optimised data structure backed by two arrays.
* This is essentially equivalent to <code>List<Pair<Integer, byte[]>></code>, but more efficient.
Expand Down Expand Up @@ -84,9 +86,8 @@ public boolean isEmpty() {
* remove all data packets
*/
public void clear() {
for (int i = 0; i < this.size; i++) {
this.data[i] = null;
}
Arrays.fill(this.discriminators, 0);
Arrays.fill(this.data, null);
this.size = 0;
}

Expand Down
Loading