Skip to content

Commit

Permalink
Better Pairing & Overcapacity Checks
Browse files Browse the repository at this point in the history
Pairing of jars always results into a new network, regardless of existing connections either jar had.

Networks in overcapacity will simply disconnect jars past the last valid connection rather than all its jars.
  • Loading branch information
DrParadox7 committed Jun 21, 2024
1 parent fb5bf61 commit 575c603
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,17 @@ private static class JarNetwork {
private void update() {
long time = MinecraftServer.getServer().getEntityWorld().getTotalWorldTime();
if (time > this.lastTime) {
int networkSize = this.jars.size();

// Not enough jars...
if (this.jars.size() < 2) return;
// Too many jars...
if (networkSize > 2) {
jars.subList(2, jars.size()).clear();
}

// Just enough jars...
if (this.jars.size() == 2) {
if (hasProcessedJars()) this.lastTime = time + 3;
return;
if (networkSize == 2 && hasProcessedJars()) {
this.lastTime = time + 3;
}

// Too many jars. Refreshing network...
this.jars.clear();
}
}

Expand Down Expand Up @@ -152,6 +151,24 @@ private static JarNetwork getNetwork(UUID id) {
return network;
}

public void disconnectJar(TileRemoteJar jar) {
UUID id = jar.networkId;

if (id != null) {
JarNetwork network = TileRemoteJar.networks.get(id);

if (network != null) {
if (network.jars.size() < 2) {
// Network consists of only this Jar. Discarding Network instead
networks.remove(id);
}

// Discarding Jar from Network
network.jars.remove(jar);
}
}
}

public void markForUpdate() {
this.markDirty();
this.getWorldObj().markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
Expand Down
32 changes: 10 additions & 22 deletions src/main/java/makeo/gadomancy/common/items/ItemBlockRemoteJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,20 @@ public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world,
float hitX, float hitY, float hitZ) {
TileRemoteJar tile = BlockRemoteJar.getJarTile(world, x, y, z);
if (stack.stackSize == 1 && tile != null) {
if (!world.isRemote) {
if (!world.isRemote && !player.isSneaking()) {
NBTTagCompound compound = NBTHelper.getData(stack);
if (!player.isSneaking()) {
UUID networkId = null;
if (tile.networkId == null) {
player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.new"));
networkId = UUID.randomUUID();
tile.networkId = networkId;
tile.markForUpdate();
} else {
UUID current = NBTHelper.getUUID(compound, "networkId");
if (current == null || !current.equals(tile.networkId)) {
player.addChatComponentMessage(
new ChatComponentTranslation("gadomancy.info.RemoteJar.connected"));
networkId = tile.networkId;
}
}
UUID networkId = UUID.randomUUID();

player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.RemoteJar.new"));
NBTHelper.setUUID(compound, "networkId", networkId);

tile.disconnectJar(tile);
tile.networkId = networkId;
tile.markForUpdate();

if (networkId != null) {
NBTHelper.setUUID(compound, "networkId", networkId);
}
}
return true;
} else {
return player.isSneaking();
}
return player.isSneaking();
}
return false;
}
Expand Down

0 comments on commit 575c603

Please sign in to comment.