1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-19 14:59:27 +00:00

GeyserItemStack.asItem() == Items.ITEM -> GeyserItemStack.is(Items.ITEM) and various other item stack cleanups

This commit is contained in:
Eclipse
2025-09-27 09:49:31 +00:00
parent 3757f3e98d
commit d94bd7c806
40 changed files with 88 additions and 89 deletions

View File

@@ -672,7 +672,7 @@ public class Entity implements GeyserEntity {
// Note this might be client side. Has yet to be an issue though, as of Java 1.21.
return InteractiveTag.REMOVE_LEASH;
}
if (session.getPlayerInventory().getItemInHand(hand).asItem() == Items.LEAD && leashable.canBeLeashed()) {
if (session.getPlayerInventory().getItemInHand(hand).is(Items.LEAD) && leashable.canBeLeashed()) {
// We shall leash
return InteractiveTag.LEASH;
}
@@ -701,7 +701,7 @@ public class Entity implements GeyserEntity {
// Has yet to be an issue though, as of Java 1.21.
return InteractionResult.SUCCESS;
}
if (session.getPlayerInventory().getItemInHand(hand).asItem() == Items.LEAD
if (session.getPlayerInventory().getItemInHand(hand).is(Items.LEAD)
&& !(session.getEntityCache().getEntityByGeyserId(leashable.leashHolderBedrockId()) instanceof PlayerEntity)) {
// We shall leash
return InteractionResult.SUCCESS;

View File

@@ -340,7 +340,7 @@ public class LivingEntity extends Entity {
@Override
public InteractionResult interact(Hand hand) {
GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand(hand);
if (itemStack.asItem() == Items.NAME_TAG) {
if (itemStack.is(Items.NAME_TAG)) {
InteractionResult result = checkInteractWithNameTag(itemStack);
if (result.consumesAction()) {
return result;

View File

@@ -30,8 +30,8 @@ import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.geyser.util.InteractionResult;
import org.geysermc.geyser.util.InteractiveTag;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
@@ -88,6 +88,6 @@ public class AllayEntity extends MobEntity {
}
private boolean isDuplicationItem(GeyserItemStack itemStack) {
return itemStack.asItem() == Items.AMETHYST_SHARD;
return itemStack.is(session, ItemTag.DUPLICATES_ALLAYS);
}
}

View File

@@ -257,7 +257,7 @@ public class ArmorStandEntity extends LivingEntity {
@Override
public InteractionResult interactAt(Hand hand) {
if (!isMarker && session.getPlayerInventory().getItemInHand(hand).asItem() != Items.NAME_TAG) {
if (!isMarker && !session.getPlayerInventory().getItemInHand(hand).is(Items.NAME_TAG)) {
// Java Edition returns SUCCESS if in spectator mode, but this is overridden with an earlier check on the client
return InteractionResult.CONSUME;
} else {

View File

@@ -54,7 +54,7 @@ public class IronGolemEntity extends GolemEntity {
@NonNull
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.IRON_INGOT) {
if (itemInHand.is(Items.IRON_INGOT)) {
if (health < maxHealth) {
// Healing the iron golem
return InteractionResult.SUCCESS;

View File

@@ -85,7 +85,7 @@ public class MobEntity extends LivingEntity implements Leashable {
return InteractiveTag.REMOVE_LEASH;
} else {
GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand(hand);
if (itemStack.asItem() == Items.NAME_TAG) {
if (itemStack.is(Items.NAME_TAG)) {
InteractionResult result = checkInteractWithNameTag(itemStack);
if (result.consumesAction()) {
return InteractiveTag.NAME;
@@ -137,7 +137,7 @@ public class MobEntity extends LivingEntity implements Leashable {
}
private InteractionResult checkPriorityInteractions(GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.NAME_TAG) {
if (itemInHand.is(Items.NAME_TAG)) {
InteractionResult result = checkInteractWithNameTag(itemInHand);
if (result.consumesAction()) {
return result;

View File

@@ -54,7 +54,7 @@ public class SnowGolemEntity extends GolemEntity {
@NonNull
@Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (Items.SHEARS == itemInHand.asItem() && isAlive() && !getFlag(EntityFlag.SHEARED)) {
if (itemInHand.is(Items.SHEARS) && isAlive() && !getFlag(EntityFlag.SHEARED)) {
// Shearing the snow golem
return InteractiveTag.SHEAR;
}
@@ -64,7 +64,7 @@ public class SnowGolemEntity extends GolemEntity {
@NonNull
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (Items.SHEARS == itemInHand.asItem() && isAlive() && !getFlag(EntityFlag.SHEARED)) {
if (itemInHand.is(Items.SHEARS) && isAlive() && !getFlag(EntityFlag.SHEARED)) {
// Shearing the snow golem
return InteractionResult.SUCCESS;
}

View File

@@ -77,7 +77,7 @@ public class GoatEntity extends AnimalEntity {
@NonNull
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (!getFlag(EntityFlag.BABY) && itemInHand.asItem() == Items.BUCKET) {
if (!getFlag(EntityFlag.BABY) && itemInHand.is(Items.BUCKET)) {
session.playSoundEvent(isScreamer ? SoundEvent.MILK_SCREAMER : SoundEvent.MILK, position);
return InteractionResult.SUCCESS;
} else {

View File

@@ -127,7 +127,7 @@ public class HappyGhastEntity extends AnimalEntity implements ClientVehicle {
// Harnesses the ghast
return InteractiveTag.EQUIP_HARNESS;
}
} else if (itemInHand.asItem() == Items.SHEARS) {
} else if (itemInHand.is(Items.SHEARS)) {
if (this.canShearEquipment() && !session.isSneaking()) {
// Shears the harness off of the ghast
return InteractiveTag.REMOVE_HARNESS;
@@ -156,7 +156,7 @@ public class HappyGhastEntity extends AnimalEntity implements ClientVehicle {
// Harnesses the ghast
return InteractionResult.SUCCESS;
}
} else if (itemInHand.asItem() == Items.SHEARS) {
} else if (itemInHand.is(Items.SHEARS)) {
if (this.canShearEquipment() && !session.isSneaking()) {
// Shears the harness off of the ghast
return InteractionResult.SUCCESS;

View File

@@ -63,10 +63,10 @@ public class MooshroomEntity extends CowEntity {
@Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (!isBaby()) {
if (itemInHand.asItem() == Items.BOWL) {
if (itemInHand.is(Items.BOWL)) {
// Stew
return InteractiveTag.MOOSHROOM_MILK_STEW;
} else if (isAlive() && itemInHand.asItem() == Items.SHEARS) {
} else if (isAlive() && itemInHand.is(Items.SHEARS)) {
// Shear items
return InteractiveTag.MOOSHROOM_SHEAR;
}
@@ -78,10 +78,10 @@ public class MooshroomEntity extends CowEntity {
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
boolean isBaby = isBaby();
if (!isBaby && itemInHand.asItem() == Items.BOWL) {
if (!isBaby && itemInHand.is(Items.BOWL)) {
// Stew
return InteractionResult.SUCCESS;
} else if (!isBaby && isAlive() && itemInHand.asItem() == Items.SHEARS) {
} else if (!isBaby && isAlive() && itemInHand.is(Items.SHEARS)) {
// Shear items
return InteractionResult.SUCCESS;
} else if (isBrown && itemInHand.is(session, ItemTag.SMALL_FLOWERS)) {

View File

@@ -68,7 +68,7 @@ public class SheepEntity extends AnimalEntity {
@NonNull
@Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.SHEARS) {
if (itemInHand.is(Items.SHEARS)) {
return InteractiveTag.SHEAR;
} else {
InteractiveTag tag = super.testMobInteraction(hand, itemInHand);
@@ -86,7 +86,7 @@ public class SheepEntity extends AnimalEntity {
@NonNull
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.SHEARS) {
if (itemInHand.is(Items.SHEARS)) {
return InteractionResult.CONSUME;
} else {
InteractionResult superResult = super.mobInteract(hand, itemInHand);

View File

@@ -54,7 +54,7 @@ public class CowEntity extends TemperatureVariantAnimal {
@NonNull
@Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (getFlag(EntityFlag.BABY) || itemInHand.asItem() != Items.BUCKET) {
if (getFlag(EntityFlag.BABY) || !itemInHand.is(Items.BUCKET)) {
return super.testMobInteraction(hand, itemInHand);
}
@@ -64,7 +64,7 @@ public class CowEntity extends TemperatureVariantAnimal {
@NonNull
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (getFlag(EntityFlag.BABY) || itemInHand.asItem() != Items.BUCKET) {
if (getFlag(EntityFlag.BABY) || !itemInHand.is(Items.BUCKET)) {
return super.mobInteract(hand, itemInHand);
}

View File

@@ -165,7 +165,7 @@ public class AbstractHorseEntity extends AnimalEntity {
return InteractiveTag.ATTACH_CHEST;
}
if (additionalTestForInventoryOpen(itemInHand) || !isBaby && !getFlag(EntityFlag.SADDLED) && itemInHand.asItem() == Items.SADDLE) {
if (additionalTestForInventoryOpen(itemInHand) || !isBaby && !getFlag(EntityFlag.SADDLED) && itemInHand.is(Items.SADDLE)) {
// Will open the inventory to be saddled
return InteractiveTag.OPEN_CONTAINER;
}
@@ -221,7 +221,7 @@ public class AbstractHorseEntity extends AnimalEntity {
}
// Note: yes, this code triggers for llamas too. lol (as of Java Edition 1.18.1)
if (additionalTestForInventoryOpen(itemInHand) || (!isBaby && !getFlag(EntityFlag.SADDLED) && itemInHand.asItem() == Items.SADDLE)) {
if (additionalTestForInventoryOpen(itemInHand) || (!isBaby && !getFlag(EntityFlag.SADDLED) && itemInHand.is(Items.SADDLE))) {
// Will open the inventory to be saddled
return InteractionResult.SUCCESS;
}
@@ -245,6 +245,7 @@ public class AbstractHorseEntity extends AnimalEntity {
}
protected boolean additionalTestForInventoryOpen(@NonNull GeyserItemStack itemInHand) {
// TODO this doesn't seem right anymore... (as of Java 1.21.9)
return itemInHand.asItem().javaIdentifier().endsWith("_horse_armor");
}
@@ -260,7 +261,7 @@ public class AbstractHorseEntity extends AnimalEntity {
} else if (!passengers.isEmpty()) {
return testHorseInteraction(hand, itemInHand);
} else {
if (Items.SADDLE == itemInHand.asItem()) {
if (itemInHand.is(Items.SADDLE)) {
return InteractiveTag.OPEN_CONTAINER;
}

View File

@@ -54,7 +54,7 @@ public class ChestedHorseEntity extends AbstractHorseEntity {
@Override
protected boolean testForChest(@NonNull GeyserItemStack itemInHand) {
return itemInHand.asItem() == Items.CHEST && !getFlag(EntityFlag.CHESTED);
return itemInHand.is(Items.CHEST) && !getFlag(EntityFlag.CHESTED);
}
@Override

View File

@@ -52,11 +52,11 @@ public class ParrotEntity extends TameableEntity {
return null;
}
private boolean isTameFood(Item item) {
private boolean isTameFood(GeyserItemStack item) {
return item.is(session, ItemTag.PARROT_FOOD);
}
private boolean isPoisonousFood(Item item) {
private boolean isPoisonousFood(GeyserItemStack item) {
return item.is(session, ItemTag.PARROT_POISONOUS_FOOD);
}
@@ -64,9 +64,9 @@ public class ParrotEntity extends TameableEntity {
@Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
boolean tame = getFlag(EntityFlag.TAMED);
if (!tame && isTameFood(itemInHand.asItem())) {
if (!tame && isTameFood(itemInHand)) {
return InteractiveTag.FEED;
} else if (isPoisonousFood(itemInHand.asItem())) {
} else if (isPoisonousFood(itemInHand)) {
return InteractiveTag.FEED;
} else if (onGround && tame && ownerBedrockId == session.getPlayerEntity().getGeyserId()) {
// Sitting/standing
@@ -79,9 +79,9 @@ public class ParrotEntity extends TameableEntity {
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
boolean tame = getFlag(EntityFlag.TAMED);
if (!tame && isTameFood(itemInHand.asItem())) {
if (!tame && isTameFood(itemInHand)) {
return InteractionResult.SUCCESS;
} else if (isPoisonousFood(itemInHand.asItem())) {
} else if (isPoisonousFood(itemInHand)) {
return InteractionResult.SUCCESS;
} else if (onGround && tame && ownerBedrockId == session.getPlayerEntity().getGeyserId()) {
// Sitting/standing

View File

@@ -147,7 +147,7 @@ public class WolfEntity extends TameableEntity implements VariantIntHolder {
if (getFlag(EntityFlag.ANGRY)) {
return InteractiveTag.NONE;
}
if (itemInHand.asItem() == Items.BONE && !getFlag(EntityFlag.TAMED)) {
if (itemInHand.is(Items.BONE) && !getFlag(EntityFlag.TAMED)) {
// Bone and untamed - can tame
return InteractiveTag.TAME;
}
@@ -160,10 +160,10 @@ public class WolfEntity extends TameableEntity implements VariantIntHolder {
return super.testMobInteraction(hand, itemInHand);
}
}
if (itemInHand.asItem() == Items.WOLF_ARMOR && !getItemInSlot(EquipmentSlot.BODY).isEmpty() && !getFlag(EntityFlag.BABY)) {
if (itemInHand.is(Items.WOLF_ARMOR) && !getItemInSlot(EquipmentSlot.BODY).isEmpty() && !getFlag(EntityFlag.BABY)) {
return InteractiveTag.EQUIP_WOLF_ARMOR;
}
if (itemInHand.asItem() == Items.SHEARS && !getItemInSlot(EquipmentSlot.BODY).isEmpty()
if (itemInHand.is(Items.SHEARS) && !getItemInSlot(EquipmentSlot.BODY).isEmpty()
&& (!isCurseOfBinding || session.getGameMode().equals(GameMode.CREATIVE))) {
return InteractiveTag.REMOVE_WOLF_ARMOR;
}
@@ -181,7 +181,7 @@ public class WolfEntity extends TameableEntity implements VariantIntHolder {
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (ownerBedrockId == session.getPlayerEntity().getGeyserId() || getFlag(EntityFlag.TAMED)
|| itemInHand.asItem() == Items.BONE && !getFlag(EntityFlag.ANGRY)) {
|| itemInHand.is(Items.BONE) && !getFlag(EntityFlag.ANGRY)) {
// Sitting toggle or feeding; not angry
return InteractionResult.CONSUME;
} else {

View File

@@ -54,7 +54,7 @@ public class AbstractMerchantEntity extends AgeableEntity {
@NonNull
@Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() != Items.VILLAGER_SPAWN_EGG
if (!itemInHand.is(Items.VILLAGER_SPAWN_EGG)
&& (definition != EntityDefinitions.VILLAGER || !getFlag(EntityFlag.SLEEPING) && ((VillagerEntity) this).isCanTradeWith())) {
// An additional check we know cannot work
if (!isBaby()) {
@@ -67,7 +67,7 @@ public class AbstractMerchantEntity extends AgeableEntity {
@NonNull
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() != Items.VILLAGER_SPAWN_EGG
if (!itemInHand.is(Items.VILLAGER_SPAWN_EGG)
&& (definition != EntityDefinitions.VILLAGER || !getFlag(EntityFlag.SLEEPING))
&& (definition != EntityDefinitions.WANDERING_TRADER || !getFlag(EntityFlag.BABY))) {
// Trading time

View File

@@ -53,7 +53,7 @@ public class BoggedEntity extends AbstractSkeletonEntity {
@Override
protected @NonNull InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.SHEARS && readyForShearing()) {
if (itemInHand.is(Items.SHEARS) && readyForShearing()) {
return InteractiveTag.SHEAR;
}
return super.testMobInteraction(hand, itemInHand);
@@ -61,7 +61,7 @@ public class BoggedEntity extends AbstractSkeletonEntity {
@Override
protected @NonNull InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.SHEARS && readyForShearing()) {
if (itemInHand.is(Items.SHEARS) && readyForShearing()) {
return InteractionResult.SUCCESS;
}
return super.mobInteract(hand, itemInHand);

View File

@@ -35,7 +35,6 @@ import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.geyser.util.InteractionResult;
@@ -72,8 +71,7 @@ public class PiglinEntity extends BasePiglinEntity {
@Override
public void setHand(GeyserItemStack stack) {
ItemMapping crossbow = session.getItemMappings().getStoredItems().crossbow();
boolean toCrossbow = stack != null && stack.asItem() == crossbow.getJavaItem();
boolean toCrossbow = stack != null && stack.is(Items.CROSSBOW);
if (toCrossbow ^ getMainHandItem().is(Items.CROSSBOW)) { // If switching to/from crossbow
dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(toCrossbow ? 0 : 1));
@@ -148,6 +146,6 @@ public class PiglinEntity extends BasePiglinEntity {
}
private boolean canGiveGoldTo(@NonNull GeyserItemStack itemInHand) {
return !getFlag(EntityFlag.BABY) && itemInHand.asItem() == Items.GOLD_INGOT && !getFlag(EntityFlag.ADMIRING);
return !getFlag(EntityFlag.BABY) && itemInHand.is(Items.GOLD_INGOT) && !getFlag(EntityFlag.ADMIRING);
}
}

View File

@@ -70,7 +70,7 @@ public class ZombieVillagerEntity extends ZombieEntity {
@NonNull
@Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.GOLDEN_APPLE) {
if (itemInHand.is(Items.GOLDEN_APPLE)) {
return InteractiveTag.CURE;
} else {
return super.testMobInteraction(hand, itemInHand);
@@ -80,7 +80,7 @@ public class ZombieVillagerEntity extends ZombieEntity {
@NonNull
@Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.GOLDEN_APPLE) {
if (itemInHand.is(Items.GOLDEN_APPLE)) {
// The client doesn't know if the entity has weakness as that's not usually sent over the network
return InteractionResult.CONSUME;
} else {

View File

@@ -322,9 +322,9 @@ public class SessionPlayerEntity extends PlayerEntity {
protected boolean hasShield(boolean offhand) {
// Must be overridden to point to the player's inventory cache
if (offhand) {
return session.getPlayerInventory().getOffhand().asItem() == Items.SHIELD;
return session.getPlayerInventory().getOffhand().is(Items.SHIELD);
} else {
return session.getPlayerInventory().getItemInHand().asItem() == Items.SHIELD;
return session.getPlayerInventory().getItemInHand().is(Items.SHIELD);
}
}
@@ -539,7 +539,7 @@ public class SessionPlayerEntity extends PlayerEntity {
}
// Bedrock will NOT allow flight when not wearing an elytra; even if it doesn't have a glider component
if (entry.getKey() == EquipmentSlot.CHESTPLATE && !entry.getValue().asItem().equals(Items.ELYTRA)) {
if (entry.getKey() == EquipmentSlot.CHESTPLATE && !entry.getValue().is(Items.ELYTRA)) {
return false;
}
}

View File

@@ -130,6 +130,10 @@ public class GeyserItemStack {
return session.getTagCache().is(set, JavaRegistries.ITEM, javaId);
}
public boolean isSameItem(GeyserItemStack other) {
return javaId == other.javaId;
}
/**
* Returns all components of this item - base and additional components sent over the network.
* These are NOT modifiable! To add components, use {@link #getOrCreateComponents()}.
@@ -263,6 +267,10 @@ public class GeyserItemStack {
return new ItemStackSlotDisplay(this.getItemStack());
}
public int getMaxStackSize() {
return getComponentElseGet(DataComponentTypes.MAX_STACK_SIZE, () -> 1);
}
public int getMaxDamage() {
return getComponentElseGet(DataComponentTypes.MAX_DAMAGE, () -> 0);
}

View File

@@ -148,7 +148,7 @@ public abstract class Inventory {
items[slot] = newItem;
// Lodestone caching
if (newItem.asItem() == Items.COMPASS) {
if (newItem.is(Items.COMPASS)) {
var tracker = newItem.getComponent(DataComponentTypes.LODESTONE_TRACKER);
if (tracker != null) {
session.getLodestoneCache().cacheInventoryItem(newItem, tracker);

View File

@@ -71,7 +71,7 @@ public class PlayerInventory extends Inventory {
* @return If the player is holding the item in either hand
*/
public boolean isHolding(@NonNull Item item) {
return getItemInHand().asItem() == item || getOffhand().asItem() == item;
return getItemInHand().is(item) || getOffhand().is(item);
}
public GeyserItemStack getItemInHand(@NonNull Hand hand) {
@@ -98,10 +98,6 @@ public class PlayerInventory extends Inventory {
);
}
public boolean eitherHandMatchesItem(@NonNull Item item) {
return getItemInHand().asItem() == item || getItemInHand(Hand.OFF_HAND).asItem() == item;
}
public void setItemInHand(@NonNull GeyserItemStack item) {
if (36 + heldItemSlot > this.size) {
GeyserImpl.getInstance().getLogger().debug("Held item slot was larger than expected!");

View File

@@ -45,7 +45,7 @@ public class StonecutterContainer extends Container {
@Override
public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) {
if (slot == 0 && newItem.getJavaId() != items[slot].getJavaId()) {
if (slot == 0 && !newItem.isSameItem(items[slot])) {
// The pressed stonecutter button output resets whenever the input item changes
this.stonecutterButton = -1;
}

View File

@@ -223,7 +223,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater {
if (!material.isEmpty()) {
totalRepairCost += getRepairCost(material);
if (isCombining(input, material)) {
if (hasDurability(input) && input.getJavaId() == material.getJavaId()) {
if (hasDurability(input) && input.isSameItem(material)) {
cost += calcMergeRepairCost(input, material);
}
@@ -388,11 +388,11 @@ public class AnvilInventoryUpdater extends InventoryUpdater {
}
private boolean isEnchantedBook(GeyserItemStack itemStack) {
return itemStack.asItem() == Items.ENCHANTED_BOOK;
return itemStack.is(Items.ENCHANTED_BOOK);
}
private boolean isCombining(GeyserItemStack input, GeyserItemStack material) {
return isEnchantedBook(material) || (input.getJavaId() == material.getJavaId() && hasDurability(input));
return isEnchantedBook(material) || (input.isSameItem(material) && hasDurability(input));
}
private boolean isRepairing(GeyserItemStack input, GeyserItemStack material, GeyserSession session) {

View File

@@ -1449,9 +1449,9 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return false;
}
if (playerInventoryHolder.inventory().getItemInHand().asItem() == Items.SHIELD) {
if (playerInventoryHolder.inventory().getItemInHand().is(Items.SHIELD)) {
useItem(Hand.MAIN_HAND);
} else if (playerInventoryHolder.inventory().getOffhand().asItem() == Items.SHIELD) {
} else if (playerInventoryHolder.inventory().getOffhand().is(Items.SHIELD)) {
useItem(Hand.OFF_HAND);
} else {
// No blocking

View File

@@ -64,7 +64,7 @@ public class BookEditCache {
}
// Don't send the update if the player is not holding a book, shouldn't happen if we catch all interactions
GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
if (itemStack == null || itemStack.asItem() != Items.WRITABLE_BOOK) {
if (itemStack == null || !itemStack.is(Items.WRITABLE_BOOK)) {
packet = null;
return;
}

View File

@@ -314,7 +314,7 @@ public final class BundleInventoryTranslator {
return Fraction.ONE;
}
}
return Fraction.getFraction(1, itemStack.getComponentElseGet(DataComponentTypes.MAX_STACK_SIZE, () -> itemStack.asItem().defaultMaxStackSize()));
return Fraction.getFraction(1, itemStack.getMaxStackSize());
}
public static int capacityForItemStack(Fraction bundleWeight, GeyserItemStack itemStack) {

View File

@@ -46,11 +46,11 @@ public class CartographyInventoryTranslator extends AbstractBlockInventoryTransl
if (javaDestinationSlot == 0) {
// Bedrock Edition can use paper or an empty map in slot 0
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : container.getItem(javaSourceSlot);
return itemStack.asItem() == Items.PAPER || itemStack.asItem() == Items.MAP;
return itemStack.is(Items.PAPER) || itemStack.is(Items.MAP);
} else if (javaDestinationSlot == 1) {
// Bedrock Edition can use a compass to create locator maps, or use a filled map, in the ADDITIONAL slot
GeyserItemStack itemStack = javaSourceSlot == -1 ? session.getPlayerInventory().getCursor() : container.getItem(javaSourceSlot);
return itemStack.asItem() == Items.COMPASS || itemStack.asItem() == Items.FILLED_MAP;
return itemStack.is(Items.COMPASS) || itemStack.is(Items.FILLED_MAP);
}
return false;
}

View File

@@ -329,8 +329,7 @@ public abstract class InventoryTranslator<Type extends Inventory> {
if (destSlot == 5) {
// only set the head if the destination is the head slot
GeyserItemStack javaItem = inventory.getItem(sourceSlot);
if (javaItem.asItem() == Items.PLAYER_HEAD
&& javaItem.hasNonBaseComponents()) {
if (javaItem.is(Items.PLAYER_HEAD) && javaItem.hasNonBaseComponents()) {
FakeHeadProvider.setHead(session, session.getPlayerEntity(), javaItem.getComponent(DataComponentTypes.PROFILE));
}
} else if (sourceSlot == 5) {

View File

@@ -108,10 +108,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator<PlayerInvento
for (int i = 5; i < 9; i++) {
GeyserItemStack item = inventory.getItem(i);
contents[i - 5] = item.getItemData(session);
if (i == 5 &&
item.asItem() == Items.PLAYER_HEAD &&
item.hasNonBaseComponents()) {
// FakeHeadProvider.setHead(session, session.getPlayerEntity(), item.getComponent(DataComponentTypes.PROFILE)); TODO 1.21.9
if (i == 5 && item.is(Items.PLAYER_HEAD) && item.hasNonBaseComponents()) {
FakeHeadProvider.setHead(session, session.getPlayerEntity(), item.getComponent(DataComponentTypes.PROFILE));
}
}
armorContentPacket.setContents(Arrays.asList(contents));
@@ -153,7 +151,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator<PlayerInvento
if (slot == 5) {
// Check for custom skull
if (javaItem.asItem() == Items.PLAYER_HEAD && javaItem.hasNonBaseComponents()) {
if (javaItem.is(Items.PLAYER_HEAD) && javaItem.hasNonBaseComponents()) {
FakeHeadProvider.setHead(session, session.getPlayerEntity(), javaItem.getComponent(DataComponentTypes.PROFILE));
} else {
FakeHeadProvider.restoreOriginalSkin(session, session.getPlayerEntity());
@@ -284,9 +282,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator<PlayerInvento
if (destSlot == 5) {
// only set the head if the destination is the head slot
GeyserItemStack javaItem = inventory.getItem(sourceSlot);
if (javaItem.asItem() == Items.PLAYER_HEAD
&& javaItem.hasNonBaseComponents()) {
// FakeHeadProvider.setHead(session, session.getPlayerEntity(), javaItem.getComponent(DataComponentTypes.PROFILE)); TODO
if (javaItem.is(Items.PLAYER_HEAD) && javaItem.hasNonBaseComponents()) {
FakeHeadProvider.setHead(session, session.getPlayerEntity(), javaItem.getComponent(DataComponentTypes.PROFILE));
}
} else if (sourceSlot == 5) {
// we are probably removing the head, so restore the original skin

View File

@@ -339,7 +339,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
slot = session.getPlayerInventory().getOffsetForHotbar(slot);
}
GeyserItemStack stack = session.getPlayerInventory().getItem(slot);
if (stack.isEmpty() || stack.getJavaId() == mightStackHere.javaId()) {
if (stack.isEmpty() || stack.is(mightStackHere)) {
session.getPlayerInventoryHolder().updateSlot(slot);
break;
}
@@ -380,7 +380,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
}
// Handled when sneaking
if (session.getPlayerInventory().getItemInHand().asItem() == Items.SHIELD) {
if (session.getPlayerInventory().getItemInHand().is(Items.SHIELD)) {
break;
}
@@ -398,7 +398,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
break;
} else if (packet.getItemInHand().getDefinition() == session.getItemMappings().getStoredItems().writtenBook().getBedrockDefinition()) {
session.setCurrentBook(packet.getItemInHand());
} else if (session.getPlayerInventory().getItemInHand().asItem() == Items.GOAT_HORN) {
} else if (session.getPlayerInventory().getItemInHand().is(Items.GOAT_HORN)) {
// Temporary workaround while we don't have full item/block use tracking.
if (!session.getWorldCache().hasCooldown(session.getPlayerInventory().getItemInHand())) {
InstrumentComponent component = session.getPlayerInventory()
@@ -447,7 +447,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
int armorSlot = slotData.getSlots()[0] + 5;
if (armorSlot == 5) {
GeyserItemStack armorSlotItem = playerInventory.getItem(armorSlot);
if (armorSlotItem.asItem() == Items.PLAYER_HEAD) {
if (armorSlotItem.is(Items.PLAYER_HEAD)) {
FakeHeadProvider.restoreOriginalSkin(session, session.getPlayerEntity());
}
}
@@ -586,7 +586,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
session.getPlayerInventoryHolder().updateSlot(heldItemSlot);
GeyserItemStack itemStack = playerInventory.getItem(heldItemSlot);
if (itemStack.getAmount() > 1) {
if (itemStack.asItem() == Items.BUCKET || itemStack.asItem() == Items.GLASS_BOTTLE) {
if (itemStack.is(Items.BUCKET) || itemStack.is(Items.GLASS_BOTTLE)) {
// Using a stack of buckets or glass bottles will result in an item being added to the first empty slot.
// We need to revert the item in case the interaction fails. The order goes from left to right in the
// hotbar. Then left to right and top to bottom in the inventory.

View File

@@ -61,7 +61,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipment
GeyserItemStack newItem = session.getPlayerInventory().getItemInHand();
if (session.isSneaking() && newItem.asItem() == Items.SHIELD) {
if (session.isSneaking() && newItem.is(Items.SHIELD)) {
// Activate shield since we are already sneaking
// (No need to send a release item packet - Java doesn't do this when swapping items)
// Required to do it a tick later or else it doesn't register
@@ -69,7 +69,7 @@ public class BedrockMobEquipmentTranslator extends PacketTranslator<MobEquipment
session.getNanosecondsPerTick(), TimeUnit.NANOSECONDS);
}
if (oldItem.getJavaId() != newItem.getJavaId()) {
if (!oldItem.isSameItem(newItem)) {
// Java sends a cooldown indicator whenever you switch to a new item type
CooldownUtils.sendCooldown(session);
}

View File

@@ -62,7 +62,7 @@ public class BedrockInteractTranslator extends PacketTranslator<InteractPacket>
switch (packet.getAction()) {
case INTERACT:
if (session.getPlayerInventory().getItemInHand().asItem() == Items.SHIELD) {
if (session.getPlayerInventory().getItemInHand().is(Items.SHIELD)) {
break;
}
ServerboundInteractPacket interactPacket = new ServerboundInteractPacket(entity.getEntityId(),

View File

@@ -171,7 +171,7 @@ public class JavaEntityEventTranslator extends PacketTranslator<ClientboundEntit
case TOTEM_OF_UNDYING_MAKE_SOUND:
// Bedrock will not play the spinning animation without the item in the hand o.o
// Fixes https://github.com/GeyserMC/Geyser/issues/2446
boolean totemItemWorkaround = !session.getPlayerInventory().eitherHandMatchesItem(Items.TOTEM_OF_UNDYING);
boolean totemItemWorkaround = !session.getPlayerInventory().isHolding(Items.TOTEM_OF_UNDYING);
if (totemItemWorkaround) {
InventoryContentPacket offhandPacket = new InventoryContentPacket();
offhandPacket.setContainerId(ContainerId.OFFHAND);

View File

@@ -62,7 +62,7 @@ public class JavaSetEquipmentTranslator extends PacketTranslator<ClientboundSetE
switch (equipment.getSlot()) {
case HELMET -> {
ResolvableProfile profile = stack.getComponent(DataComponentTypes.PROFILE);
if (livingEntity instanceof PlayerEntity && stack.asItem() == Items.PLAYER_HEAD && profile != null) {
if (livingEntity instanceof PlayerEntity && stack.is(Items.PLAYER_HEAD) && profile != null) {
FakeHeadProvider.setHead(session, (PlayerEntity) livingEntity, profile);
} else {
FakeHeadProvider.restoreOriginalSkin(session, livingEntity);

View File

@@ -234,7 +234,7 @@ public class JavaContainerSetSlotTranslator extends PacketTranslator<Clientbound
Inventory inventory = holder.inventory();
session.setContainerOutputFuture(session.scheduleInEventLoop(() -> {
GeyserItemStack template = inventory.getItem(SmithingInventoryTranslator.TEMPLATE);
if (template.asItem() != Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE) {
if (!template.is(Items.NETHERITE_UPGRADE_SMITHING_TEMPLATE)) {
// Technically we should probably also do this for custom items, but last I checked Bedrock doesn't even support that.
return;
}

View File

@@ -297,14 +297,14 @@ public final class EntityUtils {
* Determine if an action would result in a successful bucketing of the given entity.
*/
public static boolean attemptToBucket(GeyserItemStack itemInHand) {
return itemInHand.asItem() == Items.WATER_BUCKET;
return itemInHand.is(Items.WATER_BUCKET);
}
/**
* Attempt to determine the result of saddling the given entity.
*/
public static InteractionResult attemptToSaddle(Entity entityToSaddle, GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.SADDLE) {
if (itemInHand.is(Items.SADDLE)) {
if (!entityToSaddle.getFlag(EntityFlag.SADDLED) && !entityToSaddle.getFlag(EntityFlag.BABY)) {
// Saddle
return InteractionResult.SUCCESS;

View File

@@ -266,7 +266,7 @@ public class InventoryUtils {
canStackDebug(item1, item2);
if (item1.isEmpty() || item2.isEmpty())
return false;
return item1.getJavaId() == item2.getJavaId() && Objects.equals(item1.getComponents(), item2.getComponents());
return item1.isSameItem(item2) && Objects.equals(item1.getComponents(), item2.getComponents());
}
private static void canStackDebug(GeyserItemStack item1, GeyserItemStack item2) {