Skip to content

Commit

Permalink
yay
Browse files Browse the repository at this point in the history
  • Loading branch information
AViewFromTheTop committed Feb 10, 2025
1 parent 4467c7e commit 2bf5eba
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void doFireflySpawns(@NotNull Level level) {
Firefly entity = WWEntityTypes.FIREFLY.create(level);
if (entity != null) {
entity.moveTo(worldPosition.getX() + firefly.pos.x, worldPosition.getY() + firefly.y + extraHeight + 0.07D, worldPosition.getZ() + firefly.pos.z, 0F, 0F);
entity.setFromBottle(true);
entity.wilderWild$setFromBottle(true);
if (level.addFreshEntity(entity)) {
FireflyAi.rememberHome(entity, entity.blockPosition());
entity.setColor(firefly.color);
Expand Down
41 changes: 24 additions & 17 deletions src/main/java/net/frozenblock/wilderwild/entity/Butterfly.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.frozenblock.lib.wind.api.WindManager;
import net.frozenblock.wilderwild.config.WWEntityConfig;
import net.frozenblock.wilderwild.entity.ai.butterfly.ButterflyAi;
import net.frozenblock.wilderwild.entity.impl.Bottleable;
import net.frozenblock.wilderwild.entity.impl.WWBottleable;
import net.frozenblock.wilderwild.entity.variant.butterfly.ButterflyVariant;
import net.frozenblock.wilderwild.entity.variant.butterfly.ButterflyVariants;
import net.frozenblock.wilderwild.item.MobBottleItem;
Expand Down Expand Up @@ -57,6 +57,7 @@
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.VariantHolder;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
Expand All @@ -82,7 +83,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class Butterfly extends PathfinderMob implements FlyingAnimal, Bottleable {
public class Butterfly extends PathfinderMob implements FlyingAnimal, WWBottleable, VariantHolder<ButterflyVariant> {
public static final int TICKS_PER_FLAP = 3;
public static final int SPAWN_CHANCE = 50;
private static final double SPAWN_RADIUS_CHECK_DISTANCE = 20D;
Expand Down Expand Up @@ -204,7 +205,7 @@ public void onSyncedDataUpdated(EntityDataAccessor<?> entityDataAccessor) {
@Override
@NotNull
protected InteractionResult mobInteract(@NotNull Player player, @NotNull InteractionHand hand) {
return Bottleable.bottleMobPickup(player, hand, this).orElse(super.mobInteract(player, hand));
return WWBottleable.bottleMobPickup(player, hand, this).orElse(super.mobInteract(player, hand));
}

@Override
Expand All @@ -225,18 +226,18 @@ protected Brain<?> makeBrain(@NotNull Dynamic<?> dynamic) {
}

@Override
public boolean fromBottle() {
public boolean wilderWild$fromBottle() {
return this.entityData.get(FROM_BOTTLE);
}

@Override
public void setFromBottle(boolean value) {
public void wilderWild$setFromBottle(boolean value) {
this.entityData.set(FROM_BOTTLE, value);
}

@Override
public void saveToBottleTag(ItemStack itemStack) {
Bottleable.saveDefaultDataToBottleTag(this, itemStack);
public void wilderWild$saveToBottleTag(ItemStack itemStack) {
WWBottleable.saveDefaultDataToBottleTag(this, itemStack);

CustomData.update(
WWDataComponents.BOTTLE_ENTITY_DATA,
Expand All @@ -246,8 +247,8 @@ public void saveToBottleTag(ItemStack itemStack) {
}

@Override
public void loadFromBottleTag(CompoundTag compoundTag) {
Bottleable.loadDefaultDataFromBottleTag(this, compoundTag);
public void wilderWild$loadFromBottleTag(CompoundTag compoundTag) {
WWBottleable.loadDefaultDataFromBottleTag(this, compoundTag);
if (compoundTag.contains(MobBottleItem.BUTTERFLY_BOTTLE_VARIANT_FIELD)) {
Optional.ofNullable(ResourceLocation.tryParse(compoundTag.getString(MobBottleItem.BUTTERFLY_BOTTLE_VARIANT_FIELD)))
.map(resourceLocation -> ResourceKey.create(WilderWildRegistries.BUTTERFLY_VARIANT, resourceLocation))
Expand All @@ -257,21 +258,21 @@ public void loadFromBottleTag(CompoundTag compoundTag) {
}

@Override
public void onCapture() {
public void wilderWild$onCapture() {
}

@Override
public void onBottleRelease() {
public void wilderWild$onBottleRelease() {
ButterflyAi.rememberHome(this, this.blockPosition());
}

@Override
public ItemStack getBottleItemStack() {
public ItemStack wilderWild$getBottleItemStack() {
return new ItemStack(WWItems.BUTTERFLY_BOTTLE);
}

@Override
public SoundEvent getBottleCatchSound() {
public SoundEvent wilderWild$getBottleCatchSound() {
return WWSounds.ITEM_BOTTLE_CATCH_BUTTERFLY;
}

Expand All @@ -295,17 +296,23 @@ public ButterflyVariant getVariantForRendering() {
return this.butterflyVariant.orElse(this.registryAccess().registryOrThrow(WilderWildRegistries.BUTTERFLY_VARIANT).get(ButterflyVariants.DEFAULT));
}

@Override
public void setVariant(@NotNull ButterflyVariant variant) {
this.entityData.set(VARIANT, Objects.requireNonNull(this.registryAccess().registryOrThrow(WilderWildRegistries.BUTTERFLY_VARIANT).getKey(variant)).toString());
}

@Override
public @NotNull ButterflyVariant getVariant() {
return this.getVariantByLocation();
}

public void setVariant(@NotNull ResourceLocation variant) {
this.entityData.set(VARIANT, variant.toString());
}

@Override
public boolean requiresCustomPersistence() {
return super.requiresCustomPersistence() || this.fromBottle();
return super.requiresCustomPersistence() || this.wilderWild$fromBottle();
}

@Override
Expand Down Expand Up @@ -412,14 +419,14 @@ public boolean isFlapping() {

@Override
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
return !this.fromBottle() && !this.hasCustomName();
return !this.wilderWild$fromBottle() && !this.hasCustomName();
}

@Override
public void addAdditionalSaveData(@NotNull CompoundTag compoundTag) {
super.addAdditionalSaveData(compoundTag);
compoundTag.putString("variant", this.getVariantLocation().toString());
compoundTag.putBoolean("fromBottle", this.fromBottle());
compoundTag.putBoolean("fromBottle", this.wilderWild$fromBottle());
}

@Override
Expand All @@ -429,7 +436,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compoundTag) {
.map(resourceLocation -> ResourceKey.create(WilderWildRegistries.BUTTERFLY_VARIANT, resourceLocation))
.flatMap(resourceKey -> this.registryAccess().registryOrThrow(WilderWildRegistries.BUTTERFLY_VARIANT).getHolder(resourceKey))
.ifPresent(reference -> this.setVariant(reference.value()));
if (compoundTag.contains("fromBottle")) this.setFromBottle(compoundTag.getBoolean("fromBottle"));
if (compoundTag.contains("fromBottle")) this.wilderWild$setFromBottle(compoundTag.getBoolean("fromBottle"));
}

@Override
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/net/frozenblock/wilderwild/entity/Crab.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.Pose;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.VariantHolder;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
Expand Down Expand Up @@ -118,7 +119,7 @@
import org.jetbrains.annotations.Nullable;
import org.joml.Math;

public class Crab extends Animal implements VibrationSystem, Bucketable {
public class Crab extends Animal implements VibrationSystem, Bucketable, VariantHolder<CrabVariant> {
public static final float MAX_TARGET_DISTANCE = 16F;
public static final double MOVEMENT_SPEED = 0.16;
public static final float STEP_HEIGHT = 0.2F;
Expand Down Expand Up @@ -821,10 +822,16 @@ public CrabVariant getVariantForRendering() {
return this.crabVariant.orElse(this.registryAccess().registryOrThrow(WilderWildRegistries.CRAB_VARIANT).get(CrabVariants.DEFAULT));
}

@Override
public void setVariant(@NotNull CrabVariant variant) {
this.entityData.set(VARIANT, Objects.requireNonNull(this.registryAccess().registryOrThrow(WilderWildRegistries.CRAB_VARIANT).getKey(variant)).toString());
}

@Override
public @NotNull CrabVariant getVariant() {
return this.getVariantByLocation();
}

public void setVariant(@NotNull ResourceLocation variant) {
this.entityData.set(VARIANT, variant.toString());
}
Expand Down
41 changes: 26 additions & 15 deletions src/main/java/net/frozenblock/wilderwild/entity/Firefly.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import net.frozenblock.lib.wind.api.WindManager;
import net.frozenblock.wilderwild.config.WWEntityConfig;
import net.frozenblock.wilderwild.entity.ai.firefly.FireflyAi;
import net.frozenblock.wilderwild.entity.impl.Bottleable;
import net.frozenblock.wilderwild.entity.impl.WWBottleable;
import net.frozenblock.wilderwild.entity.variant.firefly.FireflyColor;
import net.frozenblock.wilderwild.entity.variant.firefly.FireflyColors;
import net.frozenblock.wilderwild.item.MobBottleItem;
Expand Down Expand Up @@ -56,6 +56,7 @@
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.PathfinderMob;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.VariantHolder;
import net.minecraft.world.entity.ai.Brain;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
Expand All @@ -79,7 +80,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class Firefly extends PathfinderMob implements FlyingAnimal, Bottleable {
public class Firefly extends PathfinderMob implements FlyingAnimal, WWBottleable, VariantHolder<FireflyColor> {
public static final int RANDOM_FLICKER_AGE_MAX = 19;
private static final EntityDataAccessor<Boolean> FROM_BOTTLE = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.BOOLEAN);
private static final EntityDataAccessor<Integer> AGE = SynchedEntityData.defineId(Firefly.class, EntityDataSerializers.INT);
Expand Down Expand Up @@ -192,7 +193,7 @@ public boolean dampensVibrations() {
@Override
@NotNull
protected InteractionResult mobInteract(@NotNull Player player, @NotNull InteractionHand hand) {
return Bottleable.bottleMobPickup(player, hand, this).orElse(super.mobInteract(player, hand));
return WWBottleable.bottleMobPickup(player, hand, this).orElse(super.mobInteract(player, hand));
}

@Override
Expand All @@ -218,17 +219,17 @@ protected Brain<?> makeBrain(@NotNull Dynamic<?> dynamic) {
}

@Override
public boolean fromBottle() {
public boolean wilderWild$fromBottle() {
return this.entityData.get(FROM_BOTTLE);
}

@Override
public void setFromBottle(boolean value) {
public void wilderWild$setFromBottle(boolean value) {
this.entityData.set(FROM_BOTTLE, value);
}

@Override
public void saveToBottleTag(ItemStack itemStack) {
public void wilderWild$saveToBottleTag(ItemStack itemStack) {
CompoundTag tag = new CompoundTag();
tag.putString(MobBottleItem.FIREFLY_BOTTLE_VARIANT_FIELD, this.getColorLocation().toString());
CustomData.set(
Expand All @@ -239,7 +240,7 @@ public void saveToBottleTag(ItemStack itemStack) {
}

@Override
public void loadFromBottleTag(@NotNull CompoundTag compoundTag) {
public void wilderWild$loadFromBottleTag(@NotNull CompoundTag compoundTag) {
if (compoundTag.contains(MobBottleItem.FIREFLY_BOTTLE_VARIANT_FIELD)) {
Optional.ofNullable(ResourceLocation.tryParse(compoundTag.getString(MobBottleItem.FIREFLY_BOTTLE_VARIANT_FIELD)))
.map(resourceLocation -> ResourceKey.create(WilderWildRegistries.FIREFLY_COLOR, resourceLocation))
Expand All @@ -249,24 +250,24 @@ public void loadFromBottleTag(@NotNull CompoundTag compoundTag) {
}

@Override
public void onCapture() {
public void wilderWild$onCapture() {
if (this.isSwarmLeader()) {
FireflyAi.transferLeadershipToRandomFirefly(this);
}
}

@Override
public void onBottleRelease() {
public void wilderWild$onBottleRelease() {
FireflyAi.rememberHome(this, this.blockPosition());
}

@Override
public ItemStack getBottleItemStack() {
public ItemStack wilderWild$getBottleItemStack() {
return new ItemStack(WWItems.FIREFLY_BOTTLE);
}

@Override
public SoundEvent getBottleCatchSound() {
public SoundEvent wilderWild$getBottleCatchSound() {
return WWSounds.ITEM_BOTTLE_CATCH_FIREFLY;
}

Expand Down Expand Up @@ -324,7 +325,7 @@ public void setColor(@NotNull ResourceLocation color) {

@Override
public boolean requiresCustomPersistence() {
return super.requiresCustomPersistence() || this.fromBottle();
return super.requiresCustomPersistence() || this.wilderWild$fromBottle();
}

@Override
Expand Down Expand Up @@ -453,7 +454,7 @@ public boolean isFlapping() {

@Override
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
return !this.fromBottle() && !this.hasCustomName();
return !this.wilderWild$fromBottle() && !this.hasCustomName();
}

@Override
Expand All @@ -472,7 +473,7 @@ public void addAdditionalSaveData(@NotNull CompoundTag compoundTag) {
.unwrapKey()
.ifPresent(resourceKey -> compoundTag.putString("color", resourceKey.location().toString()));

compoundTag.putBoolean("fromBottle", this.fromBottle());
compoundTag.putBoolean("fromBottle", this.wilderWild$fromBottle());
compoundTag.putInt("flickerAge", this.getFlickerAge());
compoundTag.putFloat("scale", this.getAnimScale());
compoundTag.putFloat("prevScale", this.getPrevAnimScale());
Expand All @@ -487,7 +488,7 @@ public void readAdditionalSaveData(@NotNull CompoundTag compoundTag) {
.flatMap(resourceKey -> this.registryAccess().registryOrThrow(WilderWildRegistries.FIREFLY_COLOR).getHolder(resourceKey))
.ifPresent(reference -> this.setColor(reference.value()));

if (compoundTag.contains("fromBottle")) this.setFromBottle(compoundTag.getBoolean("fromBottle"));
if (compoundTag.contains("fromBottle")) this.wilderWild$setFromBottle(compoundTag.getBoolean("fromBottle"));
if (compoundTag.contains("flickerAge")) this.setFlickerAge(compoundTag.getInt("flickerAge"));
if (compoundTag.contains("scale")) this.setAnimScale(compoundTag.getFloat("scale"));
if (compoundTag.contains("prevScale")) this.setPrevAnimScale(compoundTag.getFloat("prevScale"));
Expand Down Expand Up @@ -522,6 +523,16 @@ protected void doPush(@NotNull Entity entity) {
protected void pushEntities() {
}

@Override
public void setVariant(FireflyColor color) {
this.setColor(color);
}

@Override
public @NotNull FireflyColor getVariant() {
return this.getColorByLocation();
}

public static class FireflySpawnGroupData implements SpawnGroupData {
public final Holder<FireflyColor> color;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.Shearable;
import net.minecraft.world.entity.SpawnGroupData;
import net.minecraft.world.entity.VariantHolder;
import net.minecraft.world.entity.animal.Cow;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
Expand All @@ -71,7 +72,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class FlowerCow extends Cow implements Shearable {
public class FlowerCow extends Cow implements Shearable, VariantHolder<MoobloomVariant> {
public static final int MAX_FLOWERS = 4;
private static final byte GROW_FLOWER_EVENT_ID = 61;
private static final EntityDataAccessor<String> VARIANT = SynchedEntityData.defineId(FlowerCow.class, EntityDataSerializers.STRING);
Expand Down Expand Up @@ -236,10 +237,16 @@ public MoobloomVariant getVariantForRendering() {
return this.moobloomVariant.orElse(this.registryAccess().registryOrThrow(WilderWildRegistries.MOOBLOOM_VARIANT).get(MoobloomVariants.DEFAULT));
}

@Override
public void setVariant(@NotNull MoobloomVariant variant) {
this.entityData.set(VARIANT, Objects.requireNonNull(this.registryAccess().registryOrThrow(WilderWildRegistries.MOOBLOOM_VARIANT).getKey(variant)).toString());
}

@Override
public @NotNull MoobloomVariant getVariant() {
return this.getVariantByLocation();
}

public void setVariant(@NotNull ResourceLocation variant) {
this.entityData.set(VARIANT, variant.toString());
}
Expand Down
Loading

0 comments on commit 2bf5eba

Please sign in to comment.