Wolf variants

This commit is contained in:
AJ Ferguson 2024-04-23 00:44:20 -04:00 committed by Camotoy
parent d3f902ae34
commit 1bdbcab4e8
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
4 changed files with 47 additions and 1 deletions

View file

@ -971,6 +971,7 @@ public final class EntityDefinitions {
.addTranslator(MetadataType.BOOLEAN, (wolfEntity, entityMetadata) -> wolfEntity.setFlag(EntityFlag.INTERESTED, ((BooleanEntityMetadata) entityMetadata).getPrimitiveValue()))
.addTranslator(MetadataType.INT, WolfEntity::setCollarColor)
.addTranslator(MetadataType.INT, WolfEntity::setWolfAngerTime)
.addTranslator(MetadataType.WOLF_VARIANT, WolfEntity::setWolfVariant)
.build();
// As of 1.18 these don't track entity data at all

View file

@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEnti
import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
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;
@ -43,6 +44,7 @@ import org.geysermc.geyser.util.InteractionResult;
import org.geysermc.geyser.util.InteractiveTag;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
@ -102,6 +104,15 @@ public class WolfEntity extends TameableEntity {
dirtyMetadata.put(EntityDataTypes.COLOR, time != 0 ? (byte) 0 : collarColor);
}
// 1.20.5+
public void setWolfVariant(IntEntityMetadata entityMetadata) {
WolfVariant wolfVariant = session.getRegistryCache().wolfVariants().get(entityMetadata.getPrimitiveValue());
if (wolfVariant == null) {
wolfVariant = WolfVariant.PALE;
}
dirtyMetadata.put(EntityDataTypes.VARIANT, wolfVariant.ordinal());
}
@Override
public boolean canEat(Item item) {
// Cannot be a baby to eat these foods
@ -147,4 +158,34 @@ public class WolfEntity extends TameableEntity {
return InteractionResult.PASS;
}
}
// Ordered by bedrock id
public enum WolfVariant {
PALE,
ASHEN,
BLACK,
CHESTNUT,
RUSTY,
SNOWY,
SPOTTED,
STRIPED,
WOODS;
private static final WolfVariant[] VALUES = values();
private final String javaIdentifier;
WolfVariant() {
this.javaIdentifier = "minecraft:" + this.name().toLowerCase(Locale.ROOT);
}
public static @Nullable WolfVariant getByJavaIdentifier(String javaIdentifier) {
for (WolfVariant wolfVariant : VALUES) {
if (wolfVariant.javaIdentifier.equals(javaIdentifier)) {
return wolfVariant;
}
}
return null;
}
}
}

View file

@ -80,7 +80,8 @@ public class BannerItem extends BlockItem {
for (int i = 0; i < OMINOUS_BANNER_PATTERN.size(); i++) {
BannerPatternLayer patternLayer = patternLayers.get(i);
Pair<BannerPattern, DyeColor> pair = OMINOUS_BANNER_PATTERN.get(i);
if (!patternLayer.getPattern().isId() || patternLayer.getColorId() != pair.right().ordinal()) {
if (patternLayer.getColorId() != pair.right().ordinal() ||
!patternLayer.getPattern().isId()) {
return false;
}
BannerPattern bannerPattern = session.getRegistryCache().bannerPatterns().get(patternLayer.getPattern().id());

View file

@ -37,6 +37,7 @@ import lombok.experimental.Accessors;
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.tameable.WolfEntity;
import org.geysermc.geyser.inventory.item.BannerPattern;
import org.geysermc.geyser.inventory.recipe.TrimRecipe;
import org.geysermc.geyser.level.JavaDimension;
@ -70,6 +71,7 @@ public final class RegistryCache {
register("trim_pattern", cache -> cache.trimPatterns, TrimRecipe::readTrimPattern);
register("worldgen/biome", (cache, array) -> cache.biomeTranslations = array, BiomeTranslator::loadServerBiome);
register("banner_pattern", cache -> cache.bannerPatterns, ($, entry) -> BannerPattern.getByJavaIdentifier(entry.getId()));
register("wolf_variant", cache -> cache.wolfVariants, ($, entry) -> WolfEntity.WolfVariant.getByJavaIdentifier(entry.getId()));
}
@Getter(AccessLevel.NONE)
@ -88,6 +90,7 @@ public final class RegistryCache {
private final Int2ObjectMap<TrimPattern> trimPatterns = new Int2ObjectOpenHashMap<>();
private final Int2ObjectMap<BannerPattern> bannerPatterns = new Int2ObjectOpenHashMap<>();
private final Int2ObjectMap<WolfEntity.WolfVariant> wolfVariants = new Int2ObjectOpenHashMap<>();
public RegistryCache(GeyserSession session) {
this.session = session;