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

Save ItemEntry classes for items

Dieser Commit ist enthalten in:
DoctorMacc 2020-07-07 16:40:19 -04:00
Ursprung 5f6566ad0e
Commit 0cea703b46
6 geänderte Dateien mit 27 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -284,11 +284,11 @@ public class Entity {
// Shield code
if (session.getPlayerEntity().getEntityId() == entityId && metadata.getFlags().getFlag(EntityFlag.SNEAKING)) {
if ((session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().getId() == ItemRegistry.SHIELD) ||
(session.getInventoryCache().getPlayerInventory().getItem(45) != null && session.getInventoryCache().getPlayerInventory().getItem(45).getId() == ItemRegistry.SHIELD)) {
if ((session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().getId() == ItemRegistry.SHIELD.getJavaId()) ||
(session.getInventoryCache().getPlayerInventory().getItem(45) != null && session.getInventoryCache().getPlayerInventory().getItem(45).getId() == ItemRegistry.SHIELD.getJavaId())) {
ClientPlayerUseItemPacket useItemPacket;
metadata.getFlags().setFlag(EntityFlag.BLOCKING, true);
if (session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().getId() == ItemRegistry.SHIELD) {
if (session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().getId() == ItemRegistry.SHIELD.getJavaId()) {
useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
}
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent

Datei anzeigen

@ -61,7 +61,7 @@ public class PiglinEntity extends MonsterEntity {
@Override
public void updateEquipment(GeyserSession session) {
// Check if the Piglin is holding Gold and set the ADMIRING flag accordingly
metadata.getFlags().setFlag(EntityFlag.ADMIRING, offHand.getId() == ItemRegistry.GOLD);
metadata.getFlags().setFlag(EntityFlag.ADMIRING, offHand.getId() == ItemRegistry.GOLD.getBedrockId());
super.updateBedrockMetadata(session);
super.updateEquipment(session);

Datei anzeigen

@ -60,7 +60,7 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
switch (packet.getAction()) {
case INTERACT:
if (session.getInventory().getItem(session.getInventory().getHeldItemSlot() + 36).getId() == ItemRegistry.SHIELD) {
if (session.getInventory().getItem(session.getInventory().getHeldItemSlot() + 36).getId() == ItemRegistry.SHIELD.getJavaId()) {
break;
}
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),

Datei anzeigen

@ -99,7 +99,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
session.sendDownstreamPacket(blockPacket);
// Otherwise boats will not be able to be placed in survival
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BOAT) {
if (packet.getItemInHand() != null && packet.getItemInHand().getId() == ItemRegistry.BOAT.getBedrockId()) {
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
session.sendDownstreamPacket(itemPacket);
}
@ -136,7 +136,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
break;
case 1:
ItemStack shieldSlot = session.getInventory().getItem(session.getInventory().getHeldItemSlot() + 36);
if (shieldSlot != null && shieldSlot.getId() == ItemRegistry.SHIELD) {
if (shieldSlot != null && shieldSlot.getId() == ItemRegistry.SHIELD.getJavaId()) {
break;
} // Handled in Entity.java
ClientPlayerUseItemPacket useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);

Datei anzeigen

@ -27,9 +27,11 @@ package org.geysermc.connector.network.translators.item;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
@Getter
@AllArgsConstructor
@ToString
public class ItemEntry {
public static ItemEntry AIR = new ItemEntry("minecraft:air", 0, 0, 0, false);

Datei anzeigen

@ -57,11 +57,11 @@ public class ItemRegistry {
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
// Shield ID, used in Entity.java
public static int SHIELD = 0;
public static ItemEntry SHIELD;
// Boat ID, used in BedrockInventoryTransactionTranslator.java
public static int BOAT = 0;
public static ItemEntry BOAT;
// Gold ID, used in PiglinEntity.java
public static int GOLD = 0;
public static ItemEntry GOLD;
public static int BARRIER_INDEX = 0;
@ -85,20 +85,6 @@ public class ItemRegistry {
for (JsonNode entry : itemEntries) {
ITEMS.add(new StartGamePacket.ItemEntry(entry.get("name").textValue(), (short) entry.get("id").intValue()));
switch (entry.get("name").textValue()) {
case "minecraft:shield":
SHIELD = entry.get("id").intValue();
break;
case "minecraft:boat":
BOAT = entry.get("id").intValue();
break;
case "minecraft:gold_ingot":
GOLD = entry.get("id").intValue();
break;
default:
break;
}
}
stream = FileUtils.getResource("mappings/items.json");
@ -139,8 +125,21 @@ public class ItemRegistry {
entry.getValue().get("bedrock_data").intValue(),
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
}
if (entry.getKey().equals("minecraft:barrier")) {
switch (entry.getKey()) {
case "minecraft:barrier":
BARRIER_INDEX = itemIndex;
break;
case "minecraft:oak_boat":
BOAT = ITEM_ENTRIES.get(itemIndex);
break;
case "minecraft:gold_ingot":
GOLD = ITEM_ENTRIES.get(itemIndex);
break;
case "minecraft:shield":
SHIELD = ITEM_ENTRIES.get(itemIndex);
break;
default:
break;
}
itemIndex++;