mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Save ItemEntry classes for items
This commit is contained in:
parent
5f6566ad0e
commit
0cea703b46
6 changed files with 27 additions and 26 deletions
|
@ -284,11 +284,11 @@ public class Entity {
|
||||||
|
|
||||||
// Shield code
|
// Shield code
|
||||||
if (session.getPlayerEntity().getEntityId() == entityId && metadata.getFlags().getFlag(EntityFlag.SNEAKING)) {
|
if (session.getPlayerEntity().getEntityId() == entityId && metadata.getFlags().getFlag(EntityFlag.SNEAKING)) {
|
||||||
if ((session.getInventory().getItemInHand() != null && session.getInventory().getItemInHand().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)) {
|
(session.getInventoryCache().getPlayerInventory().getItem(45) != null && session.getInventoryCache().getPlayerInventory().getItem(45).getId() == ItemRegistry.SHIELD.getJavaId())) {
|
||||||
ClientPlayerUseItemPacket useItemPacket;
|
ClientPlayerUseItemPacket useItemPacket;
|
||||||
metadata.getFlags().setFlag(EntityFlag.BLOCKING, true);
|
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);
|
useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
||||||
}
|
}
|
||||||
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent
|
// Else we just assume it's the offhand, to simplify logic and to assure the packet gets sent
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class PiglinEntity extends MonsterEntity {
|
||||||
@Override
|
@Override
|
||||||
public void updateEquipment(GeyserSession session) {
|
public void updateEquipment(GeyserSession session) {
|
||||||
// Check if the Piglin is holding Gold and set the ADMIRING flag accordingly
|
// 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.updateBedrockMetadata(session);
|
||||||
|
|
||||||
super.updateEquipment(session);
|
super.updateEquipment(session);
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
|
||||||
|
|
||||||
switch (packet.getAction()) {
|
switch (packet.getAction()) {
|
||||||
case INTERACT:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
ClientPlayerInteractEntityPacket interactPacket = new ClientPlayerInteractEntityPacket((int) entity.getEntityId(),
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||||
session.sendDownstreamPacket(blockPacket);
|
session.sendDownstreamPacket(blockPacket);
|
||||||
|
|
||||||
// Otherwise boats will not be able to be placed in survival
|
// 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);
|
ClientPlayerUseItemPacket itemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
||||||
session.sendDownstreamPacket(itemPacket);
|
session.sendDownstreamPacket(itemPacket);
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
ItemStack shieldSlot = session.getInventory().getItem(session.getInventory().getHeldItemSlot() + 36);
|
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;
|
break;
|
||||||
} // Handled in Entity.java
|
} // Handled in Entity.java
|
||||||
ClientPlayerUseItemPacket useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
ClientPlayerUseItemPacket useItemPacket = new ClientPlayerUseItemPacket(Hand.MAIN_HAND);
|
||||||
|
|
|
@ -27,9 +27,11 @@ package org.geysermc.connector.network.translators.item;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.ToString;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@ToString
|
||||||
public class ItemEntry {
|
public class ItemEntry {
|
||||||
|
|
||||||
public static ItemEntry AIR = new ItemEntry("minecraft:air", 0, 0, 0, false);
|
public static ItemEntry AIR = new ItemEntry("minecraft:air", 0, 0, 0, false);
|
||||||
|
|
|
@ -57,11 +57,11 @@ public class ItemRegistry {
|
||||||
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
|
public static final Int2ObjectMap<ItemEntry> ITEM_ENTRIES = new Int2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
// Shield ID, used in Entity.java
|
// Shield ID, used in Entity.java
|
||||||
public static int SHIELD = 0;
|
public static ItemEntry SHIELD;
|
||||||
// Boat ID, used in BedrockInventoryTransactionTranslator.java
|
// Boat ID, used in BedrockInventoryTransactionTranslator.java
|
||||||
public static int BOAT = 0;
|
public static ItemEntry BOAT;
|
||||||
// Gold ID, used in PiglinEntity.java
|
// Gold ID, used in PiglinEntity.java
|
||||||
public static int GOLD = 0;
|
public static ItemEntry GOLD;
|
||||||
|
|
||||||
public static int BARRIER_INDEX = 0;
|
public static int BARRIER_INDEX = 0;
|
||||||
|
|
||||||
|
@ -85,20 +85,6 @@ public class ItemRegistry {
|
||||||
|
|
||||||
for (JsonNode entry : itemEntries) {
|
for (JsonNode entry : itemEntries) {
|
||||||
ITEMS.add(new StartGamePacket.ItemEntry(entry.get("name").textValue(), (short) entry.get("id").intValue()));
|
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");
|
stream = FileUtils.getResource("mappings/items.json");
|
||||||
|
@ -139,8 +125,21 @@ public class ItemRegistry {
|
||||||
entry.getValue().get("bedrock_data").intValue(),
|
entry.getValue().get("bedrock_data").intValue(),
|
||||||
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
|
entry.getValue().get("is_block") != null && entry.getValue().get("is_block").booleanValue()));
|
||||||
}
|
}
|
||||||
if (entry.getKey().equals("minecraft:barrier")) {
|
switch (entry.getKey()) {
|
||||||
BARRIER_INDEX = itemIndex;
|
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++;
|
itemIndex++;
|
||||||
|
|
Loading…
Reference in a new issue