mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-28 03:09:08 +00:00
Implement data driven cats
This commit is contained in:
@@ -967,6 +967,7 @@ public final class EntityDefinitions {
|
||||
.type(EntityType.COW)
|
||||
.height(1.4f).width(0.9f)
|
||||
.properties(VanillaEntityProperties.CLIMATE_VARIANT)
|
||||
.addTranslator(MetadataTypes.COW_VARIANT, CowEntity::setVariant)
|
||||
.build();
|
||||
FOX = EntityDefinition.inherited(FoxEntity::new, ageableEntityBase)
|
||||
.type(EntityType.FOX)
|
||||
|
||||
@@ -62,9 +62,12 @@ public abstract class TemperatureVariantAnimal<Variant> extends AnimalEntity {
|
||||
} else {
|
||||
animalVariant = BuiltInVariant.TEMPERATE;
|
||||
}
|
||||
// TODO does this work?
|
||||
dirtyMetadata.put(EntityDataTypes.VARIANT, animalVariant.ordinal());
|
||||
}
|
||||
|
||||
// Ordered by bedrock id
|
||||
// TODO: are these ordered correctly? Does the order differ for mobs?
|
||||
public enum BuiltInVariant {
|
||||
COLD,
|
||||
TEMPERATE,
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
package org.geysermc.geyser.entity.type.living.animal.tameable;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.cloudburstmc.math.vector.Vector3f;
|
||||
@@ -34,16 +35,21 @@ 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.registry.JavaRegistries;
|
||||
import org.geysermc.geyser.session.cache.registry.RegistryEntryContext;
|
||||
import org.geysermc.geyser.session.cache.tags.ItemTag;
|
||||
import org.geysermc.geyser.session.cache.tags.Tag;
|
||||
import org.geysermc.geyser.util.InteractionResult;
|
||||
import org.geysermc.geyser.util.InteractiveTag;
|
||||
import org.geysermc.geyser.util.MinecraftKey;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.BooleanEntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.ByteEntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.type.IntEntityMetadata;
|
||||
import org.geysermc.mcprotocollib.protocol.data.game.entity.player.Hand;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CatEntity extends TameableEntity {
|
||||
|
||||
@@ -81,17 +87,17 @@ public class CatEntity extends TameableEntity {
|
||||
updateCollarColor();
|
||||
}
|
||||
|
||||
// TODO this is a holder when MCPL updates
|
||||
// TODO also checks if this works
|
||||
public void setCatVariant(IntEntityMetadata entityMetadata) {
|
||||
// Different colors in Java and Bedrock for some reason
|
||||
int metadataValue = entityMetadata.getPrimitiveValue();
|
||||
int variantColor = switch (metadataValue) {
|
||||
case 0 -> 8;
|
||||
case 8 -> 0;
|
||||
case 9 -> 10;
|
||||
case 10 -> 9;
|
||||
default -> metadataValue;
|
||||
};
|
||||
dirtyMetadata.put(EntityDataTypes.VARIANT, variantColor);
|
||||
|
||||
BuiltInVariant variant = JavaRegistries.CAT_VARIANT.fromNetworkId(session, metadataValue);
|
||||
if (variant == null) {
|
||||
variant = BuiltInVariant.BLACK; // Default variant on Java
|
||||
}
|
||||
dirtyMetadata.put(EntityDataTypes.VARIANT, variant.ordinal());
|
||||
}
|
||||
|
||||
public void setResting(BooleanEntityMetadata entityMetadata) {
|
||||
@@ -138,4 +144,38 @@ public class CatEntity extends TameableEntity {
|
||||
return !canEat(itemInHand) || health >= maxHealth && tamed ? InteractionResult.PASS : InteractionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
// Ordered by bedrock id
|
||||
// TODO: are these ordered correctly?
|
||||
// TODO lessen code duplication with other variant mobs
|
||||
public enum BuiltInVariant {
|
||||
WHITE,
|
||||
BLACK,
|
||||
RED,
|
||||
SIAMESE,
|
||||
BRITISH_SHORTHAIR,
|
||||
CALICO,
|
||||
PERSIAN,
|
||||
RAGDOLL,
|
||||
TABBY,
|
||||
ALL_BLACK,
|
||||
JELLIE;
|
||||
|
||||
public static final Function<RegistryEntryContext, BuiltInVariant> READER = context -> getByJavaIdentifier(context.id());
|
||||
|
||||
private final Key javaIdentifier;
|
||||
|
||||
BuiltInVariant() {
|
||||
javaIdentifier = MinecraftKey.key(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static @Nullable BuiltInVariant getByJavaIdentifier(Key identifier) {
|
||||
for (BuiltInVariant variant : values()) {
|
||||
if (variant.javaIdentifier.equals(identifier)) {
|
||||
return variant;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.cloudburstmc.protocol.bedrock.data.TrimMaterial;
|
||||
import org.cloudburstmc.protocol.bedrock.data.TrimPattern;
|
||||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal;
|
||||
import org.geysermc.geyser.entity.type.living.animal.tameable.CatEntity;
|
||||
import org.geysermc.geyser.entity.type.living.animal.tameable.WolfEntity;
|
||||
import org.geysermc.geyser.inventory.item.BannerPattern;
|
||||
import org.geysermc.geyser.inventory.item.GeyserInstrument;
|
||||
@@ -95,6 +96,8 @@ public final class RegistryCache {
|
||||
register("banner_pattern", cache -> cache.bannerPatterns, context -> BannerPattern.getByJavaIdentifier(context.id()));
|
||||
register("wolf_variant", cache -> cache.wolfVariants, context -> WolfEntity.BuiltInWolfVariant.getByJavaIdentifier(context.id().asString()));
|
||||
|
||||
register(JavaRegistries.CAT_VARIANT, cache -> cache.catVariants, CatEntity.BuiltInVariant.READER);
|
||||
|
||||
register(JavaRegistries.PIG_VARIANT, cache -> cache.pigVariants, TemperatureVariantAnimal.BuiltInVariant.READER);
|
||||
register(JavaRegistries.COW_VARIANT, cache -> cache.cowVariants, TemperatureVariantAnimal.BuiltInVariant.READER);
|
||||
register(JavaRegistries.CHICKEN_VARIANT, cache -> cache.chickenVariants, TemperatureVariantAnimal.BuiltInVariant.READER);
|
||||
@@ -136,9 +139,11 @@ public final class RegistryCache {
|
||||
private final JavaRegistry<TrimPattern> trimPatterns = new SimpleJavaRegistry<>();
|
||||
|
||||
private final JavaRegistry<BannerPattern> bannerPatterns = new SimpleJavaRegistry<>();
|
||||
private final JavaRegistry<WolfEntity.BuiltInWolfVariant> wolfVariants = new SimpleJavaRegistry<>();
|
||||
private final JavaRegistry<GeyserInstrument> instruments = new SimpleJavaRegistry<>();
|
||||
|
||||
private final JavaRegistry<WolfEntity.BuiltInWolfVariant> wolfVariants = new SimpleJavaRegistry<>();
|
||||
private final JavaRegistry<CatEntity.BuiltInVariant> catVariants = new SimpleJavaRegistry<>();
|
||||
|
||||
private final JavaRegistry<TemperatureVariantAnimal.BuiltInVariant> pigVariants = new SimpleJavaRegistry<>();
|
||||
private final JavaRegistry<TemperatureVariantAnimal.BuiltInVariant> cowVariants = new SimpleJavaRegistry<>();
|
||||
private final JavaRegistry<TemperatureVariantAnimal.BuiltInVariant> chickenVariants = new SimpleJavaRegistry<>();
|
||||
|
||||
@@ -28,6 +28,7 @@ package org.geysermc.geyser.session.cache.registry;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal;
|
||||
import org.geysermc.geyser.entity.type.living.animal.tameable.CatEntity;
|
||||
import org.geysermc.geyser.inventory.item.BannerPattern;
|
||||
import org.geysermc.geyser.item.enchantment.Enchantment;
|
||||
import org.geysermc.geyser.item.type.Item;
|
||||
@@ -51,6 +52,7 @@ public class JavaRegistries {
|
||||
public static final JavaRegistryKey<Item> ITEM = create("item", Registries.JAVA_ITEMS, Item::javaId);
|
||||
public static final JavaRegistryKey<Enchantment> ENCHANTMENT = create("enchantment", RegistryCache::enchantments);
|
||||
public static final JavaRegistryKey<BannerPattern> BANNER_PATTERN = create("banner_pattern", RegistryCache::bannerPatterns);
|
||||
public static final JavaRegistryKey<CatEntity.BuiltInVariant> CAT_VARIANT = create("cat_variant", RegistryCache::catVariants);
|
||||
public static final JavaRegistryKey<TemperatureVariantAnimal.BuiltInVariant> PIG_VARIANT = create("pig_variant", RegistryCache::pigVariants);
|
||||
public static final JavaRegistryKey<TemperatureVariantAnimal.BuiltInVariant> COW_VARIANT = create("cow_variant", RegistryCache::cowVariants);
|
||||
public static final JavaRegistryKey<TemperatureVariantAnimal.BuiltInVariant> CHICKEN_VARIANT = create("chicken_variant", RegistryCache::chickenVariants);
|
||||
|
||||
Reference in New Issue
Block a user