Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-09-08 20:43:04 +02: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:
Ursprung
ce33ca56a9
Commit
ec23e409b6
@ -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);
|
||||
|
@ -103,13 +103,13 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
|
||||
|
||||
@Override
|
||||
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.ANVIL_INPUT) {
|
||||
switch (slotInfoData.getContainer()) {
|
||||
case ANVIL_INPUT:
|
||||
return 0;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.ANVIL_MATERIAL) {
|
||||
case ANVIL_MATERIAL:
|
||||
return 1;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.ANVIL_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
case ANVIL_RESULT:
|
||||
case CREATIVE_OUTPUT:
|
||||
return 2;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
|
@ -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) {
|
||||
switch (slot) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return new BedrockContainerSlot(ContainerSlotType.BREWING_RESULT, javaSlotToBedrock(slot));
|
||||
}
|
||||
if (slot == 3) {
|
||||
case 3:
|
||||
return new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0);
|
||||
case 4:
|
||||
return new BedrockContainerSlot(ContainerSlotType.BREWING_INPUT, 0);
|
||||
}
|
||||
if (slot == 4) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.BREWING_FUEL, 4);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(slot);
|
||||
}
|
||||
|
@ -38,13 +38,13 @@ public class GrindstoneInventoryTranslator extends AbstractBlockInventoryTransla
|
||||
|
||||
@Override
|
||||
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.GRINDSTONE_INPUT) {
|
||||
switch (slotInfoData.getContainer()) {
|
||||
case GRINDSTONE_INPUT:
|
||||
return 0;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.GRINDSTONE_ADDITIONAL) {
|
||||
case GRINDSTONE_ADDITIONAL:
|
||||
return 1;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.GRINDSTONE_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
case GRINDSTONE_RESULT:
|
||||
case CREATIVE_OUTPUT:
|
||||
return 2;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
|
@ -172,16 +172,15 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
|
||||
|
||||
@Override
|
||||
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_INPUT) {
|
||||
switch (slotInfoData.getContainer()) {
|
||||
case LOOM_INPUT:
|
||||
return 0;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_DYE) {
|
||||
case LOOM_DYE:
|
||||
return 1;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_MATERIAL) {
|
||||
case LOOM_MATERIAL:
|
||||
return 2;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.LOOM_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
case LOOM_RESULT:
|
||||
case CREATIVE_OUTPUT:
|
||||
return 3;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
|
@ -38,13 +38,13 @@ public class SmithingInventoryTranslator extends AbstractBlockInventoryTranslato
|
||||
|
||||
@Override
|
||||
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.SMITHING_TABLE_INPUT) {
|
||||
switch (slotInfoData.getContainer()) {
|
||||
case SMITHING_TABLE_INPUT:
|
||||
return 0;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.SMITHING_TABLE_MATERIAL) {
|
||||
case SMITHING_TABLE_MATERIAL:
|
||||
return 1;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.SMITHING_TABLE_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
case SMITHING_TABLE_RESULT:
|
||||
case CREATIVE_OUTPUT:
|
||||
return 2;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
|
@ -91,10 +91,11 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
|
||||
|
||||
@Override
|
||||
public int bedrockSlotToJava(StackRequestSlotInfoData slotInfoData) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.STONECUTTER_INPUT) {
|
||||
switch (slotInfoData.getContainer()) {
|
||||
case STONECUTTER_INPUT:
|
||||
return 0;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.STONECUTTER_RESULT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
case STONECUTTER_RESULT:
|
||||
case CREATIVE_OUTPUT:
|
||||
return 1;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
|
@ -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);
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren