Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-11-04 23:30:17 +01:00
Protocol 3.0: ContainerType enum and registries (#3470)
* P3 Updates: ContainerType enum and registries * Remove unused math import
Dieser Commit ist enthalten in:
Ursprung
3e778cdb49
Commit
4b847350b6
@ -30,6 +30,7 @@ import lombok.Value;
|
||||
import org.cloudburstmc.nbt.NbtList;
|
||||
import org.cloudburstmc.nbt.NbtMap;
|
||||
import org.cloudburstmc.protocol.bedrock.data.defintions.BlockDefinition;
|
||||
import org.cloudburstmc.protocol.bedrock.data.defintions.SimpleBlockDefinition;
|
||||
import org.cloudburstmc.protocol.common.DefinitionRegistry;
|
||||
|
||||
import java.util.Map;
|
||||
@ -75,6 +76,10 @@ public class BlockMappings {
|
||||
}
|
||||
|
||||
public boolean isItemFrame(BlockDefinition definition) {
|
||||
return this.itemFrames.containsKey(definition.getRuntimeId());
|
||||
if (definition instanceof SimpleBlockDefinition def) {
|
||||
return this.itemFrames.containsKey(def.getState());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
@ -75,7 +75,7 @@ public class AnvilInventoryTranslator extends AbstractBlockInventoryTranslator {
|
||||
return switch (slotInfoData.getContainer()) {
|
||||
case ANVIL_INPUT -> 0;
|
||||
case ANVIL_MATERIAL -> 1;
|
||||
case ANVIL_RESULT, CREATIVE_OUTPUT -> 2;
|
||||
case ANVIL_RESULT, CREATED_OUTPUT -> 2;
|
||||
default -> super.bedrockSlotToJava(slotInfoData);
|
||||
};
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
|
||||
return switch (slotInfoData.getContainer()) {
|
||||
case CARTOGRAPHY_INPUT -> 0;
|
||||
case CARTOGRAPHY_ADDITIONAL -> 1;
|
||||
case CARTOGRAPHY_RESULT, CREATIVE_OUTPUT -> 2;
|
||||
case CARTOGRAPHY_RESULT, CREATED_OUTPUT -> 2;
|
||||
default -> super.bedrockSlotToJava(slotInfoData);
|
||||
};
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class CraftingInventoryTranslator extends AbstractBlockInventoryTranslato
|
||||
// Bedrock is the same, but it starts from 32.
|
||||
return slotInfoData.getSlot() - 31;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.CRAFTING_OUTPUT || slotInfoData.getContainer() == ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.CRAFTING_OUTPUT || slotInfoData.getContainer() == ContainerSlotType.CREATED_OUTPUT) {
|
||||
return 0;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
|
@ -137,7 +137,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.ENCHANTING_INPUT) {
|
||||
return 0;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.ENCHANTING_LAPIS) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.ENCHANTING_MATERIAL) {
|
||||
return 1;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
@ -149,7 +149,7 @@ public class EnchantingInventoryTranslator extends AbstractBlockInventoryTransla
|
||||
return new BedrockContainerSlot(ContainerSlotType.ENCHANTING_INPUT, 14);
|
||||
}
|
||||
if (slot == 1) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.ENCHANTING_LAPIS, 15);
|
||||
return new BedrockContainerSlot(ContainerSlotType.ENCHANTING_MATERIAL, 15);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(slot);
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class Generic3X3InventoryTranslator extends AbstractBlockInventoryTransla
|
||||
@Override
|
||||
public BedrockContainerSlot javaSlotToBedrockContainer(int javaSlot) {
|
||||
if (javaSlot < this.size) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.CONTAINER, javaSlot);
|
||||
return new BedrockContainerSlot(ContainerSlotType.LEVEL_ENTITY, javaSlot);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(javaSlot);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class GrindstoneInventoryTranslator extends AbstractBlockInventoryTransla
|
||||
return switch (slotInfoData.getContainer()) {
|
||||
case GRINDSTONE_INPUT -> 0;
|
||||
case GRINDSTONE_ADDITIONAL -> 1;
|
||||
case GRINDSTONE_RESULT, CREATIVE_OUTPUT -> 2;
|
||||
case GRINDSTONE_RESULT, CREATED_OUTPUT -> 2;
|
||||
default -> super.bedrockSlotToJava(slotInfoData);
|
||||
};
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class HopperInventoryTranslator extends AbstractBlockInventoryTranslator
|
||||
@Override
|
||||
public BedrockContainerSlot javaSlotToBedrockContainer(int javaSlot) {
|
||||
if (javaSlot < this.size) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.CONTAINER, javaSlot);
|
||||
return new BedrockContainerSlot(ContainerSlotType.LEVEL_ENTITY, javaSlot);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(javaSlot);
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ public abstract class InventoryTranslator {
|
||||
}
|
||||
craftState = CraftState.TRANSFER;
|
||||
|
||||
if (transferAction.getSource().getContainer() != ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
if (transferAction.getSource().getContainer() != ContainerSlotType.CREATED_OUTPUT) {
|
||||
return rejectRequest(request);
|
||||
}
|
||||
if (transferAction.getCount() <= 0) {
|
||||
@ -653,7 +653,7 @@ public abstract class InventoryTranslator {
|
||||
}
|
||||
craftState = CraftState.TRANSFER;
|
||||
|
||||
if (transferAction.getSource().getContainer() != ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
if (transferAction.getSource().getContainer() != ContainerSlotType.CREATED_OUTPUT) {
|
||||
return rejectRequest(request);
|
||||
}
|
||||
if (transferAction.getCount() <= 0) {
|
||||
|
@ -186,7 +186,7 @@ public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
|
||||
case LOOM_INPUT -> 0;
|
||||
case LOOM_DYE -> 1;
|
||||
case LOOM_MATERIAL -> 2;
|
||||
case LOOM_RESULT, CREATIVE_OUTPUT -> 3;
|
||||
case LOOM_RESULT, CREATED_OUTPUT -> 3;
|
||||
default -> super.bedrockSlotToJava(slotInfoData);
|
||||
};
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
||||
@Override
|
||||
public BedrockContainerSlot javaSlotToBedrockContainer(int slot) {
|
||||
return switch (slot) {
|
||||
case 0 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT1, 4);
|
||||
case 1 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT2, 5);
|
||||
case 0 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT_1, 4);
|
||||
case 1 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_INGREDIENT_2, 5);
|
||||
case 2 -> new BedrockContainerSlot(ContainerSlotType.TRADE2_RESULT, 50);
|
||||
default -> super.javaSlotToBedrockContainer(slot);
|
||||
};
|
||||
@ -78,9 +78,9 @@ public class MerchantInventoryTranslator extends BaseInventoryTranslator {
|
||||
@Override
|
||||
public int bedrockSlotToJava(ItemStackRequestSlotData slotInfoData) {
|
||||
return switch (slotInfoData.getContainer()) {
|
||||
case TRADE2_INGREDIENT1 -> 0;
|
||||
case TRADE2_INGREDIENT2 -> 1;
|
||||
case TRADE2_RESULT, CREATIVE_OUTPUT -> 2;
|
||||
case TRADE2_INGREDIENT_1 -> 0;
|
||||
case TRADE2_INGREDIENT_2 -> 1;
|
||||
case TRADE2_RESULT, CREATED_OUTPUT -> 2;
|
||||
default -> super.bedrockSlotToJava(slotInfoData);
|
||||
};
|
||||
}
|
||||
|
@ -197,7 +197,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
|
||||
return slotnum - 27;
|
||||
}
|
||||
break;
|
||||
case CREATIVE_OUTPUT:
|
||||
case CREATED_OUTPUT:
|
||||
return 0;
|
||||
}
|
||||
return slotnum;
|
||||
@ -444,7 +444,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
|
||||
}
|
||||
craftState = CraftState.TRANSFER;
|
||||
|
||||
if (transferAction.getSource().getContainer() != ContainerSlotType.CREATIVE_OUTPUT) {
|
||||
if (transferAction.getSource().getContainer() != ContainerSlotType.CREATED_OUTPUT) {
|
||||
return rejectRequest(request);
|
||||
}
|
||||
|
||||
@ -477,7 +477,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator {
|
||||
}
|
||||
|
||||
DropAction dropAction = (DropAction) action;
|
||||
if (dropAction.getSource().getContainer() != ContainerSlotType.CREATIVE_OUTPUT || dropAction.getSource().getSlot() != 50) {
|
||||
if (dropAction.getSource().getContainer() != ContainerSlotType.CREATED_OUTPUT || dropAction.getSource().getSlot() != 50) {
|
||||
return rejectRequest(request);
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class ShulkerInventoryTranslator extends AbstractBlockInventoryTranslator
|
||||
@Override
|
||||
public BedrockContainerSlot javaSlotToBedrockContainer(int javaSlot) {
|
||||
if (javaSlot < this.size) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.SHULKER, javaSlot);
|
||||
return new BedrockContainerSlot(ContainerSlotType.SHULKER_BOX, javaSlot);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(javaSlot);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class SmithingInventoryTranslator extends AbstractBlockInventoryTranslato
|
||||
return switch (slotInfoData.getContainer()) {
|
||||
case SMITHING_TABLE_INPUT -> 0;
|
||||
case SMITHING_TABLE_MATERIAL -> 1;
|
||||
case SMITHING_TABLE_RESULT, CREATIVE_OUTPUT -> 2;
|
||||
case SMITHING_TABLE_RESULT, CREATED_OUTPUT -> 2;
|
||||
default -> super.bedrockSlotToJava(slotInfoData);
|
||||
};
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class StonecutterInventoryTranslator extends AbstractBlockInventoryTransl
|
||||
public int bedrockSlotToJava(ItemStackRequestSlotData slotInfoData) {
|
||||
return switch (slotInfoData.getContainer()) {
|
||||
case STONECUTTER_INPUT -> 0;
|
||||
case STONECUTTER_RESULT, CREATIVE_OUTPUT -> 1;
|
||||
case STONECUTTER_RESULT, CREATED_OUTPUT -> 1;
|
||||
default -> super.bedrockSlotToJava(slotInfoData);
|
||||
};
|
||||
}
|
||||
|
@ -45,10 +45,10 @@ public abstract class ChestInventoryTranslator extends BaseInventoryTranslator {
|
||||
protected boolean shouldRejectItemPlace(GeyserSession session, Inventory inventory, ContainerSlotType bedrockSourceContainer,
|
||||
int javaSourceSlot, ContainerSlotType bedrockDestinationContainer, int javaDestinationSlot) {
|
||||
// Reject any item placements that occur in the unusable inventory space
|
||||
if (bedrockSourceContainer == ContainerSlotType.CONTAINER && javaSourceSlot >= this.size) {
|
||||
if (bedrockSourceContainer == ContainerSlotType.LEVEL_ENTITY && javaSourceSlot >= this.size) {
|
||||
return true;
|
||||
}
|
||||
return bedrockDestinationContainer == ContainerSlotType.CONTAINER && javaDestinationSlot >= this.size;
|
||||
return bedrockDestinationContainer == ContainerSlotType.LEVEL_ENTITY && javaDestinationSlot >= this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,7 +64,7 @@ public abstract class ChestInventoryTranslator extends BaseInventoryTranslator {
|
||||
@Override
|
||||
public BedrockContainerSlot javaSlotToBedrockContainer(int javaSlot) {
|
||||
if (javaSlot < this.size) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.CONTAINER, javaSlot);
|
||||
return new BedrockContainerSlot(ContainerSlotType.LEVEL_ENTITY, javaSlot);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(javaSlot);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public abstract class AbstractFurnaceInventoryTranslator extends AbstractBlockIn
|
||||
return new BedrockContainerSlot(ContainerSlotType.FURNACE_FUEL, javaSlotToBedrock(slot));
|
||||
}
|
||||
if (slot == 2) {
|
||||
return new BedrockContainerSlot(ContainerSlotType.FURNACE_OUTPUT, javaSlotToBedrock(slot));
|
||||
return new BedrockContainerSlot(ContainerSlotType.FURNACE_RESULT, javaSlotToBedrock(slot));
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(slot);
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public abstract class ChestedHorseInventoryTranslator extends AbstractHorseInven
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.HORSE_EQUIP) {
|
||||
return this.equipSlot;
|
||||
}
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.CONTAINER) {
|
||||
if (slotInfoData.getContainer() == ContainerSlotType.LEVEL_ENTITY) {
|
||||
return slotInfoData.getSlot() + 1;
|
||||
}
|
||||
return super.bedrockSlotToJava(slotInfoData);
|
||||
@ -68,7 +68,7 @@ public abstract class ChestedHorseInventoryTranslator extends AbstractHorseInven
|
||||
return new BedrockContainerSlot(ContainerSlotType.HORSE_EQUIP, 0);
|
||||
}
|
||||
if (slot <= this.size - 1) { // Accommodate for the lack of one slot (saddle or armor)
|
||||
return new BedrockContainerSlot(ContainerSlotType.CONTAINER, slot - 1);
|
||||
return new BedrockContainerSlot(ContainerSlotType.LEVEL_ENTITY, slot - 1);
|
||||
}
|
||||
return super.javaSlotToBedrockContainer(slot);
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren