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. // Note this might be client side. Has yet to be an issue though, as of Java 1.21.
return InteractiveTag.REMOVE_LEASH; 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 // We shall leash
return InteractiveTag.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. // Has yet to be an issue though, as of Java 1.21.
return InteractionResult.SUCCESS; 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)) { && !(session.getEntityCache().getEntityByGeyserId(leashable.leashHolderBedrockId()) instanceof PlayerEntity)) {
// We shall leash // We shall leash
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;

View File

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

View File

@@ -30,8 +30,8 @@ import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.session.GeyserSession; 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.InteractionResult;
import org.geysermc.geyser.util.InteractiveTag; import org.geysermc.geyser.util.InteractiveTag;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; 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) { 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 @Override
public InteractionResult interactAt(Hand hand) { 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 // Java Edition returns SUCCESS if in spectator mode, but this is overridden with an earlier check on the client
return InteractionResult.CONSUME; return InteractionResult.CONSUME;
} else { } else {

View File

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

View File

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

View File

@@ -54,7 +54,7 @@ public class SnowGolemEntity extends GolemEntity {
@NonNull @NonNull
@Override @Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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 // Shearing the snow golem
return InteractiveTag.SHEAR; return InteractiveTag.SHEAR;
} }
@@ -64,7 +64,7 @@ public class SnowGolemEntity extends GolemEntity {
@NonNull @NonNull
@Override @Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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 // Shearing the snow golem
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }

View File

@@ -77,7 +77,7 @@ public class GoatEntity extends AnimalEntity {
@NonNull @NonNull
@Override @Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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); session.playSoundEvent(isScreamer ? SoundEvent.MILK_SCREAMER : SoundEvent.MILK, position);
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} else { } else {

View File

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

View File

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

View File

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

View File

@@ -54,7 +54,7 @@ public class CowEntity extends TemperatureVariantAnimal {
@NonNull @NonNull
@Override @Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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); return super.testMobInteraction(hand, itemInHand);
} }
@@ -64,7 +64,7 @@ public class CowEntity extends TemperatureVariantAnimal {
@NonNull @NonNull
@Override @Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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); return super.mobInteract(hand, itemInHand);
} }

View File

@@ -165,7 +165,7 @@ public class AbstractHorseEntity extends AnimalEntity {
return InteractiveTag.ATTACH_CHEST; 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 // Will open the inventory to be saddled
return InteractiveTag.OPEN_CONTAINER; 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) // 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 // Will open the inventory to be saddled
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
} }
@@ -245,6 +245,7 @@ public class AbstractHorseEntity extends AnimalEntity {
} }
protected boolean additionalTestForInventoryOpen(@NonNull GeyserItemStack itemInHand) { 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"); return itemInHand.asItem().javaIdentifier().endsWith("_horse_armor");
} }
@@ -260,7 +261,7 @@ public class AbstractHorseEntity extends AnimalEntity {
} else if (!passengers.isEmpty()) { } else if (!passengers.isEmpty()) {
return testHorseInteraction(hand, itemInHand); return testHorseInteraction(hand, itemInHand);
} else { } else {
if (Items.SADDLE == itemInHand.asItem()) { if (itemInHand.is(Items.SADDLE)) {
return InteractiveTag.OPEN_CONTAINER; return InteractiveTag.OPEN_CONTAINER;
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -53,7 +53,7 @@ public class BoggedEntity extends AbstractSkeletonEntity {
@Override @Override
protected @NonNull InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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 InteractiveTag.SHEAR;
} }
return super.testMobInteraction(hand, itemInHand); return super.testMobInteraction(hand, itemInHand);
@@ -61,7 +61,7 @@ public class BoggedEntity extends AbstractSkeletonEntity {
@Override @Override
protected @NonNull InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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 InteractionResult.SUCCESS;
} }
return super.mobInteract(hand, itemInHand); 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.entity.EntityDefinition;
import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag; import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractionResult;
@@ -72,8 +71,7 @@ public class PiglinEntity extends BasePiglinEntity {
@Override @Override
public void setHand(GeyserItemStack stack) { public void setHand(GeyserItemStack stack) {
ItemMapping crossbow = session.getItemMappings().getStoredItems().crossbow(); boolean toCrossbow = stack != null && stack.is(Items.CROSSBOW);
boolean toCrossbow = stack != null && stack.asItem() == crossbow.getJavaItem();
if (toCrossbow ^ getMainHandItem().is(Items.CROSSBOW)) { // If switching to/from crossbow if (toCrossbow ^ getMainHandItem().is(Items.CROSSBOW)) { // If switching to/from crossbow
dirtyMetadata.put(EntityDataTypes.BLOCK, session.getBlockMappings().getDefinition(toCrossbow ? 0 : 1)); 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) { 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 @NonNull
@Override @Override
protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) {
if (itemInHand.asItem() == Items.GOLDEN_APPLE) { if (itemInHand.is(Items.GOLDEN_APPLE)) {
return InteractiveTag.CURE; return InteractiveTag.CURE;
} else { } else {
return super.testMobInteraction(hand, itemInHand); return super.testMobInteraction(hand, itemInHand);
@@ -80,7 +80,7 @@ public class ZombieVillagerEntity extends ZombieEntity {
@NonNull @NonNull
@Override @Override
protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { 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 // The client doesn't know if the entity has weakness as that's not usually sent over the network
return InteractionResult.CONSUME; return InteractionResult.CONSUME;
} else { } else {

View File

@@ -322,9 +322,9 @@ public class SessionPlayerEntity extends PlayerEntity {
protected boolean hasShield(boolean offhand) { protected boolean hasShield(boolean offhand) {
// Must be overridden to point to the player's inventory cache // Must be overridden to point to the player's inventory cache
if (offhand) { if (offhand) {
return session.getPlayerInventory().getOffhand().asItem() == Items.SHIELD; return session.getPlayerInventory().getOffhand().is(Items.SHIELD);
} else { } 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 // 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; return false;
} }
} }

View File

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

View File

@@ -148,7 +148,7 @@ public abstract class Inventory {
items[slot] = newItem; items[slot] = newItem;
// Lodestone caching // Lodestone caching
if (newItem.asItem() == Items.COMPASS) { if (newItem.is(Items.COMPASS)) {
var tracker = newItem.getComponent(DataComponentTypes.LODESTONE_TRACKER); var tracker = newItem.getComponent(DataComponentTypes.LODESTONE_TRACKER);
if (tracker != null) { if (tracker != null) {
session.getLodestoneCache().cacheInventoryItem(newItem, tracker); 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 * @return If the player is holding the item in either hand
*/ */
public boolean isHolding(@NonNull Item item) { 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) { 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) { public void setItemInHand(@NonNull GeyserItemStack item) {
if (36 + heldItemSlot > this.size) { if (36 + heldItemSlot > this.size) {
GeyserImpl.getInstance().getLogger().debug("Held item slot was larger than expected!"); GeyserImpl.getInstance().getLogger().debug("Held item slot was larger than expected!");

View File

@@ -45,7 +45,7 @@ public class StonecutterContainer extends Container {
@Override @Override
public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) { 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 // The pressed stonecutter button output resets whenever the input item changes
this.stonecutterButton = -1; this.stonecutterButton = -1;
} }

View File

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

View File

@@ -1449,9 +1449,9 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return false; return false;
} }
if (playerInventoryHolder.inventory().getItemInHand().asItem() == Items.SHIELD) { if (playerInventoryHolder.inventory().getItemInHand().is(Items.SHIELD)) {
useItem(Hand.MAIN_HAND); useItem(Hand.MAIN_HAND);
} else if (playerInventoryHolder.inventory().getOffhand().asItem() == Items.SHIELD) { } else if (playerInventoryHolder.inventory().getOffhand().is(Items.SHIELD)) {
useItem(Hand.OFF_HAND); useItem(Hand.OFF_HAND);
} else { } else {
// No blocking // 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 // 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(); GeyserItemStack itemStack = session.getPlayerInventory().getItemInHand();
if (itemStack == null || itemStack.asItem() != Items.WRITABLE_BOOK) { if (itemStack == null || !itemStack.is(Items.WRITABLE_BOOK)) {
packet = null; packet = null;
return; return;
} }

View File

@@ -314,7 +314,7 @@ public final class BundleInventoryTranslator {
return Fraction.ONE; 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) { public static int capacityForItemStack(Fraction bundleWeight, GeyserItemStack itemStack) {

View File

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

View File

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

View File

@@ -108,10 +108,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator<PlayerInvento
for (int i = 5; i < 9; i++) { for (int i = 5; i < 9; i++) {
GeyserItemStack item = inventory.getItem(i); GeyserItemStack item = inventory.getItem(i);
contents[i - 5] = item.getItemData(session); contents[i - 5] = item.getItemData(session);
if (i == 5 && if (i == 5 && item.is(Items.PLAYER_HEAD) && item.hasNonBaseComponents()) {
item.asItem() == Items.PLAYER_HEAD && FakeHeadProvider.setHead(session, session.getPlayerEntity(), item.getComponent(DataComponentTypes.PROFILE));
item.hasNonBaseComponents()) {
// FakeHeadProvider.setHead(session, session.getPlayerEntity(), item.getComponent(DataComponentTypes.PROFILE)); TODO 1.21.9
} }
} }
armorContentPacket.setContents(Arrays.asList(contents)); armorContentPacket.setContents(Arrays.asList(contents));
@@ -153,7 +151,7 @@ public class PlayerInventoryTranslator extends InventoryTranslator<PlayerInvento
if (slot == 5) { if (slot == 5) {
// Check for custom skull // 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)); FakeHeadProvider.setHead(session, session.getPlayerEntity(), javaItem.getComponent(DataComponentTypes.PROFILE));
} else { } else {
FakeHeadProvider.restoreOriginalSkin(session, session.getPlayerEntity()); FakeHeadProvider.restoreOriginalSkin(session, session.getPlayerEntity());
@@ -284,9 +282,8 @@ public class PlayerInventoryTranslator extends InventoryTranslator<PlayerInvento
if (destSlot == 5) { if (destSlot == 5) {
// only set the head if the destination is the head slot // only set the head if the destination is the head slot
GeyserItemStack javaItem = inventory.getItem(sourceSlot); GeyserItemStack javaItem = inventory.getItem(sourceSlot);
if (javaItem.asItem() == Items.PLAYER_HEAD if (javaItem.is(Items.PLAYER_HEAD) && javaItem.hasNonBaseComponents()) {
&& javaItem.hasNonBaseComponents()) { FakeHeadProvider.setHead(session, session.getPlayerEntity(), javaItem.getComponent(DataComponentTypes.PROFILE));
// FakeHeadProvider.setHead(session, session.getPlayerEntity(), javaItem.getComponent(DataComponentTypes.PROFILE)); TODO
} }
} else if (sourceSlot == 5) { } else if (sourceSlot == 5) {
// we are probably removing the head, so restore the original skin // 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); slot = session.getPlayerInventory().getOffsetForHotbar(slot);
} }
GeyserItemStack stack = session.getPlayerInventory().getItem(slot); GeyserItemStack stack = session.getPlayerInventory().getItem(slot);
if (stack.isEmpty() || stack.getJavaId() == mightStackHere.javaId()) { if (stack.isEmpty() || stack.is(mightStackHere)) {
session.getPlayerInventoryHolder().updateSlot(slot); session.getPlayerInventoryHolder().updateSlot(slot);
break; break;
} }
@@ -380,7 +380,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
} }
// Handled when sneaking // Handled when sneaking
if (session.getPlayerInventory().getItemInHand().asItem() == Items.SHIELD) { if (session.getPlayerInventory().getItemInHand().is(Items.SHIELD)) {
break; break;
} }
@@ -398,7 +398,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
break; break;
} else if (packet.getItemInHand().getDefinition() == session.getItemMappings().getStoredItems().writtenBook().getBedrockDefinition()) { } else if (packet.getItemInHand().getDefinition() == session.getItemMappings().getStoredItems().writtenBook().getBedrockDefinition()) {
session.setCurrentBook(packet.getItemInHand()); 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. // Temporary workaround while we don't have full item/block use tracking.
if (!session.getWorldCache().hasCooldown(session.getPlayerInventory().getItemInHand())) { if (!session.getWorldCache().hasCooldown(session.getPlayerInventory().getItemInHand())) {
InstrumentComponent component = session.getPlayerInventory() InstrumentComponent component = session.getPlayerInventory()
@@ -447,7 +447,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
int armorSlot = slotData.getSlots()[0] + 5; int armorSlot = slotData.getSlots()[0] + 5;
if (armorSlot == 5) { if (armorSlot == 5) {
GeyserItemStack armorSlotItem = playerInventory.getItem(armorSlot); GeyserItemStack armorSlotItem = playerInventory.getItem(armorSlot);
if (armorSlotItem.asItem() == Items.PLAYER_HEAD) { if (armorSlotItem.is(Items.PLAYER_HEAD)) {
FakeHeadProvider.restoreOriginalSkin(session, session.getPlayerEntity()); FakeHeadProvider.restoreOriginalSkin(session, session.getPlayerEntity());
} }
} }
@@ -586,7 +586,7 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator<Inve
session.getPlayerInventoryHolder().updateSlot(heldItemSlot); session.getPlayerInventoryHolder().updateSlot(heldItemSlot);
GeyserItemStack itemStack = playerInventory.getItem(heldItemSlot); GeyserItemStack itemStack = playerInventory.getItem(heldItemSlot);
if (itemStack.getAmount() > 1) { 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. // 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 // 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. // 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(); 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 // Activate shield since we are already sneaking
// (No need to send a release item packet - Java doesn't do this when swapping items) // (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 // 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); 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 // Java sends a cooldown indicator whenever you switch to a new item type
CooldownUtils.sendCooldown(session); CooldownUtils.sendCooldown(session);
} }

View File

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

View File

@@ -171,7 +171,7 @@ public class JavaEntityEventTranslator extends PacketTranslator<ClientboundEntit
case TOTEM_OF_UNDYING_MAKE_SOUND: case TOTEM_OF_UNDYING_MAKE_SOUND:
// Bedrock will not play the spinning animation without the item in the hand o.o // Bedrock will not play the spinning animation without the item in the hand o.o
// Fixes https://github.com/GeyserMC/Geyser/issues/2446 // 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) { if (totemItemWorkaround) {
InventoryContentPacket offhandPacket = new InventoryContentPacket(); InventoryContentPacket offhandPacket = new InventoryContentPacket();
offhandPacket.setContainerId(ContainerId.OFFHAND); offhandPacket.setContainerId(ContainerId.OFFHAND);

View File

@@ -62,7 +62,7 @@ public class JavaSetEquipmentTranslator extends PacketTranslator<ClientboundSetE
switch (equipment.getSlot()) { switch (equipment.getSlot()) {
case HELMET -> { case HELMET -> {
ResolvableProfile profile = stack.getComponent(DataComponentTypes.PROFILE); 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); FakeHeadProvider.setHead(session, (PlayerEntity) livingEntity, profile);
} else { } else {
FakeHeadProvider.restoreOriginalSkin(session, livingEntity); FakeHeadProvider.restoreOriginalSkin(session, livingEntity);

View File

@@ -234,7 +234,7 @@ public class JavaContainerSetSlotTranslator extends PacketTranslator<Clientbound
Inventory inventory = holder.inventory(); Inventory inventory = holder.inventory();
session.setContainerOutputFuture(session.scheduleInEventLoop(() -> { session.setContainerOutputFuture(session.scheduleInEventLoop(() -> {
GeyserItemStack template = inventory.getItem(SmithingInventoryTranslator.TEMPLATE); 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. // Technically we should probably also do this for custom items, but last I checked Bedrock doesn't even support that.
return; 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. * Determine if an action would result in a successful bucketing of the given entity.
*/ */
public static boolean attemptToBucket(GeyserItemStack itemInHand) { 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. * Attempt to determine the result of saddling the given entity.
*/ */
public static InteractionResult attemptToSaddle(Entity entityToSaddle, GeyserItemStack itemInHand) { 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)) { if (!entityToSaddle.getFlag(EntityFlag.SADDLED) && !entityToSaddle.getFlag(EntityFlag.BABY)) {
// Saddle // Saddle
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;

View File

@@ -266,7 +266,7 @@ public class InventoryUtils {
canStackDebug(item1, item2); canStackDebug(item1, item2);
if (item1.isEmpty() || item2.isEmpty()) if (item1.isEmpty() || item2.isEmpty())
return false; 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) { private static void canStackDebug(GeyserItemStack item1, GeyserItemStack item2) {