From 57ac3e4feebf49614ab5751f29e320a00e12a071 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 14 Oct 2024 21:15:49 +0100 Subject: [PATCH] Partial updates to 1.21.2 --- gradle.properties | 12 ++++---- .../com/minelittlepony/unicopia/Debug.java | 3 +- .../com/minelittlepony/unicopia/USounds.java | 2 +- .../unicopia/WorldConvertable.java | 2 +- .../unicopia/ability/AbilityDispatcher.java | 2 +- .../unicopia/ability/BatEeeeAbility.java | 5 ++-- .../ability/ChangelingFeedAbility.java | 4 +-- .../ability/EarthPonyGrowAbility.java | 13 ++++++-- .../ability/EarthPonyKickAbility.java | 6 ++-- .../ability/EarthPonyStompAbility.java | 6 ++-- .../unicopia/ability/HugAbility.java | 13 ++++---- .../unicopia/ability/PeckAbility.java | 4 +-- .../unicopia/ability/ScreechAbility.java | 5 ++-- .../ability/SeaponySonarPulseAbility.java | 2 +- .../ability/data/tree/TreeTypeLoader.java | 30 +++++-------------- .../client/MixinLivingEntityRenderer.java | 1 - .../mixin/server/MixinServerPlayerEntity.java | 2 +- .../network/MsgRequestSpeciesChange.java | 2 +- .../particle/MagicParticleEffect.java | 2 +- .../particle/SphereParticleEffect.java | 2 +- .../unicopia/recipe/CloudShapingRecipe.java | 9 +++--- .../unicopia/recipe/GlowingRecipe.java | 2 +- .../unicopia/recipe/JarExtractRecipe.java | 4 +-- .../unicopia/recipe/JarInsertRecipe.java | 3 +- .../unicopia/recipe/TransformCropsRecipe.java | 2 +- .../unicopia/server/world/Altar.java | 12 ++++++-- .../server/world/gen/ULootTableEntryType.java | 4 +-- .../unicopia/util/InventoryUtil.java | 2 +- .../unicopia/util/LimbAnimationUtil.java | 4 +-- .../unicopia/util/RegistryUtils.java | 26 ++++++---------- .../minelittlepony/unicopia/util/Untyped.java | 6 ++++ 31 files changed, 99 insertions(+), 93 deletions(-) diff --git a/gradle.properties b/gradle.properties index 2bf8d55d..af67a1cc 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,10 +3,10 @@ org.gradle.daemon=false # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.21.1 - yarn_mappings=1.21.1+build.3 - loader_version=0.16.4 - fabric_version=0.102.0+1.21.1 + minecraft_version=1.21.2-pre3 + yarn_mappings=1.21.2-pre3+build.4 + loader_version=0.16.7 + fabric_version=0.105.4+1.21.2 # Mod Properties group=com.minelittlepony @@ -21,9 +21,9 @@ org.gradle.daemon=false # Dependencies fabwork_version=1.3.2+1.21 - modmenu_version=11.0.0-beta.1 + modmenu_version=12.0.0-beta.1 minelp_version=4.12.0+1.21 - kirin_version=1.20.0+1.21 + kirin_version=1.20.0+1.21.3 trinkets_version=3.10.0 terraformer_api_version=11.0.0-alpha.1 diff --git a/src/main/java/com/minelittlepony/unicopia/Debug.java b/src/main/java/com/minelittlepony/unicopia/Debug.java index 0d45e1c9..c59f2b30 100644 --- a/src/main/java/com/minelittlepony/unicopia/Debug.java +++ b/src/main/java/com/minelittlepony/unicopia/Debug.java @@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity; import com.minelittlepony.unicopia.entity.mob.UEntities; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.registry.Registries; import net.minecraft.registry.tag.TagKey; @@ -34,7 +35,7 @@ public interface Debug { try { for (var type : BoatEntity.Type.values()) { - var balloon = UEntities.AIR_BALLOON.create(world); + var balloon = UEntities.AIR_BALLOON.create(world, SpawnReason.SPAWN_ITEM_USE); balloon.setBasketType(AirBalloonEntity.BasketType.of(type)); balloon.asItem(); } diff --git a/src/main/java/com/minelittlepony/unicopia/USounds.java b/src/main/java/com/minelittlepony/unicopia/USounds.java index cd9fa8f7..ddeda4a2 100644 --- a/src/main/java/com/minelittlepony/unicopia/USounds.java +++ b/src/main/java/com/minelittlepony/unicopia/USounds.java @@ -24,7 +24,7 @@ public interface USounds { SoundEvent ENTITY_PLAYER_EARTHPONY_DASH = ENTITY_RAVAGER_STEP; SoundEvent ENTITY_PLAYER_CHANGELING_BUZZ = register("entity.player.changeling.buzz"); SoundEvent ENTITY_PLAYER_CHANGELING_TRANSFORM = register("entity.player.changeling.transform"); - SoundEvent ENTITY_PLAYER_CHANGELING_FEED = ENTITY_GENERIC_DRINK; + RegistryEntry ENTITY_PLAYER_CHANGELING_FEED = ENTITY_GENERIC_DRINK; SoundEvent ENTITY_PLAYER_CHANGELING_CLIMB = ENTITY_CHICKEN_STEP; SoundEvent ENTITY_PLAYER_UNICORN_TELEPORT = register("entity.player.unicorn.teleport"); SoundEvent ENTITY_PLAYER_KIRIN_RAGE = ENTITY_POLAR_BEAR_WARNING; diff --git a/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java b/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java index 0aa43e57..99e27987 100644 --- a/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java +++ b/src/main/java/com/minelittlepony/unicopia/WorldConvertable.java @@ -18,6 +18,6 @@ public interface WorldConvertable { } default RegistryEntry entryFor(RegistryKey key) { - return asWorld().getRegistryManager().get(key.getRegistryRef()).getEntry(key).orElseThrow(); + return asWorld().getRegistryManager().getOrThrow(key.getRegistryRef()).getEntry(key.getValue()).orElseThrow(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java index b0efd262..748567c7 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java @@ -302,7 +302,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { maxWarmup = compound.getInt("maxWarmup"); maxCooldown = compound.getInt("maxCooldown"); triggered = compound.getBoolean("triggered"); - activeAbility = Abilities.REGISTRY.getOrEmpty(Identifier.of(compound.getString("activeAbility"))); + activeAbility = Abilities.REGISTRY.getOptionalValue(Identifier.of(compound.getString("activeAbility"))); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java index 5222ac16..c2e57eb6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/BatEeeeAbility.java @@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.advancement.UCriteria; import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.player.Pony; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.random.Random; import net.minecraft.world.event.GameEvent; @@ -38,8 +39,8 @@ public class BatEeeeAbility extends ScreechAbility { } } - if (strength > 0.5F && rng.nextInt(SELF_SPOOK_PROBABILITY) == 0) { - player.asEntity().damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), 0.1F); + if (player.asWorld() instanceof ServerWorld sw && strength > 0.5F && rng.nextInt(SELF_SPOOK_PROBABILITY) == 0) { + player.asEntity().damage(sw, player.damageOf(UDamageTypes.BAT_SCREECH, player), 0.1F); UCriteria.SCREECH_SELF.trigger(player.asEntity()); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java index 5106b5ad..50288c03 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java @@ -82,12 +82,12 @@ public class ChangelingFeedAbility implements Ability { if (targets.size() > 0) { new ChangelingFeedingSpell(targets, maximumHealthGain, maximumFoodGain).apply(iplayer); - iplayer.playSound(USounds.ENTITY_PLAYER_CHANGELING_FEED, 0.1F, iplayer.getRandomPitch()); + iplayer.playSound(USounds.ENTITY_PLAYER_CHANGELING_FEED.value(), 0.1F, iplayer.getRandomPitch()); return true; } } - iplayer.playSound(USounds.Vanilla.ENTITY_PLAYER_BURP, 1, (float)player.getWorld().random.nextTriangular(1F, 0.2F)); + iplayer.playSound(USounds.Vanilla.ENTITY_PLAYER_BURP, 1, player.getWorld().random.nextTriangular(1F, 0.2F)); return true; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java index fabeb891..3e20a6cc 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java @@ -3,6 +3,8 @@ package com.minelittlepony.unicopia.ability; import java.util.Optional; import java.util.function.DoubleSupplier; import java.util.function.Supplier; +import java.util.stream.StreamSupport; + import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.ability.data.Pos; @@ -28,6 +30,8 @@ import net.minecraft.item.Items; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; +import net.minecraft.recipe.RecipeEntry; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; @@ -132,10 +136,13 @@ public class EarthPonyGrowAbility implements Ability { return 0; } + @SuppressWarnings("unchecked") private boolean applyDirectly(Pony player, BlockPos pos) { - return player.asWorld().getRecipeManager() - .getAllMatches(URecipes.GROWING, new TransformCropsRecipe.PlacementArea(player, pos), player.asWorld()) - .stream() + var placementArea = new TransformCropsRecipe.PlacementArea(player, pos); + return StreamSupport.stream(((ServerWorld)player.asWorld()).getRecipeManager().values().spliterator(), false) + .filter(recipe -> recipe.value().getType() == URecipes.GROWING) + .map(recipe -> (RecipeEntry)recipe) + .filter(recipe -> recipe.value().matches(placementArea, player.asWorld())) .map(recipe -> recipe.value().checkPattern(player.asWorld(), pos)) .filter(result -> result.matchedLocations().size() + 1 >= TransformCropsRecipe.MINIMUM_INPUT) .filter(result -> { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java index d91909ff..e5eeeeaf 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java @@ -90,7 +90,9 @@ public class EarthPonyKickAbility implements Ability { if (e instanceof LivingEntity entity) { float calculatedStrength = 0.5F * (1 + player.getLevel().getScaled(9)); - entity.damage(player.damageOf(UDamageTypes.KICK, player), player.asWorld().random.nextBetween(2, 10) + calculatedStrength); + if (player.asWorld() instanceof ServerWorld sw) { + entity.damage(sw, player.damageOf(UDamageTypes.KICK, player), player.asWorld().random.nextBetween(2, 10) + calculatedStrength); + } entity.takeKnockback(calculatedStrength, origin.x - entity.getX(), origin.z - entity.getZ()); Living.updateVelocity(entity); player.subtractEnergyCost(3); @@ -109,7 +111,7 @@ public class EarthPonyKickAbility implements Ability { } if (type == ActivationType.DOUBLE_TAP && player.asEntity().isOnGround() && player.getMagicalReserves().getMana().get() > 40) { - player.getPhysics().dashForward((float)player.asWorld().random.nextTriangular(3.5F, 0.3F)); + player.getPhysics().dashForward(player.asWorld().random.nextTriangular(3.5F, 0.3F)); player.subtractEnergyCost(4); player.asEntity().addExhaustion(5); return true; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java index 6fac4764..2f15a703 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java @@ -85,7 +85,7 @@ public class EarthPonyStompAbility implements Ability { public Optional prepare(Pony player) { if (player.asEntity().getVelocity().y * player.getPhysics().getGravitySignum() < 0 && !player.asEntity().getAbilities().flying - && !player.asEntity().isFallFlying() + && !player.asEntity().isGliding() && !player.asEntity().isUsingRiptide()) { thrustDownwards(player); return Hit.INSTANCE; @@ -144,7 +144,7 @@ public class EarthPonyStompAbility implements Ability { -(player.getY() - i.getY() - liftAmount) / inertia + (dist < 1 ? dist : 0), -(player.getZ() - i.getZ()) / inertia); - double amount = (1.5F * player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).getValue() + heavyness * 0.4) / (float)(dist * 1.3F); + double amount = (1.5F * player.getAttributeInstance(EntityAttributes.ATTACK_DAMAGE).getValue() + heavyness * 0.4) / (float)(dist * 1.3F); if (i instanceof PlayerEntity) { Race.Composite race = Pony.of((PlayerEntity)i).getCompositeRace(); @@ -161,7 +161,7 @@ public class EarthPonyStompAbility implements Ability { amount /= EnchantmentUtil.getImpactReduction(l); } - i.damage(iplayer.damageOf(UDamageTypes.SMASH, iplayer), (float)amount); + i.damage((ServerWorld)iplayer.asWorld(), iplayer.damageOf(UDamageTypes.SMASH, iplayer), (float)amount); Living.updateVelocity(i); } }); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/HugAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/HugAbility.java index 46cc8c65..c4c528cf 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/HugAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/HugAbility.java @@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.entity.mob.FriendlyCreeperEntity; import com.minelittlepony.unicopia.entity.mob.UEntities; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.conversion.EntityConversionContext; import net.minecraft.entity.mob.CreeperEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.particle.ParticleTypes; @@ -25,11 +26,13 @@ public class HugAbility extends CarryAbility { pony.setAnimation(Animation.ARMS_FORWARD, Animation.Recipient.ANYONE); if (rider instanceof CreeperEntity creeper) { - FriendlyCreeperEntity friendlyCreeper = creeper.convertTo(UEntities.FRIENDLY_CREEPER, true); - player.getWorld().spawnEntity(friendlyCreeper); - - friendlyCreeper.startRiding(player, true); - Living.getOrEmpty(friendlyCreeper).ifPresent(living -> living.setCarrier(player)); + FriendlyCreeperEntity friendlyCreeper = creeper.convertTo(UEntities.FRIENDLY_CREEPER, EntityConversionContext.create(creeper, true, true), e -> { + e.startRiding(player, true); + Living.getOrEmpty(e).ifPresent(living -> living.setCarrier(player)); + }); + if (friendlyCreeper != null) { + player.getWorld().spawnEntity(friendlyCreeper); + } } else if (rider instanceof FriendlyCreeperEntity creeper) { creeper.startRiding(player, true); Living.getOrEmpty(creeper).ifPresent(living -> living.setCarrier(player)); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java index 19a7d246..5a38361e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java @@ -125,8 +125,8 @@ public class PeckAbility implements Ability { boolean isEarthPony = EquinePredicates.PLAYER_EARTH.test(living); boolean isBracing = isEarthPony && player.asEntity().isSneaking(); - if (!isBracing) { - living.damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F); + if (!isBracing && living.getWorld() instanceof ServerWorld sw) { + living.damage(sw, player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F); } Vec3d knockVec = player.getOriginVector().subtract(living.getPos()).multiply(strength); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java index 196a6bb3..4ac772de 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java @@ -20,6 +20,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.random.Random; @@ -103,12 +104,12 @@ public class ScreechAbility implements Ability { boolean isBracing = isEarthPony && player.asEntity().isSneaking(); if (!isBracing) { - living.damage(player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F); + living.damage((ServerWorld)player.asWorld(), player.damageOf(UDamageTypes.BAT_SCREECH, player), isEarthPony ? 0.1F : 0.3F); if (living.getWorld().random.nextInt(MOB_SPOOK_PROBABILITY) == 0) { RegistryUtils.pickRandom(living.getWorld(), UTags.Items.SPOOKED_MOB_DROPS).ifPresent(drop -> { - living.dropStack(drop.getDefaultStack()); + living.dropStack((ServerWorld)living.getWorld(), drop.getDefaultStack()); living.playSound(USounds.Vanilla.ENTITY_ITEM_PICKUP, 1, 0.1F); UCriteria.SPOOK_MOB.trigger(player.asEntity()); }); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java index 190745d9..7407a80c 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java @@ -67,7 +67,7 @@ public class SeaponySonarPulseAbility implements Ability { if (distance < 4) { float scale = 1 - (distance/10F); ((LivingEntity)target).takeKnockback(0.7 * scale, -offset.x, -offset.z); - target.damage(target.getDamageSources().sonicBoom(player.asEntity()), 10 * scale); + target.damage((ServerWorld)target.getWorld(), target.getDamageSources().sonicBoom(player.asEntity()), 10 * scale); } else { emitPing(player, target.getPos(), 10, 1, 1.3F); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/data/tree/TreeTypeLoader.java b/src/main/java/com/minelittlepony/unicopia/ability/data/tree/TreeTypeLoader.java index d5b9e588..a1247a69 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/data/tree/TreeTypeLoader.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/data/tree/TreeTypeLoader.java @@ -2,17 +2,13 @@ package com.minelittlepony.unicopia.ability.data.tree; import java.util.*; import java.util.function.Supplier; -import com.google.gson.JsonElement; import com.minelittlepony.unicopia.Unicopia; -import com.minelittlepony.unicopia.util.Resources; import com.minelittlepony.unicopia.util.Weighted; import com.minelittlepony.unicopia.util.serialization.CodecUtils; import com.mojang.serialization.Codec; -import com.mojang.serialization.JsonOps; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; @@ -23,10 +19,9 @@ import net.minecraft.util.Identifier; import net.minecraft.util.profiler.Profiler; import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryKeys; -import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.TagKey; -public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResourceReloadListener { +public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResourceReloadListener { private static final Identifier ID = Unicopia.id("data/tree_type"); public static final TreeTypeLoader INSTANCE = new TreeTypeLoader(); @@ -34,7 +29,7 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour private Map entries = new HashMap<>(); TreeTypeLoader() { - super(Resources.GSON, "tree_types"); + super(TreeTypeDef.CODEC, "tree_types"); } public Map getEntries() { @@ -46,18 +41,9 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour return ID; } - @SuppressWarnings("unchecked") @Override - protected void apply(Map resources, ResourceManager manager, Profiler profiler) { - entries = Map.ofEntries(resources.entrySet().stream() - .filter(Objects::nonNull) - .map(entry -> TreeTypeDef.CODEC.decode(JsonOps.INSTANCE, entry.getValue()) - .result() - .map(p -> p.getFirst()) - .map(p -> Map.entry(entry.getKey(), p)) - .orElse(null)) - .filter(Objects::nonNull) - .toArray(Map.Entry[]::new)); + protected void apply(Map resources, ResourceManager manager, Profiler profiler) { + entries = resources; TreeTypes.load(entries); } @@ -120,15 +106,13 @@ public class TreeTypeLoader extends JsonDataLoader implements IdentifiableResour @Override public void appendTo(Weighted.Builder> weighted) { if (item.isPresent()) { - Registries.ITEM.getOrEmpty(item.get()).ifPresent(item -> { + Registries.ITEM.getOptionalValue(item.get()).ifPresent(item -> { weighted.put(weight, item::getDefaultStack); }); } else { weighted.put(weight, () -> { - return Registries.ITEM.getOrCreateEntryList(TagKey.of(RegistryKeys.ITEM, tag.get())) - .getRandom(Weighted.getRng()) - .map(RegistryEntry::value) - .map(Item::getDefaultStack) + return Registries.ITEM.getRandomEntry(TagKey.of(RegistryKeys.ITEM, tag.get()), Weighted.getRng()) + .map(entry -> entry.value().getDefaultStack()) .orElse(ItemStack.EMPTY); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinLivingEntityRenderer.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinLivingEntityRenderer.java index 6f915b70..2f0c71c9 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinLivingEntityRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinLivingEntityRenderer.java @@ -34,7 +34,6 @@ abstract class MixinLivingEntityRenderer> features; - MixinLivingEntityRenderer() { super(null); } @Nullable private AccessoryFeatureRenderer accessories; diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinServerPlayerEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinServerPlayerEntity.java index 4e4885a2..4b42d17e 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinServerPlayerEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/server/MixinServerPlayerEntity.java @@ -51,7 +51,7 @@ abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHan target = "net/minecraft/entity/player/PlayerEntity$SleepFailureReason.NOT_POSSIBLE_NOW:Lnet/minecraft/entity/player/PlayerEntity$SleepFailureReason;" ), cancellable = true, require = 0) private void onTrySleep(BlockPos pos, CallbackInfoReturnable> info) { - if (get().getSpecies().isNocturnal() && get().asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES)) { + if (get().getSpecies().isNocturnal() && ((ServerWorld)get().asWorld()).getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES)) { ((PlayerEntity)this).sendMessage(Text.translatable("block.unicopia.bed.no_sleep.nocturnal"), true); info.setReturnValue(Either.left(PlayerEntity.SleepFailureReason.OTHER_PROBLEM)); diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java index 06c48936..04c9c11b 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java @@ -39,7 +39,7 @@ public record MsgRequestSpeciesChange ( } if (force) { - if (sender.getWorld().getGameRules().getBoolean(UGameRules.ANNOUNCE_TRIBE_JOINS)) { + if (((ServerWorld)sender.getWorld()).getGameRules().getBoolean(UGameRules.ANNOUNCE_TRIBE_JOINS)) { Text message = Text.translatable("respawn.reason.joined_new_tribe", sender.getDisplayName(), player.getSpecies().getDisplayName(), player.getSpecies().getAltDisplayName()); diff --git a/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java index 9d4e66f2..e0304456 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java @@ -26,7 +26,7 @@ public record MagicParticleEffect ( ).apply(instance, MagicParticleEffect::new)); public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( PacketCodecs.BOOL, MagicParticleEffect::tinted, - PacketCodecs.VECTOR3F, MagicParticleEffect::color, + PacketCodecs.VECTOR_3F, MagicParticleEffect::color, MagicParticleEffect::new ); diff --git a/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java index 2affbc64..37ba765a 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java @@ -36,7 +36,7 @@ public record SphereParticleEffect ( public static final PacketCodec createPacketCodec(ParticleType type) { return PacketCodec.tuple( - PacketCodecs.VECTOR3F, SphereParticleEffect::color, + PacketCodecs.VECTOR_3F, SphereParticleEffect::color, PacketCodecs.FLOAT, SphereParticleEffect::alpha, PacketCodecs.FLOAT, SphereParticleEffect::radius, PacketCodecUtils.VECTOR, SphereParticleEffect::offset, diff --git a/src/main/java/com/minelittlepony/unicopia/recipe/CloudShapingRecipe.java b/src/main/java/com/minelittlepony/unicopia/recipe/CloudShapingRecipe.java index 3272fdc9..754b888e 100644 --- a/src/main/java/com/minelittlepony/unicopia/recipe/CloudShapingRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/recipe/CloudShapingRecipe.java @@ -1,6 +1,7 @@ package com.minelittlepony.unicopia.recipe; import com.minelittlepony.unicopia.block.UBlocks; +import com.minelittlepony.unicopia.util.Untyped; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Ingredient; @@ -19,13 +20,13 @@ public class CloudShapingRecipe extends StonecuttingRecipe { } @Override - public RecipeType getType() { - return URecipes.CLOUD_SHAPING; + public RecipeType getType() { + return Untyped.cast(URecipes.CLOUD_SHAPING); } @Override - public RecipeSerializer getSerializer() { - return URecipes.CLOUD_SHAPING_SERIALIZER; + public RecipeSerializer getSerializer() { + return Untyped.cast(URecipes.CLOUD_SHAPING_SERIALIZER); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/recipe/GlowingRecipe.java b/src/main/java/com/minelittlepony/unicopia/recipe/GlowingRecipe.java index 49ce5cb7..c154261d 100644 --- a/src/main/java/com/minelittlepony/unicopia/recipe/GlowingRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/recipe/GlowingRecipe.java @@ -43,7 +43,7 @@ public class GlowingRecipe extends ItemCombinationRecipe { } @Override - public RecipeSerializer getSerializer() { + public RecipeSerializer getSerializer() { return URecipes.GLOWING_SERIALIZER; } } diff --git a/src/main/java/com/minelittlepony/unicopia/recipe/JarExtractRecipe.java b/src/main/java/com/minelittlepony/unicopia/recipe/JarExtractRecipe.java index 41072228..6774972b 100644 --- a/src/main/java/com/minelittlepony/unicopia/recipe/JarExtractRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/recipe/JarExtractRecipe.java @@ -31,7 +31,7 @@ public class JarExtractRecipe extends SpecialCraftingRecipe { @Override public ItemStack craft(CraftingRecipeInput inventory, @Nullable WrapperLookup manager) { ItemStack jar = ItemStack.EMPTY; - for (int i = 0; i < inventory.getSize(); i++) { + for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStackInSlot(i); if (stack.isEmpty()) { continue; @@ -56,7 +56,7 @@ public class JarExtractRecipe extends SpecialCraftingRecipe { } @Override - public RecipeSerializer getSerializer() { + public RecipeSerializer getSerializer() { return URecipes.JAR_INSERT_SERIALIZER; } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/recipe/JarInsertRecipe.java b/src/main/java/com/minelittlepony/unicopia/recipe/JarInsertRecipe.java index 4a0f7300..2d8354cb 100644 --- a/src/main/java/com/minelittlepony/unicopia/recipe/JarInsertRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/recipe/JarInsertRecipe.java @@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.item.component.Appearance; import net.minecraft.item.ItemStack; import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.SpecialCraftingRecipe; import net.minecraft.recipe.book.CraftingRecipeCategory; import net.minecraft.recipe.input.CraftingRecipeInput; import net.minecraft.registry.RegistryWrapper.WrapperLookup; @@ -38,7 +39,7 @@ public class JarInsertRecipe extends ItemCombinationRecipe { } @Override - public RecipeSerializer getSerializer() { + public RecipeSerializer getSerializer() { return URecipes.JAR_INSERT_SERIALIZER; } diff --git a/src/main/java/com/minelittlepony/unicopia/recipe/TransformCropsRecipe.java b/src/main/java/com/minelittlepony/unicopia/recipe/TransformCropsRecipe.java index bfbb0af1..73b204d6 100644 --- a/src/main/java/com/minelittlepony/unicopia/recipe/TransformCropsRecipe.java +++ b/src/main/java/com/minelittlepony/unicopia/recipe/TransformCropsRecipe.java @@ -137,7 +137,7 @@ public class TransformCropsRecipe implements Recipe { - FloatingArtefactEntity artefact = UEntities.FLOATING_ARTEFACT.create(world); + FloatingArtefactEntity artefact = UEntities.FLOATING_ARTEFACT.create(world, SpawnReason.NATURAL); artefact.setStack(UItems.ALICORN_BADGE.getDefaultStack()); artefact.setPosition(pillar.up().toCenterPos()); artefact.setInvulnerable(true); @@ -159,7 +161,13 @@ public record Altar( } private void removeExisting(@Nullable Entity except, World world, BlockPos pillar) { - world.getOtherEntities(except, new Box(pillar.up()), IS_PARTICIPANT).forEach(Entity::kill); + world.getOtherEntities(except, new Box(pillar.up()), IS_PARTICIPANT).forEach(e -> { + if (world instanceof ServerWorld sw) { + e.kill(sw); + } else { + e.setRemoved(RemovalReason.KILLED); + } + }); } public boolean isValid(World world) { diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/gen/ULootTableEntryType.java b/src/main/java/com/minelittlepony/unicopia/server/world/gen/ULootTableEntryType.java index ff0b3091..d96a6d1a 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/gen/ULootTableEntryType.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/gen/ULootTableEntryType.java @@ -19,8 +19,8 @@ public interface ULootTableEntryType { }); LootTableEvents.ALL_LOADED.register((resourceManager, registry) -> { extentionTableIds.forEach((base, extra) -> { - registry.getOrEmpty(base).ifPresent(table -> { - registry.getOrEmpty(extra).ifPresent(extraTable -> { + registry.getOptionalValue(base).ifPresent(table -> { + registry.getOptionalValue(extra).ifPresent(extraTable -> { table.pools = Stream.concat(table.pools.stream(), extraTable.pools.stream()).toList(); }); }); diff --git a/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java b/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java index 3effe008..3c76665e 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/util/InventoryUtil.java @@ -21,7 +21,7 @@ public interface InventoryUtil { } static Stream slots(RecipeInput inventory) { - return Stream.iterate(0, i -> i < inventory.getSize(), i -> i + 1); + return Stream.iterate(0, i -> i < inventory.size(), i -> i + 1); } static int getOpenSlot(Inventory inventory) { diff --git a/src/main/java/com/minelittlepony/unicopia/util/LimbAnimationUtil.java b/src/main/java/com/minelittlepony/unicopia/util/LimbAnimationUtil.java index 1299a0fc..9f2e01f9 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/LimbAnimationUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/util/LimbAnimationUtil.java @@ -6,7 +6,7 @@ public interface LimbAnimationUtil { static void resetToZero(LimbAnimator animator) { animator.setSpeed(0); - animator.updateLimbs(-animator.getPos(), 1); + animator.updateLimbs(-animator.getPos(), 1, 1); animator.setSpeed(0); } @@ -17,7 +17,7 @@ public interface LimbAnimationUtil { resetToZero(to); to.setSpeed(prevSpeed); - to.updateLimbs(pos, 1); + to.updateLimbs(pos, 1, 1); to.setSpeed(speed); } } diff --git a/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java b/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java index 7d7dce90..d8d8504e 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java @@ -15,7 +15,6 @@ import net.minecraft.util.Util; import net.minecraft.registry.*; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntryList; -import net.minecraft.registry.entry.RegistryEntryList.Named; import net.minecraft.world.World; public interface RegistryUtils { @@ -35,8 +34,12 @@ public interface RegistryUtils { .buildAndRegister(); } + @SuppressWarnings("unchecked") static RegistryEntryList entriesForTag(World world, TagKey key) { - return world.getRegistryManager().get(key.registry()).getOrCreateEntryList(key); + return world.getRegistryManager().getOrThrow(key.registryRef()) + .getOptional(key) + .map(RegistryEntryList.class::cast) + .orElse(RegistryEntryList.empty()); } static Stream valuesForTag(World world, TagKey key) { @@ -52,29 +55,18 @@ public interface RegistryUtils { } static Optional pickRandom(World world, TagKey key, Predicate filter) { - return Util.getRandomOrEmpty(world.getRegistryManager().getOptional(key.registry()) - .flatMap(registry -> registry.getEntryList(key)) - .stream() - .flatMap(Named::stream) - .map(RegistryEntry::value) - .filter(filter) - .toList(), world.random); + return Util.getRandomOrEmpty(entriesForTag(world, key).stream().map(RegistryEntry::value).filter(filter).toList(), world.random); } static Optional> pickRandomEntry(World world, TagKey key, Predicate> filter) { - return Util.getRandomOrEmpty(world.getRegistryManager().getOptional(key.registry()) - .flatMap(registry -> registry.getEntryList(key)) - .stream() - .flatMap(Named::stream) - .filter(filter) - .toList(), world.random); + return Util.getRandomOrEmpty(entriesForTag(world, key).stream().filter(filter).toList(), world.random); } static boolean isIn(World world, T obj, RegistryKey> registry, TagKey tag) { - return world.getRegistryManager().get(registry).getEntry(obj).isIn(tag); + return world.getRegistryManager().getOrThrow(registry).getEntry(obj).isIn(tag); } static Identifier getId(World world, T obj, RegistryKey> registry) { - return world.getRegistryManager().get(registry).getId(obj); + return world.getRegistryManager().getOrThrow(registry).getId(obj); } } diff --git a/src/main/java/com/minelittlepony/unicopia/util/Untyped.java b/src/main/java/com/minelittlepony/unicopia/util/Untyped.java index 08ee24e1..47156177 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/Untyped.java +++ b/src/main/java/com/minelittlepony/unicopia/util/Untyped.java @@ -1,8 +1,14 @@ package com.minelittlepony.unicopia.util; +import java.util.Optional; + public interface Untyped { @SuppressWarnings("unchecked") static T cast(K t) { return (T)t; } + + static Optional cast(Optional t) { + return t.map(Untyped::cast); + } }