Skip to content

Commit

Permalink
Don't hardcode the bell block ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Jun 15, 2021
1 parent f53c0cf commit 139167d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.PacketTranslator;
import org.geysermc.connector.network.translators.Translator;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.world.block.entity.NoteblockBlockEntityTranslator;

import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -76,8 +77,7 @@ public void translate(ServerBlockValuePacket packet, GeyserSession session) {
} else if (packet.getValue() instanceof EndGatewayValue) {
blockEventPacket.setEventType(1);
session.sendUpstreamPacket(blockEventPacket);
} else if (packet.getValue() instanceof GenericBlockValue && packet.getBlockId() == 677) {
// TODO: Remove hardcode? Remove hardcodes for all of these? (EndGatewayValue for example still hardcodes the block)
} else if (packet.getValue() instanceof GenericBlockValue && packet.getBlockId() == BlockTranslator.JAVA_BELL_BLOCK_ID) {
// Bells - needed to show ring from other players
GenericBlockValue bellValue = (GenericBlockValue) packet.getValue();
Position position = packet.getPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public abstract class BlockTranslator {
private final EmptyChunkProvider emptyChunkProvider;

public static final int JAVA_COBWEB_BLOCK_ID;
public static final int JAVA_BELL_BLOCK_ID;

public static final int JAVA_RUNTIME_FURNACE_ID;
public static final int JAVA_RUNTIME_FURNACE_LIT_ID;
Expand All @@ -115,6 +116,7 @@ public abstract class BlockTranslator {
}

int javaRuntimeId = -1;
int bellBlockId = -1;
int cobwebBlockId = -1;
int furnaceRuntimeId = -1;
int furnaceLitRuntimeId = -1;
Expand Down Expand Up @@ -181,7 +183,10 @@ public abstract class BlockTranslator {

JAVA_RUNTIME_ID_TO_BLOCK_MAPPING.put(javaRuntimeId, builder.build());

if (javaId.contains("cobweb")) {
if (javaId.startsWith("minecraft:bell[")) {
bellBlockId = uniqueJavaId;

} else if (javaId.contains("cobweb")) {
cobwebBlockId = uniqueJavaId;

} else if (javaId.startsWith("minecraft:furnace[facing=north")) {
Expand All @@ -199,6 +204,11 @@ public abstract class BlockTranslator {
}
}

if (bellBlockId == -1) {
throw new AssertionError("Unable to find bell in palette");
}
JAVA_BELL_BLOCK_ID = bellBlockId;

if (cobwebBlockId == -1) {
throw new AssertionError("Unable to find cobwebs in palette");
}
Expand Down

0 comments on commit 139167d

Please sign in to comment.