Skip to content

Commit

Permalink
Use item tags for all animal loved food
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed Apr 30, 2024
1 parent aff7d2c commit 59a2c0d
Show file tree
Hide file tree
Showing 32 changed files with 174 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ public final class EntityDefinitions {
.build();
}

EntityDefinition<TameableEntity> tameableEntityBase = EntityDefinition.inherited(TameableEntity::new, ageableEntityBase)
EntityDefinition<TameableEntity> tameableEntityBase = EntityDefinition.<TameableEntity>inherited(null, ageableEntityBase) // No factory, is abstract
.addTranslator(MetadataType.BYTE, TameableEntity::setTameableFlags)
.addTranslator(MetadataType.OPTIONAL_UUID, TameableEntity::setOwner)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import org.cloudburstmc.math.vector.Vector3f;
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.player.Hand;
Expand Down Expand Up @@ -62,6 +62,6 @@ protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemS
}

private boolean isFood(GeyserItemStack itemStack) {
return itemStack.asItem() == Items.SLIME_BALL;
return session.getTagCache().is(ItemTag.FROG_FOOD, itemStack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,39 @@
package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.type.living.AgeableEntity;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item;
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.player.Hand;

import java.util.UUID;

public class AnimalEntity extends AgeableEntity {
public abstract class AnimalEntity extends AgeableEntity {

public AnimalEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
}

public final boolean canEat(GeyserItemStack itemStack) {
return canEat(itemStack.asItem());
protected final boolean canEat(GeyserItemStack itemStack) {
ItemTag tag = getFoodTag();
if (tag == null) {
return false;
}
return session.getTagCache().is(tag, itemStack);
}

/**
* @return true if this is a valid item to breed with for this animal.
* @return the tag associated with this animal for eating food. Null for nothing or different behavior.
*/
public boolean canEat(Item item) {
// This is what it defaults to. OK.
return item == Items.WHEAT;
}
protected abstract @Nullable ItemTag getFoodTag();

@NonNull
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@

package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.ArmadilloState;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;

Expand Down Expand Up @@ -70,4 +72,10 @@ public void onPeeking() {
}, 250, TimeUnit.MILLISECONDS);
}
}

@Override
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.ARMADILLO_FOOD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
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.type.Item;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.geyser.util.EntityUtils;
Expand Down Expand Up @@ -61,8 +61,9 @@ public void setPlayingDead(BooleanEntityMetadata entityMetadata) {
}

@Override
public boolean canEat(Item item) {
return session.getTagCache().is(ItemTag.AXOLOTL_FOOD, item);
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.AXOLOTL_FOOD;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@

package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
Expand Down Expand Up @@ -68,7 +68,8 @@ public void setAngerTime(IntEntityMetadata entityMetadata) {
}

@Override
public boolean canEat(Item item) {
return session.getTagCache().is(ItemTag.FLOWERS, item);
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.BEE_FOOD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@

package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;

import java.util.Set;
import java.util.UUID;

public class ChickenEntity extends AnimalEntity {
private static final Set<Item> VALID_FOOD = Set.of(Items.WHEAT_SEEDS, Items.MELON_SEEDS, Items.PUMPKIN_SEEDS, Items.BEETROOT_SEEDS);

public ChickenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
}

@Override
public boolean canEat(Item item) {
return VALID_FOOD.contains(item);
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.CHICKEN_FOOD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
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.player.Hand;
Expand Down Expand Up @@ -64,4 +66,10 @@ protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemS
session.playSoundEvent(SoundEvent.MILK, position);
return InteractionResult.SUCCESS;
}

@Override
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.COW_FOOD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
Expand All @@ -56,7 +56,8 @@ public void setFoxFlags(ByteEntityMetadata entityMetadata) {
}

@Override
public boolean canEat(Item item) {
return session.getTagCache().is(ItemTag.FOX_FOOD, item);
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.FOX_FOOD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.entity.type.Entity;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.Pose;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ObjectEntityMetadata;
Expand Down Expand Up @@ -76,7 +76,8 @@ public void setTongueTarget(ObjectEntityMetadata<OptionalInt> entityMetadata) {
}

@Override
public boolean canEat(Item item) {
return item == Items.SLIME_BALL;
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.FROG_FOOD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.SoundEvent;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
Expand All @@ -34,6 +35,7 @@
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.mcprotocollib.protocol.data.game.entity.metadata.Pose;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
Expand Down Expand Up @@ -94,4 +96,10 @@ public void setHasRightHorn(BooleanEntityMetadata entityMetadata) {
private void setHornCount() {
dirtyMetadata.put(EntityDataTypes.GOAT_HORN_COUNT, (hasLeftHorn ? 1 : 0) + (hasRightHorn ? 1 : 0));
}

@Override
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.GOAT_FOOD;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.session.cache.tags.ItemTag;
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;

import java.util.UUID;
Expand All @@ -54,8 +54,9 @@ protected boolean isShaking() {
}

@Override
public boolean canEat(Item item) {
return item == Items.CRIMSON_FUNGUS;
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.HOGLIN_FOOD;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import java.util.UUID;

public class MooshroomEntity extends AnimalEntity {
public class MooshroomEntity extends CowEntity {
private boolean isBrown = false;

public MooshroomEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
package org.geysermc.geyser.entity.type.living.animal;

import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
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.item.type.Item;
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.player.Hand;
Expand All @@ -46,8 +46,9 @@ public OcelotEntity(GeyserSession session, int entityId, long geyserId, UUID uui
}

@Override
public boolean canEat(Item item) {
return item == Items.COD || item == Items.SALMON;
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.OCELOT_FOOD;
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
import org.cloudburstmc.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.geyser.entity.EntityDefinition;
import org.geysermc.geyser.inventory.GeyserItemStack;
import org.geysermc.geyser.item.Items;
import org.geysermc.geyser.item.type.Item;
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.ByteEntityMetadata;
Expand Down Expand Up @@ -89,8 +88,9 @@ public void setPandaFlags(ByteEntityMetadata entityMetadata) {
}

@Override
public boolean canEat(Item item) {
return item == Items.BAMBOO;
@Nullable
protected ItemTag getFoodTag() {
return ItemTag.PANDA_FOOD;
}

@NonNull
Expand Down
Loading

0 comments on commit 59a2c0d

Please sign in to comment.