Skip to content

Commit c398d5c

Browse files
eclipseisofflineonebeastchris
authored andcommitted
Work on farmland variants, not sure if this will work
1 parent 8035a26 commit c398d5c

File tree

9 files changed

+141
-16
lines changed

9 files changed

+141
-16
lines changed

core/src/main/java/org/geysermc/geyser/entity/EntityDefinitions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@
8080
import org.geysermc.geyser.entity.type.living.animal.ArmadilloEntity;
8181
import org.geysermc.geyser.entity.type.living.animal.AxolotlEntity;
8282
import org.geysermc.geyser.entity.type.living.animal.BeeEntity;
83-
import org.geysermc.geyser.entity.type.living.animal.ChickenEntity;
84-
import org.geysermc.geyser.entity.type.living.animal.CowEntity;
83+
import org.geysermc.geyser.entity.type.living.animal.farm.ChickenEntity;
84+
import org.geysermc.geyser.entity.type.living.animal.farm.CowEntity;
8585
import org.geysermc.geyser.entity.type.living.animal.FoxEntity;
8686
import org.geysermc.geyser.entity.type.living.animal.FrogEntity;
8787
import org.geysermc.geyser.entity.type.living.animal.GoatEntity;
8888
import org.geysermc.geyser.entity.type.living.animal.HoglinEntity;
8989
import org.geysermc.geyser.entity.type.living.animal.MooshroomEntity;
9090
import org.geysermc.geyser.entity.type.living.animal.OcelotEntity;
9191
import org.geysermc.geyser.entity.type.living.animal.PandaEntity;
92-
import org.geysermc.geyser.entity.type.living.animal.PigEntity;
92+
import org.geysermc.geyser.entity.type.living.animal.farm.PigEntity;
9393
import org.geysermc.geyser.entity.type.living.animal.PolarBearEntity;
9494
import org.geysermc.geyser.entity.type.living.animal.PufferFishEntity;
9595
import org.geysermc.geyser.entity.type.living.animal.RabbitEntity;

core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
3131
import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket;
3232
import org.geysermc.geyser.entity.EntityDefinition;
33+
import org.geysermc.geyser.entity.type.living.animal.farm.CowEntity;
3334
import org.geysermc.geyser.inventory.GeyserItemStack;
3435
import org.geysermc.geyser.item.Items;
3536
import org.geysermc.geyser.session.GeyserSession;

core/src/main/java/org/geysermc/geyser/entity/type/living/animal/ChickenEntity.java renamed to core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/ChickenEntity.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -23,21 +23,24 @@
2323
* @link https://github.com/GeyserMC/Geyser
2424
*/
2525

26-
package org.geysermc.geyser.entity.type.living.animal;
26+
package org.geysermc.geyser.entity.type.living.animal.farm;
2727

2828
import org.checkerframework.checker.nullness.qual.Nullable;
2929
import org.cloudburstmc.math.vector.Vector3f;
3030
import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket;
3131
import org.geysermc.geyser.entity.EntityDefinition;
3232
import org.geysermc.geyser.entity.properties.VanillaEntityProperties;
33+
import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
3334
import org.geysermc.geyser.item.type.Item;
3435
import org.geysermc.geyser.session.GeyserSession;
36+
import org.geysermc.geyser.session.cache.registry.JavaRegistries;
37+
import org.geysermc.geyser.session.cache.registry.JavaRegistryKey;
3538
import org.geysermc.geyser.session.cache.tags.ItemTag;
3639
import org.geysermc.geyser.session.cache.tags.Tag;
3740

3841
import java.util.UUID;
3942

40-
public class ChickenEntity extends AnimalEntity {
43+
public class ChickenEntity extends TemperatureVariantAnimal<ChickenVariant> {
4144

4245
public ChickenEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
4346
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
@@ -54,4 +57,9 @@ public void addAdditionalSpawnData(AddEntityPacket addEntityPacket) {
5457
protected Tag<Item> getFoodTag() {
5558
return ItemTag.CHICKEN_FOOD;
5659
}
60+
61+
@Override
62+
protected JavaRegistryKey<BuiltInVariant> variantRegistry() {
63+
return JavaRegistries.CHICKEN_VARIANT;
64+
}
5765
}

core/src/main/java/org/geysermc/geyser/entity/type/living/animal/CowEntity.java renamed to core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/CowEntity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,7 @@
2323
* @link https://github.com/GeyserMC/Geyser
2424
*/
2525

26-
package org.geysermc.geyser.entity.type.living.animal;
26+
package org.geysermc.geyser.entity.type.living.animal.farm;
2727

2828
import org.checkerframework.checker.nullness.qual.NonNull;
2929
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -33,10 +33,13 @@
3333
import org.cloudburstmc.protocol.bedrock.packet.AddEntityPacket;
3434
import org.geysermc.geyser.entity.EntityDefinition;
3535
import org.geysermc.geyser.entity.properties.VanillaEntityProperties;
36+
import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
3637
import org.geysermc.geyser.inventory.GeyserItemStack;
3738
import org.geysermc.geyser.item.Items;
3839
import org.geysermc.geyser.item.type.Item;
3940
import org.geysermc.geyser.session.GeyserSession;
41+
import org.geysermc.geyser.session.cache.registry.JavaRegistries;
42+
import org.geysermc.geyser.session.cache.registry.JavaRegistryKey;
4043
import org.geysermc.geyser.session.cache.tags.ItemTag;
4144
import org.geysermc.geyser.session.cache.tags.Tag;
4245
import org.geysermc.geyser.util.InteractionResult;
@@ -45,7 +48,8 @@
4548

4649
import java.util.UUID;
4750

48-
public class CowEntity extends AnimalEntity {
51+
public class CowEntity extends TemperatureVariantAnimal<CowVariant> {
52+
4953
public CowEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
5054
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
5155
}
@@ -82,4 +86,9 @@ protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemS
8286
protected Tag<Item> getFoodTag() {
8387
return ItemTag.COW_FOOD;
8488
}
89+
90+
@Override
91+
protected JavaRegistryKey<BuiltInVariant> variantRegistry() {
92+
return JavaRegistries.COW_VARIANT;
93+
}
8594
}

core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java renamed to core/src/main/java/org/geysermc/geyser/entity/type/living/animal/farm/PigEntity.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
2+
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -23,7 +23,7 @@
2323
* @link https://github.com/GeyserMC/Geyser
2424
*/
2525

26-
package org.geysermc.geyser.entity.type.living.animal;
26+
package org.geysermc.geyser.entity.type.living.animal.farm;
2727

2828
import org.checkerframework.checker.nullness.qual.NonNull;
2929
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -35,6 +35,7 @@
3535
import org.geysermc.geyser.entity.EntityDefinition;
3636
import org.geysermc.geyser.entity.properties.VanillaEntityProperties;
3737
import org.geysermc.geyser.entity.type.Tickable;
38+
import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
3839
import org.geysermc.geyser.entity.type.player.PlayerEntity;
3940
import org.geysermc.geyser.entity.vehicle.BoostableVehicleComponent;
4041
import org.geysermc.geyser.entity.vehicle.ClientVehicle;
@@ -43,6 +44,8 @@
4344
import org.geysermc.geyser.item.type.Item;
4445
import org.geysermc.geyser.item.Items;
4546
import org.geysermc.geyser.session.GeyserSession;
47+
import org.geysermc.geyser.session.cache.registry.JavaRegistries;
48+
import org.geysermc.geyser.session.cache.registry.JavaRegistryKey;
4649
import org.geysermc.geyser.session.cache.tags.ItemTag;
4750
import org.geysermc.geyser.session.cache.tags.Tag;
4851
import org.geysermc.geyser.util.EntityUtils;
@@ -57,7 +60,7 @@
5760

5861
import java.util.UUID;
5962

60-
public class PigEntity extends AnimalEntity implements Tickable, ClientVehicle {
63+
public class PigEntity extends TemperatureVariantAnimal<PigVariant> implements Tickable, ClientVehicle {
6164
private final BoostableVehicleComponent<PigEntity> vehicleComponent = new BoostableVehicleComponent<>(this, 1.0f);
6265

6366
public PigEntity(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition, Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
@@ -160,7 +163,8 @@ public boolean isClientControlled() {
160163
return getPlayerPassenger() == session.getPlayerEntity() && session.getPlayerInventory().isHolding(Items.CARROT_ON_A_STICK);
161164
}
162165

163-
public void setVariant(EntityMetadata<Holder<PigVariant>,? extends MetadataType<Holder<PigVariant>>> holderEntityMetadata) {
164-
// TODO
166+
@Override
167+
protected JavaRegistryKey<BuiltInVariant> variantRegistry() {
168+
return JavaRegistries.PIG_VARIANT;
165169
}
166170
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Copyright (c) 2025 GeyserMC. http://geysermc.org
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*
22+
* @author GeyserMC
23+
* @link https://github.com/GeyserMC/Geyser
24+
*/
25+
26+
package org.geysermc.geyser.entity.type.living.animal.farm;
27+
28+
import net.kyori.adventure.key.Key;
29+
import org.checkerframework.checker.nullness.qual.Nullable;
30+
import org.cloudburstmc.math.vector.Vector3f;
31+
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
32+
import org.geysermc.geyser.entity.EntityDefinition;
33+
import org.geysermc.geyser.entity.type.living.animal.AnimalEntity;
34+
import org.geysermc.geyser.session.GeyserSession;
35+
import org.geysermc.geyser.session.cache.registry.JavaRegistryKey;
36+
import org.geysermc.geyser.session.cache.registry.RegistryEntryContext;
37+
import org.geysermc.geyser.util.MinecraftKey;
38+
import org.geysermc.mcprotocollib.protocol.data.game.Holder;
39+
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.EntityMetadata;
40+
import org.geysermc.mcprotocollib.protocol.data.game.entity.metadata.MetadataType;
41+
42+
import java.util.Locale;
43+
import java.util.UUID;
44+
import java.util.function.Function;
45+
46+
public abstract class TemperatureVariantAnimal<Variant> extends AnimalEntity {
47+
48+
public TemperatureVariantAnimal(GeyserSession session, int entityId, long geyserId, UUID uuid, EntityDefinition<?> definition,
49+
Vector3f position, Vector3f motion, float yaw, float pitch, float headYaw) {
50+
super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw);
51+
}
52+
53+
protected abstract JavaRegistryKey<BuiltInVariant> variantRegistry();
54+
55+
public void setVariant(EntityMetadata<Holder<Variant>, ? extends MetadataType<Holder<Variant>>> variant) {
56+
BuiltInVariant animalVariant;
57+
if (variant.getValue().isId()) {
58+
animalVariant = variantRegistry().fromNetworkId(session, variant.getValue().id());
59+
if (animalVariant == null) {
60+
animalVariant = BuiltInVariant.TEMPERATE;
61+
}
62+
} else {
63+
animalVariant = BuiltInVariant.TEMPERATE;
64+
}
65+
dirtyMetadata.put(EntityDataTypes.VARIANT, animalVariant.ordinal());
66+
}
67+
68+
public enum BuiltInVariant {
69+
COLD,
70+
TEMPERATE,
71+
WARM;
72+
73+
public static final Function<RegistryEntryContext, BuiltInVariant> READER = context -> getByJavaIdentifier(context.id());
74+
75+
private final Key javaIdentifier;
76+
77+
BuiltInVariant() {
78+
javaIdentifier = MinecraftKey.key(name().toLowerCase(Locale.ROOT));
79+
}
80+
81+
public static @Nullable BuiltInVariant getByJavaIdentifier(Key identifier) {
82+
for (BuiltInVariant variant : values()) {
83+
if (variant.javaIdentifier.equals(identifier)) {
84+
return variant;
85+
}
86+
}
87+
return null;
88+
}
89+
}
90+
}

core/src/main/java/org/geysermc/geyser/session/cache/RegistryCache.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.cloudburstmc.protocol.bedrock.data.TrimMaterial;
3939
import org.cloudburstmc.protocol.bedrock.data.TrimPattern;
4040
import org.geysermc.geyser.GeyserImpl;
41+
import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal;
4142
import org.geysermc.geyser.entity.type.living.animal.tameable.WolfEntity;
4243
import org.geysermc.geyser.inventory.item.BannerPattern;
4344
import org.geysermc.geyser.inventory.item.GeyserInstrument;
@@ -94,6 +95,10 @@ public final class RegistryCache {
9495
register("banner_pattern", cache -> cache.bannerPatterns, context -> BannerPattern.getByJavaIdentifier(context.id()));
9596
register("wolf_variant", cache -> cache.wolfVariants, context -> WolfEntity.BuiltInWolfVariant.getByJavaIdentifier(context.id().asString()));
9697

98+
register(JavaRegistries.PIG_VARIANT, cache -> cache.pigVariants, TemperatureVariantAnimal.BuiltInVariant.READER);
99+
register(JavaRegistries.COW_VARIANT, cache -> cache.cowVariants, TemperatureVariantAnimal.BuiltInVariant.READER);
100+
register(JavaRegistries.CHICKEN_VARIANT, cache -> cache.chickenVariants, TemperatureVariantAnimal.BuiltInVariant.READER);
101+
97102
// Load from MCProtocolLib's classloader
98103
NbtMap tag = MinecraftProtocol.loadNetworkCodec();
99104
Map<Key, Map<Key, NbtMap>> defaults = new HashMap<>();
@@ -134,6 +139,10 @@ public final class RegistryCache {
134139
private final JavaRegistry<WolfEntity.BuiltInWolfVariant> wolfVariants = new SimpleJavaRegistry<>();
135140
private final JavaRegistry<GeyserInstrument> instruments = new SimpleJavaRegistry<>();
136141

142+
private final JavaRegistry<TemperatureVariantAnimal.BuiltInVariant> pigVariants = new SimpleJavaRegistry<>();
143+
private final JavaRegistry<TemperatureVariantAnimal.BuiltInVariant> cowVariants = new SimpleJavaRegistry<>();
144+
private final JavaRegistry<TemperatureVariantAnimal.BuiltInVariant> chickenVariants = new SimpleJavaRegistry<>();
145+
137146
public RegistryCache(GeyserSession session) {
138147
this.session = session;
139148
}

core/src/main/java/org/geysermc/geyser/session/cache/registry/JavaRegistries.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import net.kyori.adventure.key.Key;
2929
import org.checkerframework.checker.nullness.qual.Nullable;
30+
import org.geysermc.geyser.entity.type.living.animal.farm.TemperatureVariantAnimal;
3031
import org.geysermc.geyser.inventory.item.BannerPattern;
3132
import org.geysermc.geyser.item.enchantment.Enchantment;
3233
import org.geysermc.geyser.item.type.Item;
@@ -49,7 +50,10 @@ public class JavaRegistries {
4950
public static final JavaRegistryKey<Block> BLOCK = create("block", BlockRegistries.JAVA_BLOCKS, Block::javaId);
5051
public static final JavaRegistryKey<Item> ITEM = create("item", Registries.JAVA_ITEMS, Item::javaId);
5152
public static final JavaRegistryKey<Enchantment> ENCHANTMENT = create("enchantment", RegistryCache::enchantments);
52-
public static final JavaRegistryKey<BannerPattern> BANNER_PATTERNS = create("banner_pattern", RegistryCache::bannerPatterns);
53+
public static final JavaRegistryKey<BannerPattern> BANNER_PATTERN = create("banner_pattern", RegistryCache::bannerPatterns);
54+
public static final JavaRegistryKey<TemperatureVariantAnimal.BuiltInVariant> PIG_VARIANT = create("pig_variant", RegistryCache::pigVariants);
55+
public static final JavaRegistryKey<TemperatureVariantAnimal.BuiltInVariant> COW_VARIANT = create("cow_variant", RegistryCache::cowVariants);
56+
public static final JavaRegistryKey<TemperatureVariantAnimal.BuiltInVariant> CHICKEN_VARIANT = create("chicken_variant", RegistryCache::chickenVariants);
5357

5458
private static <T> JavaRegistryKey<T> create(String key, JavaRegistryKey.NetworkSerializer<T> networkSerializer, JavaRegistryKey.NetworkDeserializer<T> networkDeserializer) {
5559
JavaRegistryKey<T> registry = new JavaRegistryKey<>(MinecraftKey.key(key), networkSerializer, networkDeserializer);

core/src/main/java/org/geysermc/geyser/translator/inventory/LoomInventoryTranslator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
public class LoomInventoryTranslator extends AbstractBlockInventoryTranslator {
6262

63-
private static final Tag<BannerPattern> NO_ITEMS_REQUIRED = new Tag<>(JavaRegistries.BANNER_PATTERNS, Key.key("no_item_required"));
63+
private static final Tag<BannerPattern> NO_ITEMS_REQUIRED = new Tag<>(JavaRegistries.BANNER_PATTERN, Key.key("no_item_required"));
6464

6565
public LoomInventoryTranslator() {
6666
super(4, Blocks.LOOM, ContainerType.LOOM, UIInventoryUpdater.INSTANCE);

0 commit comments

Comments
 (0)