3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-03 14:50:19 +01:00

Use switch statements, and change default block usage

This is to support future changes of using multiple block translators
Dieser Commit ist enthalten in:
Camotoy 2021-02-13 15:29:54 -05:00
Ursprung ce33ca56a9
Commit ec23e409b6
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
8 geänderte Dateien mit 59 neuen und 59 gelöschten Zeilen

Datei anzeigen

@ -48,15 +48,14 @@ import java.util.Set;
*/ */
public class BlockInventoryHolder extends InventoryHolder { public class BlockInventoryHolder extends InventoryHolder {
/** /**
* The default Bedrock block ID to use as a fake block * The default Java block ID to translate as a fake block
*/ */
private final int defaultBedrockBlockId; private final int defaultJavaBlockState;
private final ContainerType containerType; private final ContainerType containerType;
private final Set<String> validBlocks; private final Set<String> validBlocks;
public BlockInventoryHolder(String javaBlockIdentifier, ContainerType containerType, String... validBlocks) { public BlockInventoryHolder(String javaBlockIdentifier, ContainerType containerType, String... validBlocks) {
int javaBlockState = BlockTranslator.getJavaBlockState(javaBlockIdentifier); this.defaultJavaBlockState = BlockTranslator.getJavaBlockState(javaBlockIdentifier);
this.defaultBedrockBlockId = BlockTranslator.getBedrockBlockId(javaBlockState);
this.containerType = containerType; this.containerType = containerType;
if (validBlocks != null) { if (validBlocks != null) {
this.validBlocks = Sets.newHashSet(validBlocks); this.validBlocks = Sets.newHashSet(validBlocks);
@ -90,7 +89,7 @@ public class BlockInventoryHolder extends InventoryHolder {
UpdateBlockPacket blockPacket = new UpdateBlockPacket(); UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0); blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(position); blockPacket.setBlockPosition(position);
blockPacket.setRuntimeId(defaultBedrockBlockId); blockPacket.setRuntimeId(BlockTranslator.getBedrockBlockId(defaultJavaBlockState));
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY); blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket); session.sendUpstreamPacket(blockPacket);
inventory.setHolderPosition(position); inventory.setHolderPosition(position);

Datei anzeigen

@ -103,14 +103,14 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
@Override @Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) { public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
if (slotInfoData.getContainer() == ContainerSlotType.ANVIL_INPUT) { switch (slotInfoData.getContainer()) {
return 0; case ANVIL_INPUT:
} return 0;
if (slotInfoData.getContainer() == ContainerSlotType.ANVIL_MATERIAL) { case ANVIL_MATERIAL:
return 1; return 1;
} case ANVIL_RESULT:
if (slotInfoData.getContainer() == ContainerSlotType.ANVIL_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) { case CREATIVE_OUTPUT:
return 2; return 2;
} }
return super.bedrockSlotToJava(slotInfoData); return super.bedrockSlotToJava(slotInfoData);
} }

Datei anzeigen

@ -71,7 +71,6 @@ public class BrewingInventoryTranslator extends AbstractBlockInventoryTranslator
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) { public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
if (slotInfoData.getContainer() == ContainerSlotType.BREWING_INPUT) { if (slotInfoData.getContainer() == ContainerSlotType.BREWING_INPUT) {
// Ingredient // Ingredient
// TODO: This hasn't worked and then suddenly, it did.
return 3; return 3;
} }
if (slotInfoData.getContainer() == ContainerSlotType.BREWING_RESULT) { if (slotInfoData.getContainer() == ContainerSlotType.BREWING_RESULT) {
@ -98,14 +97,15 @@ public class BrewingInventoryTranslator extends AbstractBlockInventoryTranslator
@Override @Override
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) { public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
if (slot == 0 || slot == 1 || slot == 2) { switch (slot) {
return new BedrockContainerSlot(ContainerSlotType.BREWING_RESULT, javaSlotToBedrock(slot)); case 0:
} case 1:
if (slot == 3) { case 2:
return new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0); return new BedrockContainerSlot(ContainerSlotType.BREWING_RESULT, javaSlotToBedrock(slot));
} case 3:
if (slot == 4) { return new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0);
return new BedrockContainerSlot(ContainerSlotType.BREWING_FUEL, 4); case 4:
return new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0);
} }
return super.javaSlotToBedrockContainer(slot); return super.javaSlotToBedrockContainer(slot);
} }

Datei anzeigen

@ -38,14 +38,14 @@ public class GrindstoneInventoryTranslator extends AbstractBlockInventoryTransla
@Override @Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) { public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
if (slotInfoData.getContainer() == ContainerSlotType.GRINDSTONE_INPUT) { switch (slotInfoData.getContainer()) {
return 0; case GRINDSTONE_INPUT:
} return 0;
if (slotInfoData.getContainer() == ContainerSlotType.GRINDSTONE_ADDITIONAL) { case GRINDSTONE_ADDITIONAL:
return 1; return 1;
} case GRINDSTONE_RESULT:
if (slotInfoData.getContainer() == ContainerSlotType.GRINDSTONE_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) { case CREATIVE_OUTPUT:
return 2; return 2;
} }
return super.bedrockSlotToJava(slotInfoData); return super.bedrockSlotToJava(slotInfoData);
} }

Datei anzeigen

@ -172,17 +172,16 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
@Override @Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) { public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_INPUT) { switch (slotInfoData.getContainer()) {
return 0; case LOOM_INPUT:
} return 0;
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_DYE) { case LOOM_DYE:
return 1; return 1;
} case LOOM_MATERIAL:
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_MATERIAL) { return 2;
return 2; case LOOM_RESULT:
} case CREATIVE_OUTPUT:
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) { return 3;
return 3;
} }
return super.bedrockSlotToJava(slotInfoData); return super.bedrockSlotToJava(slotInfoData);
} }

Datei anzeigen

@ -38,14 +38,14 @@ public class SmithingInventoryTranslator extends AbstractBlockInventoryTranslato
@Override @Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) { public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
if (slotInfoData.getContainer() == ContainerSlotType.SMITHING_TABLE_INPUT) { switch (slotInfoData.getContainer()) {
return 0; case SMITHING_TABLE_INPUT:
} return 0;
if (slotInfoData.getContainer() == ContainerSlotType.SMITHING_TABLE_MATERIAL) { case SMITHING_TABLE_MATERIAL:
return 1; return 1;
} case SMITHING_TABLE_RESULT:
if (slotInfoData.getContainer() == ContainerSlotType.SMITHING_TABLE_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) { case CREATIVE_OUTPUT:
return 2; return 2;
} }
return super.bedrockSlotToJava(slotInfoData); return super.bedrockSlotToJava(slotInfoData);
} }

Datei anzeigen

@ -91,11 +91,12 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
@Override @Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) { public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
if (slotInfoData.getContainer() == ContainerSlotType.STONECUTTER_INPUT) { switch (slotInfoData.getContainer()) {
return 0; case STONECUTTER_INPUT:
} return 0;
if (slotInfoData.getContainer() == ContainerSlotType.STONECUTTER_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) { case STONECUTTER_RESULT:
return 1; case CREATIVE_OUTPUT:
return 1;
} }
return super.bedrockSlotToJava(slotInfoData); return super.bedrockSlotToJava(slotInfoData);
} }

Datei anzeigen

@ -42,12 +42,11 @@ import org.geysermc.connector.network.translators.world.block.DoubleChestValue;
import org.geysermc.connector.network.translators.world.block.entity.DoubleChestBlockEntityTranslator; import org.geysermc.connector.network.translators.world.block.entity.DoubleChestBlockEntityTranslator;
public class DoubleChestInventoryTranslator extends ChestInventoryTranslator { public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
private final int defaultBedrockBlockId; private final int defaultJavaBlockState;
public DoubleChestInventoryTranslator(int size) { public DoubleChestInventoryTranslator(int size) {
super(size, 54); super(size, 54);
int javaBlockState = BlockTranslator.getJavaBlockState("minecraft:chest[facing=north,type=single,waterlogged=false]"); this.defaultJavaBlockState = BlockTranslator.getJavaBlockState("minecraft:chest[facing=north,type=single,waterlogged=false]");
this.defaultBedrockBlockId = BlockTranslator.getBedrockBlockId(javaBlockState);
} }
@Override @Override
@ -84,10 +83,12 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
Vector3i position = session.getPlayerEntity().getPosition().toInt().add(Vector3i.UP); Vector3i position = session.getPlayerEntity().getPosition().toInt().add(Vector3i.UP);
Vector3i pairPosition = position.add(Vector3i.UNIT_X); Vector3i pairPosition = position.add(Vector3i.UNIT_X);
int bedrockBlockId = BlockTranslator.getBedrockBlockId(defaultJavaBlockState);
UpdateBlockPacket blockPacket = new UpdateBlockPacket(); UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0); blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(position); blockPacket.setBlockPosition(position);
blockPacket.setRuntimeId(defaultBedrockBlockId); blockPacket.setRuntimeId(bedrockBlockId);
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY); blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket); session.sendUpstreamPacket(blockPacket);
@ -107,7 +108,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
blockPacket = new UpdateBlockPacket(); blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0); blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(pairPosition); blockPacket.setBlockPosition(pairPosition);
blockPacket.setRuntimeId(defaultBedrockBlockId); blockPacket.setRuntimeId(bedrockBlockId);
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY); blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket); session.sendUpstreamPacket(blockPacket);