From e06c6108f5671bb127da68d6b8ecef4882101066 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 14 Oct 2024 22:09:00 +0100 Subject: [PATCH] More 1.21.2 updates --- .../spell/effect/CustomisedSpellType.java | 2 +- .../unicopia/block/ItemJarBlock.java | 15 +++---- .../unicopia/block/jar/EntityJarContents.java | 7 +-- .../unicopia/block/zap/ElectrifiedBlock.java | 9 ++-- .../unicopia/entity/mob/ButterflyEntity.java | 2 +- .../unicopia/entity/mob/CastSpellEntity.java | 11 ++++- .../entity/mob/FloatingArtefactEntity.java | 3 +- .../unicopia/entity/mob/StormCloudEntity.java | 16 +++---- .../unicopia/entity/player/Acrobatics.java | 2 +- .../entity/player/ManaConsumptionUtil.java | 5 ++- .../entity/player/PlayerAttributes.java | 20 ++++----- .../entity/player/PlayerCharmTracker.java | 2 +- .../unicopia/entity/player/PlayerPhysics.java | 43 +++++++++++-------- .../unicopia/entity/player/Pony.java | 10 ++--- .../unicopia/item/EmptyJarItem.java | 7 +-- .../unicopia/item/EnchantableItem.java | 6 +-- .../unicopia/item/WeatherJarItem.java | 8 ++-- .../unicopia/item/cloud/CloudBlockItem.java | 12 +----- .../component/BreaksIntoItemComponent.java | 4 +- .../item/enchantment/EnchantmentUtil.java | 4 +- .../projectile/MagicProjectileEntity.java | 10 ++--- .../PhysicsBodyProjectileEntity.java | 6 +-- .../unicopia/projectile/Projectile.java | 6 +-- .../server/world/FeatureRegistry.java | 2 +- .../unicopia/server/world/Tree.java | 7 +-- .../unicopia/server/world/UWorldGen.java | 2 +- .../server/world/ZapAppleStageStore.java | 3 +- .../unicopia/util/ColorHelper.java | 15 ++++--- .../unicopia/util/Dispensable.java | 10 ++--- .../unicopia/util/TypedActionResult.java | 17 ++++++++ .../util/registry/DynamicRegistry.java | 2 +- 31 files changed, 148 insertions(+), 120 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/util/TypedActionResult.java diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java index c8229747..5e2ae45a 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/CustomisedSpellType.java @@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.Spell; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.client.TextHelper; import com.minelittlepony.unicopia.entity.effect.EffectUtils; +import com.minelittlepony.unicopia.util.TypedActionResult; import net.minecraft.item.Item.TooltipContext; import net.minecraft.item.ItemStack; @@ -25,7 +26,6 @@ import net.minecraft.registry.RegistryWrapper.WrapperLookup; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; -import net.minecraft.util.TypedActionResult; public record CustomisedSpellType ( SpellType type, diff --git a/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java index 5db566f6..af73fafa 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java @@ -5,6 +5,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.block.jar.EntityJarContents; import com.minelittlepony.unicopia.block.jar.FluidOnlyJarContents; import com.minelittlepony.unicopia.block.jar.ItemsJarContents; +import com.minelittlepony.unicopia.util.TypedActionResult; import com.mojang.serialization.MapCodec; import com.minelittlepony.unicopia.block.jar.FakeFluidJarContents; @@ -29,8 +30,6 @@ import net.minecraft.registry.RegistryWrapper.WrapperLookup; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.ItemActionResult; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -54,11 +53,11 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven } @Override - protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + protected ActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { if (hand == Hand.OFF_HAND) { - return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + return ActionResult.PASS_TO_DEFAULT_BLOCK_ACTION; } - return world.getBlockEntity(pos, UBlockEntities.ITEM_JAR).map(data -> data.interact(player, hand)).orElse(ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION); + return world.getBlockEntity(pos, UBlockEntities.ITEM_JAR).map(data -> data.interact(player, hand)).orElse(ActionResult.PASS_TO_DEFAULT_BLOCK_ACTION); } @Override @@ -110,10 +109,10 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven super(UBlockEntities.ITEM_JAR, pos, state); } - public ItemActionResult interact(PlayerEntity player, Hand hand) { + public ActionResult interact(PlayerEntity player, Hand hand) { TypedActionResult result = contents.interact(player, hand); - contents = result.getValue(); - return result.getResult().isAccepted() ? ItemActionResult.SUCCESS : result.getResult() == ActionResult.FAIL ? ItemActionResult.FAIL : ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; + contents = result.value(); + return result.result().isAccepted() ? ActionResult.SUCCESS : result.result() == ActionResult.FAIL ? ActionResult.FAIL : ActionResult.PASS_TO_DEFAULT_BLOCK_ACTION; } public JarContents getContents() { diff --git a/src/main/java/com/minelittlepony/unicopia/block/jar/EntityJarContents.java b/src/main/java/com/minelittlepony/unicopia/block/jar/EntityJarContents.java index cfb6c2e2..9bb277c3 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/jar/EntityJarContents.java +++ b/src/main/java/com/minelittlepony/unicopia/block/jar/EntityJarContents.java @@ -8,12 +8,14 @@ import com.google.common.base.Suppliers; import com.minelittlepony.unicopia.block.ItemJarBlock.FluidJarContents; import com.minelittlepony.unicopia.block.ItemJarBlock.JarContents; import com.minelittlepony.unicopia.block.ItemJarBlock.TileData; +import com.minelittlepony.unicopia.util.TypedActionResult; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.minecraft.block.Blocks; import net.minecraft.entity.Bucketable; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemStack; @@ -23,7 +25,6 @@ import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryWrapper.WrapperLookup; import net.minecraft.util.Hand; import net.minecraft.util.Identifier; -import net.minecraft.util.TypedActionResult; public record EntityJarContents ( TileData tile, @@ -31,7 +32,7 @@ public record EntityJarContents ( Supplier<@Nullable Entity> entity ) implements FluidJarContents { public EntityJarContents(TileData tile, NbtCompound compound) { - this(tile, Registries.ENTITY_TYPE.getOrEmpty(Identifier.tryParse(compound.getString("entity"))).orElse(null)); + this(tile, Registries.ENTITY_TYPE.getOptionalValue(Identifier.tryParse(compound.getString("entity"))).orElse(null)); } public EntityJarContents(TileData tile) { @@ -40,7 +41,7 @@ public record EntityJarContents ( public EntityJarContents(TileData tile, EntityType entityType) { this(tile, entityType, Suppliers.memoize(() -> { - return entityType == null ? null : entityType.create(tile.getWorld()); + return entityType == null ? null : entityType.create(tile.getWorld(), SpawnReason.LOAD); })); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/zap/ElectrifiedBlock.java b/src/main/java/com/minelittlepony/unicopia/block/zap/ElectrifiedBlock.java index bba75e5b..aa5b12c3 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/zap/ElectrifiedBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/zap/ElectrifiedBlock.java @@ -12,6 +12,7 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.LightningEntity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; @@ -44,7 +45,7 @@ public interface ElectrifiedBlock { default void triggerLightning(BlockState state, World world, BlockPos pos) { Vec3d center = pos.toCenterPos(); if (world instanceof ServerWorld serverWorld) { - LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(world); + LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(world, SpawnReason.EVENT); world.getOtherEntities(null, Box.from(center).expand(7)).forEach(entity -> { shockEntity(serverWorld, center, lightning, entity); }); @@ -56,7 +57,7 @@ public interface ElectrifiedBlock { default void triggerLightning(BlockState state, World world, BlockPos pos, LivingEntity entity, boolean knockBack) { Vec3d center = pos.toCenterPos(); if (world instanceof ServerWorld serverWorld) { - shockEntity(serverWorld, center, EntityType.LIGHTNING_BOLT.create(world), entity); + shockEntity(serverWorld, center, EntityType.LIGHTNING_BOLT.create(world, SpawnReason.EVENT), entity); } if (knockBack) { Vec3d offset = center.subtract(entity.getPos()); @@ -72,11 +73,11 @@ public interface ElectrifiedBlock { } float dist = (float)entity.getPos().distanceTo(center); if (dist < 4) { - entity.onStruckByLightning(serverWorld, EntityType.LIGHTNING_BOLT.create(serverWorld)); + entity.onStruckByLightning(serverWorld, EntityType.LIGHTNING_BOLT.create(serverWorld, SpawnReason.EVENT)); } else { float damage = 3 / dist; if (damage > 1) { - entity.damage(entity.getDamageSources().lightningBolt(), damage); + entity.damage(serverWorld, entity.getDamageSources().lightningBolt(), damage); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java index b64aed67..2d882e71 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java @@ -69,7 +69,7 @@ public class ButterflyEntity extends AmbientEntity { } public static DefaultAttributeContainer.Builder createButterflyAttributes() { - return createMobAttributes().add(EntityAttributes.GENERIC_MAX_HEALTH, 2); + return createMobAttributes().add(EntityAttributes.MAX_HEALTH, 2); } public static boolean canSpawn(EntityType type, WorldAccess world, SpawnReason spawnReason, BlockPos pos, Random random) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java index ab6a367c..f5691fba 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java @@ -26,11 +26,13 @@ import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.DataTracker.Builder; import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.world.ServerWorld; import net.minecraft.text.Text; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; @@ -139,7 +141,7 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster { @@ -157,7 +159,12 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster table = getType().getLootTableId(); - LootContextParameterSet.Builder builder = new LootContextParameterSet.Builder((ServerWorld)this.getWorld()) + if (!world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) { + Optional> table = getType().getLootTableKey(); + LootContextParameterSet.Builder builder = new LootContextParameterSet.Builder(world) .add(LootContextParameters.THIS_ENTITY, this) .add(LootContextParameters.ORIGIN, this.getPos()) .add(LootContextParameters.DAMAGE_SOURCE, source) @@ -310,7 +310,7 @@ public class StormCloudEntity extends Entity implements MagicImmune { getRegistryManager().get(RegistryKeys.LOOT_TABLE).get(table) .generateLoot(builder.build(LootContextTypes.ENTITY), 0L, this::dropStack); } - kill(); + kill(world); getWorld().sendEntityStatus(this, EntityStatuses.ADD_DEATH_PARTICLES); } else { split(2 + random.nextInt(4)); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java index f99d5213..fd7f328f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java @@ -166,7 +166,7 @@ public class Acrobatics implements Tickable, NbtSerialisable { entity.setPosition(pos.getX() + 0.5, pos.getY() - (inverted ? 0 : 1), pos.getZ() + 0.5); entity.setVelocity(Vec3d.ZERO); entity.setSneaking(false); - entity.stopFallFlying(); + entity.stopGliding(); pony.getPhysics().cancelFlight(true); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaConsumptionUtil.java b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaConsumptionUtil.java index fb8991e6..6f95de9f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaConsumptionUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaConsumptionUtil.java @@ -5,6 +5,7 @@ import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import net.minecraft.entity.player.HungerManager; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.world.ServerWorld; public interface ManaConsumptionUtil { float MANA_PER_FOOD = 10F; @@ -62,8 +63,8 @@ public interface ManaConsumptionUtil { float consumedHearts = Math.max(0, Math.min(availableHearts - 1, foodSubtract * HEARTS_PER_FOOD)); foodSubtract = addExhaustion(hunger, foodSubtract); foodSubtract -= (consumedHearts / HEARTS_PER_FOOD); - if (consumedHearts > 0) { - entity.damage(UDamageSources.of(entity.getWorld()).damageOf(UDamageTypes.EXHAUSTION), consumedHearts); + if (consumedHearts > 0 && !entity.getWorld().isClient) { + entity.damage((ServerWorld)entity.getWorld(), UDamageSources.of(entity.getWorld()).damageOf(UDamageTypes.EXHAUSTION), consumedHearts); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java index dad3d817..6a6b41c2 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java @@ -22,12 +22,12 @@ public class PlayerAttributes implements Tickable { private final static List ATTRIBUTES = List.of( new ToggleableAttribute( new EntityAttributeModifier(Unicopia.id("earth_pony_strength"), 0.6, Operation.ADD_MULTIPLIED_TOTAL), - List.of(EntityAttributes.GENERIC_ATTACK_DAMAGE, EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE), + List.of(EntityAttributes.ATTACK_DAMAGE, EntityAttributes.KNOCKBACK_RESISTANCE), pony -> pony.getCompositeRace().canUseEarth() ), new ToggleableAttribute( new EntityAttributeModifier(Unicopia.id("earth_pony_knockback_resistance"), 6, Operation.ADD_VALUE), - List.of(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE), + List.of(EntityAttributes.KNOCKBACK_RESISTANCE), pony -> pony.getCompositeRace().canUseEarth() && pony.asEntity().isSneaking() ), new ToggleableAttribute( @@ -38,7 +38,7 @@ public class PlayerAttributes implements Tickable { new ToggleableAttribute( new EntityAttributeModifier(Unicopia.id("pegasus_speed"), 0.2, Operation.ADD_MULTIPLIED_TOTAL), - List.of(EntityAttributes.GENERIC_MOVEMENT_SPEED, EntityAttributes.GENERIC_ATTACK_SPEED), + List.of(EntityAttributes.MOVEMENT_SPEED, EntityAttributes.ATTACK_SPEED), pony -> pony.getCompositeRace().canFly() && !pony.getCompositeRace().includes(Race.HIPPOGRIFF) ), new ToggleableAttribute( @@ -49,7 +49,7 @@ public class PlayerAttributes implements Tickable { new ToggleableAttribute( new EntityAttributeModifier(Unicopia.id("hippogriff_speed"), 0.1, Operation.ADD_MULTIPLIED_TOTAL), - List.of(EntityAttributes.GENERIC_MOVEMENT_SPEED, EntityAttributes.GENERIC_ATTACK_SPEED), + List.of(EntityAttributes.MOVEMENT_SPEED, EntityAttributes.ATTACK_SPEED), pony -> pony.getCompositeRace().includes(Race.HIPPOGRIFF) ), new ToggleableAttribute( @@ -60,16 +60,16 @@ public class PlayerAttributes implements Tickable { new ToggleableAttribute( new EntityAttributeModifier(Unicopia.id("kirin_knockback_vulneravility"), -2, Operation.ADD_VALUE), - List.of(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE), + List.of(EntityAttributes.KNOCKBACK_RESISTANCE), pony -> pony.getCompositeRace().includes(Race.KIRIN) ), new ToggleableAttribute( new EntityAttributeModifier(Unicopia.id("kirin_rage"), 0.7, Operation.ADD_MULTIPLIED_TOTAL), - List.of(EntityAttributes.GENERIC_MOVEMENT_SPEED, - EntityAttributes.GENERIC_ATTACK_SPEED, - EntityAttributes.GENERIC_ATTACK_DAMAGE, - EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, - EntityAttributes.GENERIC_ATTACK_KNOCKBACK + List.of(EntityAttributes.MOVEMENT_SPEED, + EntityAttributes.ATTACK_SPEED, + EntityAttributes.ATTACK_DAMAGE, + EntityAttributes.KNOCKBACK_RESISTANCE, + EntityAttributes.ATTACK_KNOCKBACK ), SpellType.RAGE::isOn ) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java index 30e38a66..7b57c630 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerCharmTracker.java @@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellTyp import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.item.EnchantableItem; import com.minelittlepony.unicopia.util.Copyable; +import com.minelittlepony.unicopia.util.TypedActionResult; import com.minelittlepony.unicopia.util.serialization.NbtSerialisable; import net.minecraft.nbt.NbtCompound; @@ -15,7 +16,6 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtList; import net.minecraft.registry.RegistryWrapper.WrapperLookup; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; public class PlayerCharmTracker implements NbtSerialisable, Copyable { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 8c8abb5a..99d157a2 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -41,6 +41,7 @@ import net.minecraft.block.*; import net.minecraft.entity.EntityType; import net.minecraft.entity.LightningEntity; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.nbt.NbtCompound; @@ -138,7 +139,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab @Override public boolean isFlying() { return isFlyingSurvival - && !entity.isFallFlying() + && !entity.isGliding() && !entity.hasVehicle() && !entity.getAbilities().creativeMode && !entity.isSpectator(); @@ -299,7 +300,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab && ticksInAir > 90) { entity.getWorld().playSoundFromEntity(null, entity, USounds.Vanilla.ENTITY_PLAYER_BIG_FALL, SoundCategory.PLAYERS, 2, 1F); - entity.damage(entity.getDamageSources().generic(), 3); + entity.damage((ServerWorld)entity.getWorld(), entity.getDamageSources().generic(), 3); cancelFlight(true); } } @@ -394,7 +395,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab entity.setVelocity(velocity.toImmutable()); - if (isFlying() && !entity.isFallFlying() && !pony.getAcrobatics().isHanging() && pony.isClient()) { + if (isFlying() && !entity.isGliding() && !pony.getAcrobatics().isHanging() && pony.isClient()) { if (!MineLPDelegate.getInstance().getPlayerPonyRace(entity).isEquine() && getHorizontalMotion() > 0.03) { float pitch = ((LivingEntityDuck)entity).getLeaningPitch(); if (pitch < 1) { @@ -465,12 +466,16 @@ public class PlayerPhysics extends EntityPhysics implements Tickab applyThrust(velocity); } else if (entity.getWorld().random.nextInt(40) == 0) { entity.getWorld().playSoundFromEntity(null, entity, USounds.Vanilla.ENTITY_PLAYER_BIG_FALL, SoundCategory.PLAYERS, 2, 1.5F); - entity.damage(entity.getDamageSources().generic(), 0.5F); + if (!entity.getWorld().isClient) { + entity.damage((ServerWorld)entity.getWorld(), entity.getDamageSources().generic(), 0.5F); + } } if (type.isAvian() && !entity.getWorld().isClient) { if (pony.getObservedSpecies() != Race.BAT && entity.getWorld().random.nextInt(9000) == 0) { - entity.dropItem(pony.getObservedSpecies() == Race.HIPPOGRIFF ? UItems.GRYPHON_FEATHER : UItems.PEGASUS_FEATHER); + if (!entity.getWorld().isClient) { + entity.dropItem((pony.getObservedSpecies() == Race.HIPPOGRIFF ? UItems.GRYPHON_FEATHER : UItems.PEGASUS_FEATHER).getDefaultStack(), false); + } playSound(USounds.ENTITY_PLAYER_PEGASUS_MOLT, 0.3F, 1); UCriteria.SHED_FEATHER.trigger(entity); } @@ -574,7 +579,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab } if (pony.getMagicalReserves().getExhaustion().getPercentFill() > 0.99F && ticksInAir % 25 == 0 && !pony.isClient()) { - entity.damage(pony.damageOf(UDamageTypes.EXHAUSTION), entity.getWorld().random.nextBetween(2, 4)); + entity.damage((ServerWorld)entity.getWorld(), pony.damageOf(UDamageTypes.EXHAUSTION), entity.getWorld().random.nextBetween(2, 4)); if (entity.getWorld().random.nextInt(110) == 1) { pony.getLevel().add(1); @@ -666,7 +671,9 @@ public class PlayerPhysics extends EntityPhysics implements Tickab LivingEntity.FallSounds fallSounds = entity.getFallSounds(); playSound(distance > 4 ? fallSounds.big() : fallSounds.small(), 1, entity.getSoundPitch()); } - entity.damage(entity.getDamageSources().flyIntoWall(), distance); + if (!entity.getWorld().isClient) { + entity.damage((ServerWorld)entity.getWorld(), entity.getDamageSources().flyIntoWall(), distance); + } } } @@ -694,7 +701,9 @@ public class PlayerPhysics extends EntityPhysics implements Tickab } if (entity.getWorld().hasRain(entity.getBlockPos())) { - applyTurbulance(velocity); + if (!entity.getWorld().isClient) { + applyTurbulance((ServerWorld)entity.getWorld(), velocity); + } } else { float targetUpdraft = WeatherConditions.THERMAL_FIELD.getValue(entity.getWorld(), new BlockPos.Mutable().set(entity.getBlockPos())) / 3F; targetUpdraft *= 1 + motion; @@ -768,17 +777,13 @@ public class PlayerPhysics extends EntityPhysics implements Tickab } } - private void applyTurbulance(MutableVector velocity) { - int globalEffectStrength = entity.getWorld().getGameRules().getInt(UGameRules.WEATHER_EFFECTS_STRENGTH); + private void applyTurbulance(ServerWorld world, MutableVector velocity) { + int globalEffectStrength = world.getGameRules().getInt(UGameRules.WEATHER_EFFECTS_STRENGTH); float effectStrength = Math.min(1, (float)ticksInAir / MAX_TICKS_TO_WEATHER_EFFECTS) * (globalEffectStrength / 100F); Vec3d gust = WeatherConditions.getGustStrength(entity.getWorld(), entity.getBlockPos()) .multiply(globalEffectStrength / 100D) .multiply(1 / (1 + Math.floor(pony.getLevel().get() / 10F))); - - - - if (effectStrength * gust.getX() >= 1) { SoundEmitter.playSoundAt(entity, USounds.AMBIENT_WIND_GUST, SoundCategory.AMBIENT, 3, 1); } @@ -796,7 +801,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab velocity.add(airflow.normalize(), windStrength.getValue()); if (!entity.getWorld().isClient && effectStrength > 0.9F && entity.getWorld().isThundering() && entity.getWorld().random.nextInt(9000) == 0) { - LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(entity.getWorld()); + LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(entity.getWorld(), SpawnReason.EVENT); lightning.refreshPositionAfterTeleport(entity.getX(), entity.getY(), entity.getZ()); entity.getWorld().spawnEntity(lightning); @@ -847,15 +852,17 @@ public class PlayerPhysics extends EntityPhysics implements Tickab if (damage > 0) { pony.subtractEnergyCost(damage / 5F); - entity.damage(entity.getDamageSources().flyIntoWall(), Math.min(damage, entity.getHealth() - 1)); + if (!entity.getWorld().isClient) { + entity.damage((ServerWorld)entity.getWorld(), entity.getDamageSources().flyIntoWall(), Math.min(damage, entity.getHealth() - 1)); + } if (!isEarthPonySmash) { UCriteria.BREAK_WINDOW.trigger(entity); } } - if (isEarthPonySmash) { + if (isEarthPonySmash && !entity.getWorld().isClient) { DamageSource damageSource = pony.damageOf(UDamageTypes.STEAMROLLER); - pony.findAllEntitiesInRange(speed + 4, EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(EntityPredicates.VALID_LIVING_ENTITY)).forEach(e -> e.damage(damageSource, 50)); + pony.findAllEntitiesInRange(speed + 4, EntityPredicates.EXCEPT_CREATIVE_OR_SPECTATOR.and(EntityPredicates.VALID_LIVING_ENTITY)).forEach(e -> e.damage((ServerWorld)entity.getWorld(), damageSource, 50)); } pony.updateVelocity(); diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 7479e037..be76e087 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -482,9 +482,9 @@ public class Pony extends Living implements Copyable, Update entity.playSound(SoundEvents.ENTITY_TURTLE_AMBIENT_LAND, 1, 1); } - if (entity.getAir() == -20) { + if (entity.getAir() == -20 && !asWorld().isClient) { entity.setAir(0); - entity.damage(entity.getDamageSources().dryOut(), 2); + entity.damage((ServerWorld)asWorld(), entity.getDamageSources().dryOut(), 2); } } } @@ -831,7 +831,7 @@ public class Pony extends Living implements Copyable, Update } public ActionResult canSleepNow() { - if (asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES) && getSpecies().isNocturnal()) { + if (!asWorld().isClient && ((ServerWorld)asWorld()).getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES) && getSpecies().isNocturnal()) { return asWorld().isDay() || asWorld().getAmbientDarkness() >= 4 ? ActionResult.SUCCESS : ActionResult.FAIL; } @@ -899,7 +899,7 @@ public class Pony extends Living implements Copyable, Update public void copyFrom(Pony oldPlayer, boolean alive) { boolean forcedSwap = (!alive && entity instanceof ServerPlayerEntity - && entity.getWorld().getGameRules().getBoolean(UGameRules.SWAP_TRIBE_ON_DEATH) + && ((ServerWorld)entity.getWorld()).getGameRules().getBoolean(UGameRules.SWAP_TRIBE_ON_DEATH) && oldPlayer.respawnRace.isUnset()) || oldPlayer.getSpecies().isUnset(); @@ -919,7 +919,7 @@ public class Pony extends Living implements Copyable, Update if (!alive) { // putting it here instead of adding another injection point into ServerPlayerEntity.copyFrom() - if (!asWorld().getGameRules().getBoolean(GameRules.KEEP_INVENTORY)) { + if (!((ServerWorld)asWorld()).getGameRules().getBoolean(GameRules.KEEP_INVENTORY)) { PlayerInventory inventory = oldPlayer.asEntity().getInventory(); for (int i = 0; i < inventory.size(); i++) { ItemStack stack = inventory.getStack(i); diff --git a/src/main/java/com/minelittlepony/unicopia/item/EmptyJarItem.java b/src/main/java/com/minelittlepony/unicopia/item/EmptyJarItem.java index c571054f..ad294443 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/EmptyJarItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/EmptyJarItem.java @@ -4,6 +4,7 @@ import net.minecraft.block.Block; import net.minecraft.entity.EntityType; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.LightningEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.Entity.RemovalReason; import net.minecraft.item.BlockItem; import net.minecraft.item.ItemStack; @@ -23,20 +24,20 @@ public class EmptyJarItem extends BlockItem { && entity.getWorld().isThundering() && entity.getWorld().isSkyVisible(entity.getBlockPos()) && entity.getWorld().random.nextInt(130) == 0) { - LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(entity.getWorld()); + LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(entity.getWorld(), SpawnReason.EVENT); lightning.refreshPositionAfterTeleport(entity.getX(), entity.getY(), entity.getZ()); entity.remove(RemovalReason.DISCARDED); entity.getWorld().spawnEntity(lightning); - ItemEntity neu = EntityType.ITEM.create(entity.getWorld()); + ItemEntity neu = EntityType.ITEM.create(entity.getWorld(), SpawnReason.TRIGGERED); neu.copyPositionAndRotation(entity); neu.setStack(new ItemStack(this == UItems.RAIN_CLOUD_JAR ? UItems.STORM_CLOUD_JAR : UItems.LIGHTNING_JAR)); neu.setInvulnerable(true); entity.getWorld().spawnEntity(neu); - ItemEntity copy = EntityType.ITEM.create(entity.getWorld()); + ItemEntity copy = EntityType.ITEM.create(entity.getWorld(), SpawnReason.TRIGGERED); copy.copyPositionAndRotation(entity); copy.setInvulnerable(true); copy.setStack(entity.getStack()); diff --git a/src/main/java/com/minelittlepony/unicopia/item/EnchantableItem.java b/src/main/java/com/minelittlepony/unicopia/item/EnchantableItem.java index 478d4101..b6aee75c 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/EnchantableItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/EnchantableItem.java @@ -11,12 +11,12 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellTyp import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.item.component.UDataComponentTypes; +import com.minelittlepony.unicopia.util.TypedActionResult; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; public interface EnchantableItem extends ItemConvertible { static CustomisedSpellType getSpellEffect(ItemStack stack) { @@ -43,7 +43,7 @@ public interface EnchantableItem extends ItemConvertible { if (!player.getWorld().isClient && consume) { player.swingHand(player.getStackInHand(Hand.OFF_HAND) == stack ? Hand.OFF_HAND : Hand.MAIN_HAND); - player.getItemCooldownManager().set(stack.getItem(), 20); + player.getItemCooldownManager().set(stack, 20); if (!player.isCreative()) { if (stack.getCount() == 1) { @@ -54,7 +54,7 @@ public interface EnchantableItem extends ItemConvertible { } } - return TypedActionResult.consume(result); + return TypedActionResult.success(result); } static boolean isEnchanted(ItemStack stack) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/WeatherJarItem.java b/src/main/java/com/minelittlepony/unicopia/item/WeatherJarItem.java index 401ffaa7..583000e3 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/WeatherJarItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/WeatherJarItem.java @@ -13,14 +13,14 @@ import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.entity.EntityType; import net.minecraft.entity.LightningEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.AliasedBlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundEvent; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkSectionPos; import net.minecraft.util.math.Vec3d; @@ -48,7 +48,7 @@ public class WeatherJarItem extends AliasedBlockItem implements Projectile, Proj } @Override - public TypedActionResult use(World world, PlayerEntity player, Hand hand) { + public ActionResult use(World world, PlayerEntity player, Hand hand) { if (player.shouldCancelInteraction()) { return super.use(world, player, hand); } @@ -100,7 +100,7 @@ public class WeatherJarItem extends AliasedBlockItem implements Projectile, Proj } if (type == Type.LIGHTNING) { - LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(world); + LightningEntity lightning = EntityType.LIGHTNING_BOLT.create(world, SpawnReason.EVENT); lightning.refreshPositionAfterTeleport(pos.getX(), pos.getY(), pos.getZ()); world.spawnEntity(lightning); diff --git a/src/main/java/com/minelittlepony/unicopia/item/cloud/CloudBlockItem.java b/src/main/java/com/minelittlepony/unicopia/item/cloud/CloudBlockItem.java index 0dd707eb..20913145 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/cloud/CloudBlockItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/cloud/CloudBlockItem.java @@ -8,11 +8,9 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemPlacementContext; -import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -30,7 +28,7 @@ public class CloudBlockItem extends BlockItem { } @Override - public TypedActionResult use(World world, PlayerEntity user, Hand hand) { + public ActionResult use(World world, PlayerEntity user, Hand hand) { InteractionManager.getInstance().sendPlayerLookAngles(user); Vec3d targetPos = user.getEyePos().add(user.getRotationVec(1).multiply(1, 1.5, 1).normalize().multiply(2)); ItemPlacementContext context = new ItemPlacementContext(user, hand, user.getStackInHand(hand), new BlockHitResult( @@ -40,13 +38,7 @@ public class CloudBlockItem extends BlockItem { true )); - ActionResult actionResult = place(context); - - if (actionResult.isAccepted()) { - return TypedActionResult.success(context.getStack(), world.isClient); - } - - return TypedActionResult.pass(user.getStackInHand(hand)); + return place(context); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/item/component/BreaksIntoItemComponent.java b/src/main/java/com/minelittlepony/unicopia/item/component/BreaksIntoItemComponent.java index c5d60941..c33a9518 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/component/BreaksIntoItemComponent.java +++ b/src/main/java/com/minelittlepony/unicopia/item/component/BreaksIntoItemComponent.java @@ -34,10 +34,10 @@ public record BreaksIntoItemComponent( ); public Optional getItemAfterBreaking() { - return Registries.ITEM.getOrEmpty(itemAfterBreaking()); + return Registries.ITEM.getOptionalValue(itemAfterBreaking()); } public Optional getBreakingSound() { - return Registries.SOUND_EVENT.getOrEmpty(breakingSound); + return Registries.SOUND_EVENT.getOptionalValue(breakingSound); } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java index 16c9d943..0951f0b1 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java @@ -138,13 +138,13 @@ public interface EnchantmentUtil { @Deprecated static int getLevel(RegistryKey enchantment, LivingEntity entity) { - return entity.getRegistryManager().get(RegistryKeys.ENCHANTMENT).getEntry(enchantment) + return entity.getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getEntry(enchantment.getValue()) .map(entry -> EnchantmentHelper.getEquipmentLevel(entry, entity)) .orElse(0); } private static int getTotalLevel(RegistryKey enchantment, LivingEntity entity) { - return entity.getRegistryManager().get(RegistryKeys.ENCHANTMENT).getEntry(enchantment) + return entity.getRegistryManager().getOrThrow(RegistryKeys.ENCHANTMENT).getEntry(enchantment.getValue()) .map(entry -> getTotalEquipmentLevel(entry, entity)) .orElse(0); } diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java index 88c85231..52898d31 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicProjectileEntity.java @@ -61,11 +61,11 @@ public class MagicProjectileEntity extends ThrownItemEntity implements WeaklyOwn } public MagicProjectileEntity(World world, LivingEntity thrower) { - super(UEntities.THROWN_ITEM, thrower, world); + super(UEntities.THROWN_ITEM, thrower, world, UItems.GEMSTONE.getDefaultStack()); } protected MagicProjectileEntity(EntityType type, World world, LivingEntity thrower) { - super(type, thrower, world); + super(type, thrower, world, UItems.GEMSTONE.getDefaultStack()); } @Override @@ -221,8 +221,8 @@ public class MagicProjectileEntity extends ThrownItemEntity implements WeaklyOwn if (entity != null) { float damage = getThrowDamage(); - if (damage > 0) { - entity.damage(getDamageSources().thrown(this, getOwner()), getThrowDamage()); + if (damage > 0 && !getWorld().isClient) { + entity.damage((ServerWorld)getWorld(), getDamageSources().thrown(this, getOwner()), getThrowDamage()); } forEachDelegates(effect -> effect.onImpact(this, hit), ProjectileDelegate.EntityHitListener.PREDICATE); @@ -232,7 +232,7 @@ public class MagicProjectileEntity extends ThrownItemEntity implements WeaklyOwn public void knockback(LivingEntity target, DamageSource source, ItemStack weapon) { double d = weapon != null && getWorld() instanceof ServerWorld serverWorld ? EnchantmentHelper.modifyKnockback(serverWorld, weapon, target, source, 0) : 0; if (d > 0) { - double e = Math.max(0, 1 - target.getAttributeValue(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE)); + double e = Math.max(0, 1 - target.getAttributeValue(EntityAttributes.KNOCKBACK_RESISTANCE)); Vec3d vec3d = this.getVelocity().multiply(1, 0, 1).normalize().multiply(d * 0.6 * e); if (vec3d.lengthSquared() > 0) { target.addVelocity(vec3d.x, 0.1, vec3d.z); diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java index f972fe01..8fc978e6 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/PhysicsBodyProjectileEntity.java @@ -120,7 +120,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl @Override public void tick() { super.tick(); - if (inGround) { + if (inGroundTime > 0) { Vec3d vel = getVelocity(); vel = vel.multiply(0, 1, 0); @@ -168,7 +168,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl playSound(USounds.Vanilla.ENTITY_ITEM_BREAK, 1, 1); }); if (!stack.isEmpty()) { - dropStack(stack); + dropStack(sw, stack); } discard(); } @@ -227,7 +227,7 @@ public class PhysicsBodyProjectileEntity extends PersistentProjectileEntity impl if (getVelocity().length() > 0.2F) { boolean ownerCanModify = !getWorld().isClient && Caster.of(getOwner()).filter(pony -> pony.canModifyAt(hit.getBlockPos())).isPresent(); - if (ownerCanModify && getWorld().getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) { + if (ownerCanModify && ((ServerWorld)getWorld()).getGameRules().getBoolean(GameRules.DO_MOB_GRIEFING)) { if ((!isBouncy() || getWorld().random.nextInt(200) == 0) && getWorld().getBlockState(hit.getBlockPos()).isIn(UTags.Blocks.FRAGILE)) { getWorld().breakBlock(hit.getBlockPos(), true); } diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java b/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java index 1281d66c..1d96a7b8 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/Projectile.java @@ -16,8 +16,8 @@ import net.minecraft.item.ProjectileItem; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; import net.minecraft.stat.Stats; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.Unit; import net.minecraft.util.math.Direction; import net.minecraft.util.math.Position; @@ -48,7 +48,7 @@ public interface Projectile extends ItemConvertible, ProjectileItem { return SETTINGS; } - default TypedActionResult triggerThrow(World world, PlayerEntity player, Hand hand) { + default ActionResult triggerThrow(World world, PlayerEntity player, Hand hand) { ItemStack stack = player.getStackInHand(hand); if (!world.isClient) { @@ -71,7 +71,7 @@ public interface Projectile extends ItemConvertible, ProjectileItem { stack.decrement(1); } - return TypedActionResult.success(stack, world.isClient()); + return ActionResult.SUCCESS_SERVER.withNewHandStack(stack); } default ProjectileEntity createProjectile(ItemStack stack, World world, @Nullable PlayerEntity player) { diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/FeatureRegistry.java b/src/main/java/com/minelittlepony/unicopia/server/world/FeatureRegistry.java index 1a4b6dcb..84ef8c4d 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/FeatureRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/FeatureRegistry.java @@ -26,7 +26,7 @@ class FeatureRegistry { registries.getOptional(RegistryKeys.PLACED_FEATURE).ifPresent(registry -> { var lookup = registries.getOptional(RegistryKeys.CONFIGURED_FEATURE).orElseThrow(); PLACED_FEATURES.forEach(entry -> { - Registry.register(registry, entry.key(), entry.factory().apply(lookup.getEntry(entry.configuration()).orElseThrow())); + Registry.register(registry, entry.key(), entry.factory().apply(lookup.getEntry(entry.configuration().getValue()).orElseThrow())); }); }); }); diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/Tree.java b/src/main/java/com/minelittlepony/unicopia/server/world/Tree.java index 312bd160..e8c1283b 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/Tree.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/Tree.java @@ -42,7 +42,7 @@ public record Tree ( }); }); registries.getOptional(RegistryKeys.PLACED_FEATURE).ifPresent(registry -> { - var reg = registries.asDynamicRegistryManager().createRegistryLookup().getOrThrow(RegistryKeys.CONFIGURED_FEATURE); + var reg = registries.asDynamicRegistryManager().getOrThrow(RegistryKeys.CONFIGURED_FEATURE); REGISTRY.stream().forEach(tree -> { tree.placements().forEach(placement -> { Registry.register(registry, placement.id(), new PlacedFeature(reg.getOrThrow(tree.configuredFeatureId()), @@ -131,7 +131,7 @@ public record Tree ( public Tree build() { RegistryKey> configuredFeatureId = RegistryKey.of(RegistryKeys.CONFIGURED_FEATURE, id); - Optional sapling = saplingId.map(id -> UBlocks.register(id, saplingConstructor.apply(new SaplingGenerator(id.toString(), Optional.of(configuredFeatureId), Optional.empty(), Optional.empty()), Block.Settings.copy(Blocks.OAK_SAPLING)), ItemGroups.NATURAL)); + Optional sapling = saplingId.map(id -> UBlocks.register(id, saplingConstructor.apply(new SaplingGenerator(id.toString(), Optional.of(configuredFeatureId), Optional.empty(), Optional.empty()), Block.Settings.copy(Blocks.OAK_SAPLING).registryKey(RegistryKey.of(RegistryKeys.BLOCK, id))), ItemGroups.NATURAL)); Tree tree = new Tree(id, configParameters.apply(new TreeFeatureConfig.Builder( BlockStateProvider.of(logType), trunkPlacer, @@ -142,7 +142,8 @@ public record Tree ( .collect(Collectors.toUnmodifiableSet()), sapling, sapling.map(saplingBlock -> { - Block flowerPot = Registry.register(Registries.BLOCK, saplingId.get().withPrefixedPath("potted_"), Blocks.createFlowerPotBlock(saplingBlock)); + RegistryKey flowerPotKey = RegistryKey.of(RegistryKeys.BLOCK, saplingId.get().withPrefixedPath("potted_")); + Block flowerPot = Registry.register(Registries.BLOCK, saplingId.get().withPrefixedPath("potted_"), new FlowerPotBlock(saplingBlock, Blocks.createFlowerPotSettings().registryKey(flowerPotKey))); UBlocks.TRANSLUCENT_BLOCKS.add(flowerPot); return flowerPot; })); diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java b/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java index 765d97e5..ca0c5bc6 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/UWorldGen.java @@ -149,7 +149,7 @@ public interface UWorldGen { .or(BiomeSelectors.tag(BiomeTags.IS_RIVER)) .or(BiomeSelectors.includeByKey(BiomeKeys.STONY_SHORE)) ), GenerationStep.Feature.VEGETAL_DECORATION, SHELLS_PLACED_FEATURE); - BiomeModifications.addCarver(BiomeSelectors.foundInOverworld(), GenerationStep.Carver.AIR, OVERWORLD_CLOUD_CARVER_CONFIG); + BiomeModifications.addCarver(BiomeSelectors.foundInOverworld(), OVERWORLD_CLOUD_CARVER_CONFIG); UTreeGen.bootstrap(); OverworldBiomeSelectionCallback.EVENT.register(context -> { diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/ZapAppleStageStore.java b/src/main/java/com/minelittlepony/unicopia/server/world/ZapAppleStageStore.java index 7b9ccfe6..b6f72992 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/ZapAppleStageStore.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/ZapAppleStageStore.java @@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.util.Tickable; import io.netty.buffer.ByteBuf; import net.minecraft.entity.EntityType; import net.minecraft.entity.LightningEntity; +import net.minecraft.entity.SpawnReason; import net.minecraft.nbt.*; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodecs; @@ -113,7 +114,7 @@ public class ZapAppleStageStore extends PersistentState implements Tickable { StreamSupport.stream(BlockPos.iterateRandomly(world.random, 20, pos, 10).spliterator(), false) .filter(p -> world.isAir(p) && !world.isAir(p.down()) && world.isSkyVisible(p)) .findFirst().ifPresent(p -> { - LightningEntity bolt = EntityType.LIGHTNING_BOLT.create(world); + LightningEntity bolt = EntityType.LIGHTNING_BOLT.create(world, SpawnReason.EVENT); bolt.refreshPositionAfterTeleport(Vec3d.ofBottomCenter(pos)); bolt.setCosmetic(true); world.spawnEntity(bolt); diff --git a/src/main/java/com/minelittlepony/unicopia/util/ColorHelper.java b/src/main/java/com/minelittlepony/unicopia/util/ColorHelper.java index aa7e2854..b92f72f8 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/ColorHelper.java +++ b/src/main/java/com/minelittlepony/unicopia/util/ColorHelper.java @@ -3,7 +3,8 @@ package com.minelittlepony.unicopia.util; import net.minecraft.entity.Entity; import net.minecraft.entity.passive.SheepEntity; import net.minecraft.util.DyeColor; -import net.minecraft.util.math.ColorHelper.Argb; + +import static net.minecraft.util.math.ColorHelper.*; public interface ColorHelper { static int getRainbowColor(Entity entity, int speed, float tickDelta) { @@ -14,7 +15,7 @@ public interface ColorHelper { float r = (entity.age % speed + tickDelta) / 25.0f; int fs = SheepEntity.getRgbColor(DyeColor.byId(p)); int gs = SheepEntity.getRgbColor(DyeColor.byId(q)); - return Argb.lerp(r, fs, gs); + return lerp(r, fs, gs); } static float[] changeSaturation(float red, float green, float blue, float intensity) { @@ -43,10 +44,10 @@ public interface ColorHelper { } static int saturate(int color, float intensity) { - float a = Argb.getAlpha(color) / 255F, - red = Argb.getRed(color) / 255F, - green = Argb.getGreen(color) / 255F, - blue = Argb.getBlue(color) / 255F; + float a = getAlpha(color) / 255F, + red = getRed(color) / 255F, + green = getGreen(color) / 255F, + blue = getBlue(color) / 255F; float avg = (red + green + blue) / 3F; float r = avg + (red - avg) * intensity, g = avg + (green - avg) * intensity, @@ -68,6 +69,6 @@ public interface ColorHelper { b = 1; } - return Argb.fromFloats(a, r, g, b); + return fromFloats(a, r, g, b); } } diff --git a/src/main/java/com/minelittlepony/unicopia/util/Dispensable.java b/src/main/java/com/minelittlepony/unicopia/util/Dispensable.java index b7479c1b..0d5f0941 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/Dispensable.java +++ b/src/main/java/com/minelittlepony/unicopia/util/Dispensable.java @@ -4,7 +4,6 @@ import net.minecraft.block.dispenser.DispenserBehavior; import net.minecraft.block.dispenser.ItemDispenserBehavior; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.math.BlockPointer; import net.minecraft.util.math.Direction; @@ -14,14 +13,13 @@ public interface Dispensable { private ActionResult result; @Override protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack) { - TypedActionResult result = dispenseStack(source, stack); - this.result = result.getResult(); + result = dispenseStack(source, stack); - if (!this.result.isAccepted()) { + if (!result.isAccepted()) { return super.dispenseSilently(source, stack); } - return result.getValue(); + return result instanceof ActionResult.Success success ? success.getNewHandStack() : stack.split(1); } @Override @@ -43,5 +41,5 @@ public interface Dispensable { /** * Called to dispense this stack. */ - TypedActionResult dispenseStack(BlockPointer source, ItemStack stack); + ActionResult dispenseStack(BlockPointer source, ItemStack stack); } diff --git a/src/main/java/com/minelittlepony/unicopia/util/TypedActionResult.java b/src/main/java/com/minelittlepony/unicopia/util/TypedActionResult.java new file mode 100644 index 00000000..e714369d --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/util/TypedActionResult.java @@ -0,0 +1,17 @@ +package com.minelittlepony.unicopia.util; + +import net.minecraft.util.ActionResult; + +public record TypedActionResult (ActionResult result, T value) { + public static TypedActionResult success(T value) { + return new TypedActionResult<>(ActionResult.SUCCESS, value); + } + + public static TypedActionResult pass(T value) { + return new TypedActionResult<>(ActionResult.PASS, value); + } + + public static TypedActionResult fail(T value) { + return new TypedActionResult<>(ActionResult.FAIL, value); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/util/registry/DynamicRegistry.java b/src/main/java/com/minelittlepony/unicopia/util/registry/DynamicRegistry.java index 8cc6336d..a06baa41 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/registry/DynamicRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/util/registry/DynamicRegistry.java @@ -28,7 +28,7 @@ public class DynamicRegistry implements RegistryBuilder.BootstrapFunction if (added.getAndSet(true)) { return; } - final WrapperLookup lookup = registries.asDynamicRegistryManager()::getWrapperOrThrow; + final WrapperLookup lookup = registries.asDynamicRegistryManager()::getOrThrow; keys.forEach((key, entry) -> { if (!r.contains(key)) { Registry.register(r, key, entry.factory().apply(lookup, key));