3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +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 {
/**
* 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 Set<String> validBlocks;
public BlockInventoryHolder(String javaBlockIdentifier, ContainerType containerType, String... validBlocks) {
int javaBlockState = BlockTranslator.getJavaBlockState(javaBlockIdentifier);
this.defaultBedrockBlockId = BlockTranslator.getBedrockBlockId(javaBlockState);
this.defaultJavaBlockState = BlockTranslator.getJavaBlockState(javaBlockIdentifier);
this.containerType = containerType;
if (validBlocks != null) {
this.validBlocks = Sets.newHashSet(validBlocks);
@ -90,7 +89,7 @@ public class BlockInventoryHolder extends InventoryHolder {
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(position);
blockPacket.setRuntimeId(defaultBedrockBlockId);
blockPacket.setRuntimeId(BlockTranslator.getBedrockBlockId(defaultJavaBlockState));
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket);
inventory.setHolderPosition(position);

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -91,11 +91,12 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
@Override
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
if (slotInfoData.getContainer() == ContainerSlotType.STONECUTTER_INPUT) {
return 0;
}
if (slotInfoData.getContainer() == ContainerSlotType.STONECUTTER_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
return 1;
switch (slotInfoData.getContainer()) {
case STONECUTTER_INPUT:
return 0;
case STONECUTTER_RESULT:
case CREATIVE_OUTPUT:
return 1;
}
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;
public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
private final int defaultBedrockBlockId;
private final int defaultJavaBlockState;
public DoubleChestInventoryTranslator(int size) {
super(size, 54);
int javaBlockState = BlockTranslator.getJavaBlockState("minecraft:chest[facing=north,type=single,waterlogged=false]");
this.defaultBedrockBlockId = BlockTranslator.getBedrockBlockId(javaBlockState);
this.defaultJavaBlockState = BlockTranslator.getJavaBlockState("minecraft:chest[facing=north,type=single,waterlogged=false]");
}
@Override
@ -84,10 +83,12 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
Vector3i position = session.getPlayerEntity().getPosition().toInt().add(Vector3i.UP);
Vector3i pairPosition = position.add(Vector3i.UNIT_X);
int bedrockBlockId = BlockTranslator.getBedrockBlockId(defaultJavaBlockState);
UpdateBlockPacket blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(position);
blockPacket.setRuntimeId(defaultBedrockBlockId);
blockPacket.setRuntimeId(bedrockBlockId);
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket);
@ -107,7 +108,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
blockPacket = new UpdateBlockPacket();
blockPacket.setDataLayer(0);
blockPacket.setBlockPosition(pairPosition);
blockPacket.setRuntimeId(defaultBedrockBlockId);
blockPacket.setRuntimeId(bedrockBlockId);
blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY);
session.sendUpstreamPacket(blockPacket);