diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbstractSpellCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/AbstractSpellCastingAbility.java index 0be8ddcd..594327dd 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbstractSpellCastingAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbstractSpellCastingAbility.java @@ -5,7 +5,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellTyp import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.MagicParticleEffect; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; @@ -54,7 +54,7 @@ abstract class AbstractSpellCastingAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java index 6c71e186..166dc446 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/BatPonyHangAbility.java @@ -6,7 +6,7 @@ import com.minelittlepony.unicopia.ability.data.Multi; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.TraceHelper; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.util.math.BlockPos; @@ -45,7 +45,7 @@ public class BatPonyHangAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Multi.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java index 1ca3341f..c3824f87 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/CarryAbility.java @@ -11,10 +11,10 @@ import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.TraceHelper; -import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.world.World; @@ -50,7 +50,7 @@ public class CarryAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java index d3b84876..5dfcb905 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java @@ -15,7 +15,7 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.item.FriendshipBraceletItem; import com.minelittlepony.unicopia.item.UItems; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; import net.minecraft.server.network.ServerPlayerEntity; @@ -62,7 +62,7 @@ public class ChangeFormAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java index 0ea48d92..5106b5ad 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangelingFeedAbility.java @@ -15,7 +15,6 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.VecHelper; -import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.mob.HostileEntity; @@ -24,6 +23,7 @@ import net.minecraft.entity.passive.MerchantEntity; import net.minecraft.entity.passive.PigEntity; import net.minecraft.entity.passive.SheepEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; @@ -56,7 +56,7 @@ public class ChangelingFeedAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java index 896021e0..fabeb891 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java @@ -5,7 +5,6 @@ import java.util.function.DoubleSupplier; import java.util.function.Supplier; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.UTags; -import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Pos; import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.entity.player.Pony; @@ -18,7 +17,6 @@ import com.minelittlepony.unicopia.server.world.ModificationType; import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.VecHelper; -import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -27,6 +25,7 @@ import net.minecraft.block.FarmlandBlock; import net.minecraft.item.BoneMealItem; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; import net.minecraft.util.math.BlockPos; @@ -56,7 +55,7 @@ public class EarthPonyGrowAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Pos.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java index 263463e9..d91909ff 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyKickAbility.java @@ -19,7 +19,6 @@ import com.minelittlepony.unicopia.server.world.BlockDestructionManager; import com.minelittlepony.unicopia.server.world.ModificationType; import com.minelittlepony.unicopia.util.*; -import io.netty.buffer.ByteBuf; import net.minecraft.block.BeehiveBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -30,6 +29,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.BeeEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.server.world.ServerWorld; @@ -146,7 +146,7 @@ public class EarthPonyKickAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Pos.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java index 600c5bc7..09cfabb5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java @@ -23,7 +23,6 @@ import com.minelittlepony.unicopia.server.world.ModificationType; import com.minelittlepony.unicopia.util.PosHelper; import com.minelittlepony.unicopia.util.VecHelper; -import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.enchantment.EnchantmentHelper; @@ -32,6 +31,7 @@ import net.minecraft.entity.LivingEntity; import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.registry.tag.BlockTags; @@ -96,7 +96,7 @@ public class EarthPonyStompAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/FlyingDashAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/FlyingDashAbility.java index 7b5dd353..e828cd7e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/FlyingDashAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/FlyingDashAbility.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.entity.player.Pony; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; /** @@ -32,7 +32,7 @@ public class FlyingDashAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/KirinRageAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/KirinRageAbility.java index 554f1182..5b9fa227 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/KirinRageAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/KirinRageAbility.java @@ -11,7 +11,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.block.state.StateMaps; import com.minelittlepony.unicopia.entity.player.Pony; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; import net.minecraft.sound.SoundCategory; @@ -38,7 +38,7 @@ public class KirinRageAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/NirikBlastAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/NirikBlastAbility.java index 8ad4412c..a227cd52 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/NirikBlastAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/NirikBlastAbility.java @@ -11,10 +11,10 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation.Recipient import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.ExplosionUtil; -import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageTypes; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; import net.minecraft.predicate.entity.EntityPredicates; @@ -44,7 +44,7 @@ public class NirikBlastAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java index 1958aa41..19a7d246 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PeckAbility.java @@ -10,13 +10,13 @@ import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.TraceHelper; -import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.registry.tag.BlockTags; @@ -60,7 +60,7 @@ public class PeckAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java index dd847d20..2f93f112 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusCaptureStormAbility.java @@ -9,8 +9,8 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.particle.MagicParticleEffect; -import io.netty.buffer.ByteBuf; import net.minecraft.item.ItemStack; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket; import net.minecraft.server.world.ServerWorld; @@ -41,7 +41,7 @@ public class PegasusCaptureStormAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java index 6af9e83d..86550299 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusRainboomAbility.java @@ -10,7 +10,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.MagicParticleEffect; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; /** @@ -35,7 +35,7 @@ public class PegasusRainboomAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java index fe0b34e5..196a6bb3 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ScreechAbility.java @@ -16,8 +16,8 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.RegistryUtils; import com.minelittlepony.unicopia.util.VecHelper; -import io.netty.buffer.ByteBuf; import net.minecraft.entity.LivingEntity; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.particle.ParticleTypes; import net.minecraft.util.math.MathHelper; @@ -60,7 +60,7 @@ public class ScreechAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Numeric.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java index 332ca32f..190745d9 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/SeaponySonarPulseAbility.java @@ -13,12 +13,12 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.particle.UParticles; -import io.netty.buffer.ByteBuf; import net.minecraft.block.ChestBlock; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.mob.HostileEntity; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.registry.tag.FluidTags; import net.minecraft.server.world.ServerWorld; @@ -46,7 +46,7 @@ public class SeaponySonarPulseAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java index c6df8e5c..dfc756f6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/TimeChangeAbility.java @@ -9,7 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.server.world.UGameRules; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; public class TimeChangeAbility implements Ability { @@ -35,7 +35,7 @@ public class TimeChangeAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Rot.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ToggleFlightAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ToggleFlightAbility.java index ec86c1a1..38df6bda 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ToggleFlightAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ToggleFlightAbility.java @@ -10,7 +10,7 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation; import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.player.Pony; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.util.Identifier; import net.minecraft.util.math.Vec3d; @@ -34,7 +34,7 @@ public class ToggleFlightAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Hit.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java index c3b52f8a..3e0cd70f 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornDispellAbility.java @@ -14,7 +14,7 @@ import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.VecHelper; -import io.netty.buffer.ByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -45,7 +45,7 @@ public class UnicornDispellAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Pos.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java index 226adf3d..f7c87b7b 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornTeleportAbility.java @@ -13,7 +13,6 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.util.Trace; -import io.netty.buffer.ByteBuf; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.LeavesBlock; @@ -21,6 +20,7 @@ import net.minecraft.block.PowderSnowBlock; import net.minecraft.block.ShapeContext; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.network.codec.PacketCodec; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.sound.SoundCategory; @@ -132,7 +132,7 @@ public class UnicornTeleportAbility implements Ability { } @Override - public PacketCodec getSerializer() { + public PacketCodec getSerializer() { return Pos.CODEC; } diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java index 21802353..cce83b66 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/element/PageElement.java @@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.Dra import com.minelittlepony.unicopia.container.SpellbookChapterLoader.Flow; import net.minecraft.client.gui.DrawContext; import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; import net.minecraft.registry.Registries; import net.minecraft.text.Text; @@ -45,7 +46,7 @@ public interface PageElement extends Drawable { return switch (type) { case 0 -> new Image(buffer.readIdentifier(), boundsFromBuffer(buffer), buffer.readEnumConstant(Flow.class)); case 1 -> new Recipe(page, buffer.readIdentifier(), Bounds.empty()); - case 2 -> new Stack(page, IngredientWithSpell.fromPacket(buffer), boundsFromBuffer(buffer)); + case 2 -> new Stack(page, IngredientWithSpell.PACKET_CODEC.decode((RegistryByteBuf)buffer), boundsFromBuffer(buffer)); case 3 -> new TextBlock(page, List.of(Suppliers.ofInstance(buffer.readText()))); case 4 -> new TextBlock(page, buffer.readList(b -> { int count = b.readVarInt(); diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java index 916f8ab2..c9da698d 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BodyPartGear.java @@ -137,8 +137,8 @@ class BodyPartGear> implements Gear { } @Override - public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha, UUID interpolatorId) { - part.renderPart(stack, consumer, light, overlay, red, green, blue, alpha, model.getAttributes()); + public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, int color, UUID interpolatorId) { + part.renderPart(stack, consumer, light, overlay, color, model.getAttributes()); } static final class WingsGearModel extends PegasusModel { diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/GlassesGear.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/GlassesGear.java index cce63359..e4782d51 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/GlassesGear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/GlassesGear.java @@ -38,11 +38,11 @@ class GlassesGear extends GlassesModel implements Gear { @Override public Identifier getTexture(T entity, Context context) { - return textures.computeIfAbsent(Registries.ITEM.getId(GlassesItem.getForEntity((LivingEntity)entity).stack().getItem()), id -> new Identifier(id.getNamespace(), "textures/models/armor/" + id.getPath() + ".png")); + return textures.computeIfAbsent(Registries.ITEM.getId(GlassesItem.getForEntity((LivingEntity)entity).stack().getItem()), id -> id.withPath(p -> "textures/models/armor/" + p + ".png")); } @Override - public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha, UUID interpolatorId) { - render(stack, consumer, light, overlay, red, green, blue, 1); + public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, int color, UUID interpolatorId) { + render(stack, consumer, light, overlay, color); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/HeldEntityGear.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/HeldEntityGear.java index 27f8a8c6..9a6fcd36 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/HeldEntityGear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/HeldEntityGear.java @@ -49,13 +49,13 @@ class HeldEntityGear extends HeldEntityFeatureRenderer implements } @Override - public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha, UUID interpolatorId) { + public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, int color, UUID interpolatorId) { render( stack, MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(), light, entity, 0, 0, - MinecraftClient.getInstance().getTickDelta(), 0, 0, 0 + MinecraftClient.getInstance().getRenderTickCounter().getTickDelta(false), 0, 0, 0 ); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/SpellEffectGear.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/SpellEffectGear.java index 50ebf82b..519d70b2 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/SpellEffectGear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/SpellEffectGear.java @@ -50,13 +50,13 @@ class SpellEffectGear implements Gear { } @Override - public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha, UUID interpolatorId) { + public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, int color, UUID interpolatorId) { SpellEffectsRenderDispatcher.INSTANCE.render( stack, MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(), light, caster, limbAngle, limbDistance, - MinecraftClient.getInstance().getTickDelta(), animationProgress, 0, 0 + MinecraftClient.getInstance().getRenderTickCounter().getTickDelta(false), animationProgress, 0, 0 ); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractBillboardParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractBillboardParticle.java index 52420762..1ad8f546 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractBillboardParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractBillboardParticle.java @@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.client.particle; import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Camera; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumer; @@ -19,9 +18,6 @@ public abstract class AbstractBillboardParticle extends AbstractGeometryBasedPar @Override public void buildGeometry(VertexConsumer drawer, Camera camera, float tickDelta) { - Tessellator te = Tessellator.getInstance(); - BufferBuilder buffer = te.getBuffer(); - RenderSystem.setShaderTexture(0, getTexture()); RenderSystem.disableCull(); @@ -35,13 +31,13 @@ public abstract class AbstractBillboardParticle extends AbstractGeometryBasedPar float renderY = (float)(MathHelper.lerp(tickDelta, prevPosY, y) - cam.getY()); float renderZ = (float)(MathHelper.lerp(tickDelta, prevPosZ, z) - cam.getZ()); - renderQuads(te, buffer, renderX, renderY, renderZ, tickDelta); + renderQuads(Tessellator.getInstance(), renderX, renderY, renderZ, tickDelta); RenderSystem.enableCull(); RenderSystem.disableDepthTest(); } - protected abstract void renderQuads(Tessellator te, BufferBuilder buffer, float x, float y, float z, float tickDelta); + protected abstract void renderQuads(Tessellator te, float x, float y, float z, float tickDelta); protected abstract Identifier getTexture(); } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractGeometryBasedParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractGeometryBasedParticle.java index cb5a2c51..34a4debe 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractGeometryBasedParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/AbstractGeometryBasedParticle.java @@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.client.render.RenderUtil; import net.minecraft.client.particle.Particle; import net.minecraft.client.particle.ParticleTextureSheet; import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexFormat; @@ -27,42 +28,42 @@ public abstract class AbstractGeometryBasedParticle extends Particle { return ParticleTextureSheet.CUSTOM; } - protected final void renderQuad(Tessellator te, BufferBuilder buffer, Vector3f[] corners, float alpha, float tickDelta) { + protected final void renderQuad(Tessellator te, Vector3f[] corners, float alpha, float tickDelta) { int light = getBrightness(tickDelta); - buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); - buffer.vertex(corners[0].x, corners[0].y, corners[0].z).texture(0, 0).color(red, green, blue, alpha).light(light).next(); - buffer.vertex(corners[1].x, corners[1].y, corners[1].z).texture(1, 0).color(red, green, blue, alpha).light(light).next(); - buffer.vertex(corners[2].x, corners[2].y, corners[2].z).texture(1, 1).color(red, green, blue, alpha).light(light).next(); - buffer.vertex(corners[3].x, corners[3].y, corners[3].z).texture(0, 1).color(red, green, blue, alpha).light(light).next(); + BufferBuilder buffer = te.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); + buffer.vertex(corners[0].x, corners[0].y, corners[0].z).texture(0, 0).color(red, green, blue, alpha).light(light); + buffer.vertex(corners[1].x, corners[1].y, corners[1].z).texture(1, 0).color(red, green, blue, alpha).light(light); + buffer.vertex(corners[2].x, corners[2].y, corners[2].z).texture(1, 1).color(red, green, blue, alpha).light(light); + buffer.vertex(corners[3].x, corners[3].y, corners[3].z).texture(0, 1).color(red, green, blue, alpha).light(light); - te.draw(); + BufferRenderer.drawWithGlobalProgram(buffer.end()); } - protected final void renderQuad(MatrixStack matrices, Tessellator te, BufferBuilder buffer, RenderUtil.Vertex[] corners, float alpha, float tickDelta) { + protected final void renderQuad(MatrixStack matrices, Tessellator te, RenderUtil.Vertex[] corners, float alpha, float tickDelta) { int light = getBrightness(tickDelta); - buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); + BufferBuilder buffer = te.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); for (RenderUtil.Vertex corner : corners) { var position = corner.position(matrices.peek().getPositionMatrix()); - buffer.vertex(position.x, position.y, position.z).texture(corner.texture().x, corner.texture().y).color(red, green, blue, alpha).light(light).next(); + buffer.vertex(position.x, position.y, position.z).texture(corner.texture().x, corner.texture().y).color(red, green, blue, alpha).light(light); } - te.draw(); + BufferRenderer.drawWithGlobalProgram(buffer.end()); } - protected final void renderQuad(Tessellator te, BufferBuilder buffer, RenderUtil.Vertex[] corners, float alpha, float tickDelta) { + protected final void renderQuad(Tessellator te, RenderUtil.Vertex[] corners, float alpha, float tickDelta) { int light = getBrightness(tickDelta); - buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); + BufferBuilder buffer = te.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); for (RenderUtil.Vertex corner : corners) { - buffer.vertex(corner.position().x, corner.position().y, corner.position().z).texture(corner.texture().x, corner.texture().y).color(red, green, blue, alpha).light(light).next(); + buffer.vertex(corner.position().x, corner.position().y, corner.position().z).texture(corner.texture().x, corner.texture().y).color(red, green, blue, alpha).light(light); } - te.draw(); + BufferRenderer.drawWithGlobalProgram(buffer.end()); } protected final void renderQuad(VertexConsumer buffer, Vector3f[] corners, float alpha, float tickDelta) { int light = getBrightness(tickDelta); for (Vector3f corner : corners) { - buffer.vertex(corner.x, corner.y, corner.z).color(red, green, blue, alpha).light(light).next(); + buffer.vertex(corner.x, corner.y, corner.z).color(red, green, blue, alpha).light(light); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/DustCloudParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/DustCloudParticle.java index 2e550c7a..67f8da0a 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/DustCloudParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/DustCloudParticle.java @@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.client.render.model.VertexLightSource; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; @@ -70,7 +71,7 @@ public class DustCloudParticle extends AbstractBillboardParticle { } @Override - protected void renderQuads(Tessellator te, BufferBuilder buffer, float x, float y, float z, float tickDelta) { + protected void renderQuads(Tessellator te, float x, float y, float z, float tickDelta) { float scale = getScale(tickDelta) * 0.5F; float alpha = this.alpha * (1 - ((float)age / maxAge)); MatrixStack matrices = new MatrixStack(); @@ -86,9 +87,9 @@ public class DustCloudParticle extends AbstractBillboardParticle { matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees((SEPARATION * i + angle))); float ringScale = 1 + MathHelper.sin(((i * 10) + age + tickDelta) * 0.05F) * 0.1F; - buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); + BufferBuilder buffer = te.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); model.render(matrices, buffer, 0, scale * ringScale, 1, 1, 1, alpha); - te.draw(); + BufferRenderer.drawWithGlobalProgram(buffer.end()); matrices.pop(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/FootprintParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/FootprintParticle.java index 32075c5e..83537d4a 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/FootprintParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/FootprintParticle.java @@ -65,10 +65,10 @@ public class FootprintParticle extends SpriteBillboardParticle { float minV = this.sprite.getMinV(); float maxV = this.sprite.getMaxV(); - drawer.vertex(corners[0].x, corners[0].y, corners[0].z).texture(minU, minV).color(red, green, blue, alpha).light(light).next(); - drawer.vertex(corners[1].x, corners[1].y, corners[1].z).texture(maxU, minV).color(red, green, blue, alpha).light(light).next(); - drawer.vertex(corners[2].x, corners[2].y, corners[2].z).texture(maxU, maxV).color(red, green, blue, alpha).light(light).next(); - drawer.vertex(corners[3].x, corners[3].y, corners[3].z).texture(minU, maxV).color(red, green, blue, alpha).light(light).next(); + drawer.vertex(corners[0].x, corners[0].y, corners[0].z).texture(minU, minV).color(red, green, blue, alpha).light(light); + drawer.vertex(corners[1].x, corners[1].y, corners[1].z).texture(maxU, minV).color(red, green, blue, alpha).light(light); + drawer.vertex(corners[2].x, corners[2].y, corners[2].z).texture(maxU, maxV).color(red, green, blue, alpha).light(light); + drawer.vertex(corners[3].x, corners[3].y, corners[3].z).texture(minU, maxV).color(red, green, blue, alpha).light(light); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/OrientedBillboardParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/OrientedBillboardParticle.java index 4c25b465..c42290a3 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/OrientedBillboardParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/OrientedBillboardParticle.java @@ -5,7 +5,6 @@ import org.joml.Vector3f; import com.minelittlepony.unicopia.particle.OrientedBillboardParticleEffect; -import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Camera; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumer; @@ -36,7 +35,7 @@ public abstract class OrientedBillboardParticle extends AbstractBillboardParticl } @Override - protected void renderQuads(Tessellator te, BufferBuilder buffer, float x, float y, float z, float tickDelta) { + protected void renderQuads(Tessellator te, float x, float y, float z, float tickDelta) { Vector3f[] corners = new Vector3f[]{ new Vector3f(-1, -1, 0), new Vector3f(-1, 1, 0), @@ -54,7 +53,7 @@ public abstract class OrientedBillboardParticle extends AbstractBillboardParticl float alpha = this.alpha * (1 - ((float)age / maxAge)); - renderQuad(te, buffer, corners, alpha, tickDelta); + renderQuad(te, corners, alpha, tickDelta); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/RainbowTrailParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/RainbowTrailParticle.java index 4a8d7b26..7551e1e4 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/RainbowTrailParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/RainbowTrailParticle.java @@ -10,7 +10,6 @@ import com.minelittlepony.unicopia.client.render.bezier.BezierSegment; import com.minelittlepony.unicopia.client.render.bezier.Trail; import com.minelittlepony.unicopia.particle.TargetBoundParticleEffect; -import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; @@ -35,10 +34,10 @@ public class RainbowTrailParticle extends AbstractBillboardParticle { this.velocityY = velocityY; this.velocityZ = velocityZ; - if (effect.getTargetId() <= 0) { + if (effect.targetId() <= 0) { this.target = world.getOtherEntities(null, Box.from(trail.pos)).get(0); } else { - this.target = world.getEntityById(effect.getTargetId()); + this.target = world.getEntityById(effect.targetId()); } isAbility = Caster.of(target).filter(caster -> SpellType.RAINBOOM.isOn(caster)).isPresent(); } @@ -54,7 +53,7 @@ public class RainbowTrailParticle extends AbstractBillboardParticle { } @Override - protected void renderQuads(Tessellator te, BufferBuilder buffer, float x, float y, float z, float tickDelta) { + protected void renderQuads(Tessellator te, float x, float y, float z, float tickDelta) { float alpha = this.alpha * (1 - (float)age / maxAge); List segments = trail.getSegments(); @@ -67,7 +66,7 @@ public class RainbowTrailParticle extends AbstractBillboardParticle { corner.position().mul(scale).add(x, y, z); }); - renderQuad(te, buffer, corners.corners(), segments.get(i).getAlpha() * alpha, tickDelta); + renderQuad(te, corners.corners(), segments.get(i).getAlpha() * alpha, tickDelta); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java index 75cc73f6..8d179869 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/ShockwaveParticle.java @@ -4,7 +4,6 @@ import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.client.render.RenderUtil; import net.minecraft.block.BlockState; -import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.client.render.Tessellator; import net.minecraft.client.util.math.MatrixStack; @@ -32,7 +31,7 @@ public class ShockwaveParticle extends AbstractBillboardParticle { } @Override - protected void renderQuads(Tessellator te, BufferBuilder buffer, float x, float y, float z, float tickDelta) { + protected void renderQuads(Tessellator te, float x, float y, float z, float tickDelta) { if (age < 5 || age % 6 == 0) { BlockState state = world.getBlockState(BlockPos.ofFloored(this.x, this.y - 0.5, this.z)); if (!state.isAir()) { @@ -51,7 +50,7 @@ public class ShockwaveParticle extends AbstractBillboardParticle { matrices.translate(-0.5, 0, -0.5); int sides = 5; for (int i = 0; i < sides; i++) { - RenderUtil.renderFace(matrices, te, buffer, red, green, blue, 0.3F, LightmapTextureManager.MAX_LIGHT_COORDINATE); + RenderUtil.renderFace(matrices, te, red, green, blue, 0.3F, LightmapTextureManager.MAX_LIGHT_COORDINATE); matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(360 / sides)); matrices.translate(-1, 0, 0); } diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/WindParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/WindParticle.java index 38700671..2cd9119b 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/WindParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/WindParticle.java @@ -9,7 +9,6 @@ import com.minelittlepony.unicopia.client.render.bezier.Trail; import com.minelittlepony.unicopia.particle.TargetBoundParticleEffect; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.Tessellator; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; @@ -39,11 +38,11 @@ public class WindParticle extends AbstractBillboardParticle { this.velocityY = velocityY; this.velocityZ = velocityZ; this.attachmentTicks = (int)world.random.nextTriangular(15, 12); - this.passive = effect.getTargetId() <= 0; + this.passive = effect.targetId() <= 0; this.collidesWithWorld = false; - if (effect.getTargetId() > 0) { - this.target = world.getEntityById(effect.getTargetId()); + if (effect.targetId() > 0) { + this.target = world.getEntityById(effect.targetId()); } offset = target == null ? Vec3d.ZERO : new Vec3d(x, y, z).subtract(target.getPos()); } @@ -59,7 +58,7 @@ public class WindParticle extends AbstractBillboardParticle { } @Override - protected void renderQuads(Tessellator te, BufferBuilder buffer, float x, float y, float z, float tickDelta) { + protected void renderQuads(Tessellator te, float x, float y, float z, float tickDelta) { float alpha = this.alpha * (1 - (float)age / maxAge); List segments = trail.getSegments(); @@ -72,7 +71,7 @@ public class WindParticle extends AbstractBillboardParticle { corner.position().mul(scale).add(x, y, z); }); - renderQuad(te, buffer, corners.corners(), segments.get(i).getAlpha() * alpha, tickDelta); + renderQuad(te, corners.corners(), segments.get(i).getAlpha() * alpha, tickDelta); } } @@ -80,7 +79,7 @@ public class WindParticle extends AbstractBillboardParticle { public void tick() { super.tick(); - float animationFrame = age + MinecraftClient.getInstance().getTickDelta(); + float animationFrame = age + MinecraftClient.getInstance().getRenderTickCounter().getTickDelta(false); float sin = MathHelper.sin(animationFrame / 5F) * 0.1F; float cos = MathHelper.cos(animationFrame / 10F) * 0.2F; diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/RenderUtil.java b/src/main/java/com/minelittlepony/unicopia/client/render/RenderUtil.java index 9b92256d..a74b7d20 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/RenderUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/RenderUtil.java @@ -5,6 +5,7 @@ import org.joml.Vector3f; import org.joml.Vector4f; import net.minecraft.client.render.BufferBuilder; +import net.minecraft.client.render.BufferRenderer; import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormats; @@ -27,21 +28,18 @@ public class RenderUtil { new Vertex(0, 0, 0, 0, 1) }; - - - - public static void renderFace(MatrixStack matrices, Tessellator te, BufferBuilder buffer, float r, float g, float b, float a, int light) { - renderFace(matrices, te, buffer, r, g, b, a, light, 1, 1); + public static void renderFace(MatrixStack matrices, Tessellator te, float r, float g, float b, float a, int light) { + renderFace(matrices, te, r, g, b, a, light, 1, 1); } - public static void renderFace(MatrixStack matrices, Tessellator te, BufferBuilder buffer, float r, float g, float b, float a, int light, float uScale, float vScale) { - buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); + public static void renderFace(MatrixStack matrices, Tessellator te, float r, float g, float b, float a, int light, float uScale, float vScale) { + BufferBuilder buffer = te.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); Matrix4f positionmatrix = matrices.peek().getPositionMatrix(); for (Vertex vertex : UNIT_FACE) { Vector4f position = vertex.position(positionmatrix); - buffer.vertex(position.x, position.y, position.z).texture(vertex.texture().x * uScale, vertex.texture().y * vScale).color(r, g, b, a).light(light).next(); + buffer.vertex(position.x, position.y, position.z).texture(vertex.texture().x * uScale, vertex.texture().y * vScale).color(r, g, b, a).light(light); } - te.draw(); + BufferRenderer.drawWithGlobalProgram(buffer.end()); } public record Vertex(Vector3f position, Vector3f texture) { diff --git a/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java b/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java index 1ff7f727..f28196a0 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java +++ b/src/main/java/com/minelittlepony/unicopia/client/render/WorldRenderDelegate.java @@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.util.ColorHelper; import com.mojang.blaze3d.systems.RenderSystem; +import net.minecraft.block.enums.CameraSubmersionType; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.*; import net.minecraft.client.render.BackgroundRenderer.FogType; diff --git a/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java index d59e42f0..92bd5e94 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/FollowingParticleEffect.java @@ -1,17 +1,19 @@ package com.minelittlepony.unicopia.particle; -import java.util.Locale; import java.util.Optional; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; +import net.minecraft.particle.ParticleTypes; import net.minecraft.entity.Entity; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.util.math.Vec3d; -import net.minecraft.registry.Registries; public record FollowingParticleEffect ( ParticleType type, @@ -19,21 +21,20 @@ public record FollowingParticleEffect ( float followSpeed, Optional childEffect ) implements ParticleEffect { - @SuppressWarnings("deprecation") - public static final Factory FACTORY = ParticleFactoryHelper.of(FollowingParticleEffect::new, FollowingParticleEffect::new); - - protected FollowingParticleEffect(ParticleType type, StringReader reader) throws CommandSyntaxException { - this(type, - new WeakTarget(reader), - ParticleFactoryHelper.readFloat(reader), - ParticleFactoryHelper.readOptional(reader, r -> ParticleFactoryHelper.read(r))); + public static MapCodec createCodec(ParticleType type) { + return RecordCodecBuilder.mapCodec(instance -> instance.group( + WeakTarget.CODEC.fieldOf("target").forGetter(FollowingParticleEffect::target), + Codec.FLOAT.fieldOf("follow_speed").forGetter(FollowingParticleEffect::followSpeed), + ParticleTypes.TYPE_CODEC.optionalFieldOf("child_effect").forGetter(FollowingParticleEffect::childEffect) + ).apply(instance, (target, speed, effect) -> new FollowingParticleEffect(type, target, speed, effect))); } - protected FollowingParticleEffect(ParticleType type, PacketByteBuf buf) { - this(type, - new WeakTarget(buf), - buf.readFloat(), - ParticleFactoryHelper.OPTIONAL_PARTICLE_EFFECT_CODEC.read(buf) + public static final PacketCodec createPacketCodec(ParticleType type) { + return PacketCodec.tuple( + WeakTarget.PACKET_CODEC, FollowingParticleEffect::target, + PacketCodecs.FLOAT, FollowingParticleEffect::followSpeed, + PacketCodecs.optional(ParticleTypes.PACKET_CODEC), FollowingParticleEffect::childEffect, + (target, speed, effect) -> new FollowingParticleEffect(type, target, speed, effect) ); } @@ -53,31 +54,4 @@ public record FollowingParticleEffect ( public ParticleType getType() { return type; } - - @Override - public void write(PacketByteBuf buf) { - target.write(buf); - buf.writeFloat(followSpeed); - ParticleFactoryHelper.OPTIONAL_PARTICLE_EFFECT_CODEC.write(buf, childEffect()); - } - - @Override - public String asString() { - return childEffect().map(child -> { - return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f %s", - Registries.PARTICLE_TYPE.getId(getType()), - target.fixedPosition.x, - target.fixedPosition.y, - target.fixedPosition.z, - followSpeed, child.asString()); - }).orElseGet(() -> { - return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f", - Registries.PARTICLE_TYPE.getId(getType()), - target.fixedPosition.x, - target.fixedPosition.y, - target.fixedPosition.z, - followSpeed); - }); - - } } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/FootprintParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/FootprintParticleEffect.java index 69ef2300..b916aea0 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/FootprintParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/FootprintParticleEffect.java @@ -1,42 +1,22 @@ package com.minelittlepony.unicopia.particle; -import java.util.Locale; - -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import io.netty.buffer.ByteBuf; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.registry.Registries; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; public record FootprintParticleEffect ( float yaw ) implements ParticleEffect { - @SuppressWarnings("deprecation") - public static final ParticleEffect.Factory FACTORY = ParticleFactoryHelper.of(FootprintParticleEffect::new, FootprintParticleEffect::new); - - protected FootprintParticleEffect(ParticleType type, StringReader reader) throws CommandSyntaxException { - this(ParticleFactoryHelper.readFloat(reader)); - } - - protected FootprintParticleEffect(ParticleType particleType, PacketByteBuf buf) { - this(buf.readFloat()); - } + public static final MapCodec CODEC = Codec.FLOAT.fieldOf("yaw").xmap(FootprintParticleEffect::new, FootprintParticleEffect::yaw); + public static final PacketCodec PACKET_CODEC = PacketCodecs.FLOAT.xmap(FootprintParticleEffect::new, FootprintParticleEffect::yaw); @Override public ParticleType getType() { return UParticles.FOOTPRINT; } - - @Override - public void write(PacketByteBuf buf) { - buf.writeFloat(yaw); - } - - @Override - public String asString() { - return String.format(Locale.ROOT, "%s %.2f", Registries.PARTICLE_TYPE.getId(getType()), yaw); - } - } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/LightningBoltParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/LightningBoltParticleEffect.java index 19274a80..e6cbfe4d 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/LightningBoltParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/LightningBoltParticleEffect.java @@ -2,10 +2,15 @@ package com.minelittlepony.unicopia.particle; import java.util.Optional; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.minelittlepony.unicopia.util.CodecUtils; +import com.minelittlepony.unicopia.util.serialization.PacketCodecUtils; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; import net.minecraft.util.math.Vec3d; @@ -18,40 +23,25 @@ public record LightningBoltParticleEffect ( Optional pathEndPoint ) implements ParticleEffect { public static final LightningBoltParticleEffect DEFAULT = new LightningBoltParticleEffect(false, 10, 6, 3, Optional.empty()); - @SuppressWarnings("deprecation") - public static final ParticleEffect.Factory FACTORY = ParticleFactoryHelper.of(LightningBoltParticleEffect::new, LightningBoltParticleEffect::new); - protected LightningBoltParticleEffect(ParticleType particleType, StringReader reader) throws CommandSyntaxException { - this( - ParticleFactoryHelper.readBoolean(reader), - ParticleFactoryHelper.readInt(reader), - ParticleFactoryHelper.readInt(reader), - ParticleFactoryHelper.readFloat(reader), - ParticleFactoryHelper.readOptional(reader, ParticleFactoryHelper::readVector) - ); - } - - protected LightningBoltParticleEffect(ParticleType particleType, PacketByteBuf buf) { - this(buf.readBoolean(), buf.readInt(), buf.readInt(), buf.readFloat(), ParticleFactoryHelper.OPTIONAL_VECTOR_CODEC.read(buf)); - } + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.fieldOf("silent").forGetter(LightningBoltParticleEffect::silent), + Codec.INT.fieldOf("changeFrequency").forGetter(LightningBoltParticleEffect::changeFrequency), + Codec.INT.fieldOf("maxBranches").forGetter(LightningBoltParticleEffect::maxBranches), + Codec.FLOAT.fieldOf("maxDeviation").forGetter(LightningBoltParticleEffect::maxDeviation), + CodecUtils.VECTOR.optionalFieldOf("pathEndPoint").forGetter(LightningBoltParticleEffect::pathEndPoint) + ).apply(instance, LightningBoltParticleEffect::new)); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( + PacketCodecs.BOOL, LightningBoltParticleEffect::silent, + PacketCodecs.INTEGER, LightningBoltParticleEffect::changeFrequency, + PacketCodecs.INTEGER, LightningBoltParticleEffect::maxBranches, + PacketCodecs.FLOAT, LightningBoltParticleEffect::maxDeviation, + PacketCodecUtils.OPTIONAL_VECTOR, LightningBoltParticleEffect::pathEndPoint, + LightningBoltParticleEffect::new + ); @Override public ParticleType getType() { return UParticles.LIGHTNING_BOLT; } - - @Override - public void write(PacketByteBuf buffer) { - buffer.writeBoolean(silent); - buffer.writeInt(changeFrequency); - buffer.writeInt(maxBranches); - buffer.writeFloat(maxDeviation); - ParticleFactoryHelper.OPTIONAL_VECTOR_CODEC.write(buffer, pathEndPoint); - } - - @Override - public String asString() { - return String.format("%s %s %s %s", silent, changeFrequency, maxBranches, maxDeviation); - } - } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java index 3b5671a9..9d4e66f2 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/MagicParticleEffect.java @@ -1,35 +1,34 @@ package com.minelittlepony.unicopia.particle; -import java.util.Locale; - import org.joml.Vector3f; import com.minelittlepony.common.util.Color; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.particle.AbstractDustParticleEffect; +import io.netty.buffer.ByteBuf; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.random.Random; -import net.minecraft.registry.Registries; public record MagicParticleEffect ( boolean tinted, Vector3f color ) implements ParticleEffect { public static final MagicParticleEffect UNICORN = new MagicParticleEffect(false, new Vector3f()); - @SuppressWarnings("deprecation") - public static final ParticleEffect.Factory FACTORY = ParticleFactoryHelper.of(MagicParticleEffect::new, MagicParticleEffect::new); - - protected MagicParticleEffect(ParticleType particleType, StringReader reader) throws CommandSyntaxException { - this(ParticleFactoryHelper.readBoolean(reader), AbstractDustParticleEffect.readColor(reader)); - } - - protected MagicParticleEffect(ParticleType particleType, PacketByteBuf buf) { - this(buf.readBoolean(), AbstractDustParticleEffect.readColor(buf)); - } + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.fieldOf("tinted").forGetter(MagicParticleEffect::tinted), + Codecs.VECTOR_3F.fieldOf("color").forGetter(MagicParticleEffect::color) + ).apply(instance, MagicParticleEffect::new)); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( + PacketCodecs.BOOL, MagicParticleEffect::tinted, + PacketCodecs.VECTOR3F, MagicParticleEffect::color, + MagicParticleEffect::new + ); public MagicParticleEffect(int tint) { this(true, new Vector3f(Color.r(tint), Color.g(tint), Color.b(tint))); @@ -61,18 +60,4 @@ public record MagicParticleEffect ( public ParticleType getType() { return UParticles.UNICORN_MAGIC; } - - @Override - public void write(PacketByteBuf buf) { - buf.writeBoolean(tinted); - buf.writeFloat(color.x); - buf.writeFloat(color.y); - buf.writeFloat(color.z); - } - - @Override - public String asString() { - return String.format(Locale.ROOT, "%s %.2f %.2f %.2f", Registries.PARTICLE_TYPE.getId(getType()), color.x, color.y, color.z); - } - } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/OrientedBillboardParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/OrientedBillboardParticleEffect.java index b57360d8..89d39aaf 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/OrientedBillboardParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/OrientedBillboardParticleEffect.java @@ -1,15 +1,15 @@ package com.minelittlepony.unicopia.particle; -import java.util.Locale; - -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.util.math.Vec3d; -import net.minecraft.registry.Registries; public record OrientedBillboardParticleEffect ( ParticleType type, @@ -17,15 +17,21 @@ public record OrientedBillboardParticleEffect ( float yaw, float pitch ) implements ParticleEffect { - @SuppressWarnings("deprecation") - public static final ParticleEffect.Factory FACTORY = ParticleFactoryHelper.of(OrientedBillboardParticleEffect::new, OrientedBillboardParticleEffect::new); - - protected OrientedBillboardParticleEffect(ParticleType type, StringReader reader) throws CommandSyntaxException { - this(type, ParticleFactoryHelper.readBoolean(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readFloat(reader)); + public static MapCodec createCodec(ParticleType type) { + return RecordCodecBuilder.mapCodec(instance -> instance.group( + Codec.BOOL.fieldOf("fixed").forGetter(OrientedBillboardParticleEffect::fixed), + Codec.FLOAT.fieldOf("yaw").forGetter(OrientedBillboardParticleEffect::yaw), + Codec.FLOAT.fieldOf("pitch").forGetter(OrientedBillboardParticleEffect::pitch) + ).apply(instance, (fixed, yaw, pitch) -> new OrientedBillboardParticleEffect(type, fixed, yaw, pitch))); } - protected OrientedBillboardParticleEffect(ParticleType particleType, PacketByteBuf buf) { - this(particleType, buf.readBoolean(), buf.readFloat(), buf.readFloat()); + public static final PacketCodec createPacketCodec(ParticleType type) { + return PacketCodec.tuple( + PacketCodecs.BOOL, OrientedBillboardParticleEffect::fixed, + PacketCodecs.FLOAT, OrientedBillboardParticleEffect::yaw, + PacketCodecs.FLOAT, OrientedBillboardParticleEffect::pitch, + (fixed, yaw, pitch) -> new OrientedBillboardParticleEffect(type, fixed, yaw, pitch) + ); } public OrientedBillboardParticleEffect(ParticleType type, Vec3d orientation) { @@ -40,17 +46,4 @@ public record OrientedBillboardParticleEffect ( public ParticleType getType() { return type; } - - @Override - public void write(PacketByteBuf buf) { - buf.writeBoolean(fixed); - buf.writeFloat(yaw); - buf.writeFloat(pitch); - } - - @Override - public String asString() { - return String.format(Locale.ROOT, "%s %b %.2f %.2f", Registries.PARTICLE_TYPE.getId(getType()), fixed, yaw, pitch); - } - } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/ParticleFactoryHelper.java b/src/main/java/com/minelittlepony/unicopia/particle/ParticleFactoryHelper.java deleted file mode 100644 index be78f0b7..00000000 --- a/src/main/java/com/minelittlepony/unicopia/particle/ParticleFactoryHelper.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.minelittlepony.unicopia.particle; - -import java.util.Optional; - -import com.minelittlepony.unicopia.util.serialization.PacketCodec; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; - -import net.minecraft.command.argument.ParticleEffectArgumentType; -import net.minecraft.network.PacketByteBuf; -import net.minecraft.particle.ParticleEffect; -import net.minecraft.particle.ParticleType; -import net.minecraft.registry.Registries; -import net.minecraft.util.math.Vec3d; - -public interface ParticleFactoryHelper { - @SuppressWarnings({ "deprecation", "unchecked", "rawtypes" }) - PacketCodec PARTICLE_EFFECT_CODEC = PacketCodec.ofRegistry(Registries.PARTICLE_TYPE).andThen( - (buf, type) -> type.getParametersFactory().read((ParticleType) type, buf), - ParticleEffect::getType, - (buf, effect) -> effect.write(buf) - ); - PacketCodec> OPTIONAL_PARTICLE_EFFECT_CODEC = PARTICLE_EFFECT_CODEC.asOptional(); - PacketCodec VECTOR_CODEC = new PacketCodec<>( - buf -> new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble()), - (buf, vector) -> { - buf.writeDouble(vector.x); - buf.writeDouble(vector.y); - buf.writeDouble(vector.z); - } - ); - PacketCodec> OPTIONAL_VECTOR_CODEC = VECTOR_CODEC.asOptional(); - - @SuppressWarnings("unchecked") - static T read(StringReader reader) throws CommandSyntaxException { - reader.expect(' '); - return (T)ParticleEffectArgumentType.readParameters(reader, Registries.PARTICLE_TYPE.getReadOnlyWrapper()); - } - - static Vec3d readVector(StringReader reader) throws CommandSyntaxException { - return new Vec3d(readDouble(reader), readDouble(reader), readDouble(reader)); - } - - static boolean readBoolean(StringReader reader) throws CommandSyntaxException { - reader.expect(' '); - return reader.readBoolean(); - } - - static Optional readOptional(StringReader reader, ReaderFunc readFunc) throws CommandSyntaxException { - if (reader.canRead()) { - return Optional.ofNullable(readFunc.read(reader)); - } - return Optional.empty(); - } - - static double readDouble(StringReader reader) throws CommandSyntaxException { - reader.expect(' '); - return reader.readDouble(); - } - - static float readFloat(StringReader reader) throws CommandSyntaxException { - reader.expect(' '); - return reader.readFloat(); - } - - static int readInt(StringReader reader) throws CommandSyntaxException { - reader.expect(' '); - return reader.readInt(); - } - - @SuppressWarnings("deprecation") - static ParticleEffect.Factory of(CommandReader commandReader, PacketReader packetReader) { - return new ParticleEffect.Factory<>() { - @Override - public T read(ParticleType type, StringReader reader) throws CommandSyntaxException { - return commandReader.read(type, reader); - } - @Override - public T read(ParticleType type, PacketByteBuf buf) { - return packetReader.read(type, buf); - } - }; - } - - interface ReaderFunc { - T read(StringReader reader) throws CommandSyntaxException; - } - - interface CommandReader { - T read(ParticleType type, StringReader reader) throws CommandSyntaxException; - } - - interface PacketReader { - T read(ParticleType type, PacketByteBuf buf); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java index 41f95970..35b0bd1b 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/SphereParticleEffect.java @@ -1,19 +1,21 @@ package com.minelittlepony.unicopia.particle; -import java.util.Locale; - import org.joml.Vector3f; import com.minelittlepony.common.util.Color; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.minelittlepony.unicopia.util.CodecUtils; +import com.minelittlepony.unicopia.util.serialization.PacketCodecUtils; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.particle.AbstractDustParticleEffect; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.Vec3d; -import net.minecraft.registry.Registries; public record SphereParticleEffect ( ParticleType type, @@ -22,17 +24,24 @@ public record SphereParticleEffect ( float radius, Vec3d offset ) implements ParticleEffect { - @SuppressWarnings("deprecation") - public static final Factory FACTORY = ParticleFactoryHelper.of(SphereParticleEffect::new, SphereParticleEffect::new); - private static final Vec3d DEFAULT_OFFSET = new Vec3d(0, 0.5, 0); - - protected SphereParticleEffect(ParticleType type, StringReader reader) throws CommandSyntaxException { - this(type, AbstractDustParticleEffect.readColor(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readVector(reader)); + public static MapCodec createCodec(ParticleType type) { + return RecordCodecBuilder.mapCodec(instance -> instance.group( + Codecs.VECTOR_3F.fieldOf("color").forGetter(SphereParticleEffect::color), + Codec.FLOAT.fieldOf("alpha").forGetter(SphereParticleEffect::alpha), + Codec.FLOAT.fieldOf("radius").forGetter(SphereParticleEffect::radius), + CodecUtils.VECTOR.fieldOf("offset").forGetter(SphereParticleEffect::offset) + ).apply(instance, (color, alpha, radius, offset) -> new SphereParticleEffect(type, color, alpha, radius, offset))); } - protected SphereParticleEffect(ParticleType type, PacketByteBuf buf) { - this(type, buf.readVector3f(), buf.readFloat(), buf.readFloat(), ParticleFactoryHelper.VECTOR_CODEC.read(buf)); + public static final PacketCodec createPacketCodec(ParticleType type) { + return PacketCodec.tuple( + PacketCodecs.VECTOR3F, SphereParticleEffect::color, + PacketCodecs.FLOAT, SphereParticleEffect::alpha, + PacketCodecs.FLOAT, SphereParticleEffect::radius, + PacketCodecUtils.VECTOR, SphereParticleEffect::offset, + (color, alpha, radius, offset) -> new SphereParticleEffect(type, color, alpha, radius, offset) + ); } public SphereParticleEffect(ParticleType type, int tint, float alpha, float rad) { @@ -55,23 +64,4 @@ public record SphereParticleEffect ( public ParticleType getType() { return type; } - - @Override - public void write(PacketByteBuf buf) { - buf.writeVector3f(color); - buf.writeFloat(alpha); - buf.writeFloat(radius); - ParticleFactoryHelper.VECTOR_CODEC.write(buf, offset); - } - - @Override - public String asString() { - return String.format(Locale.ROOT, "%s %.2f %.2f %.2f %.2f %.2f %.2f %.2f", - Registries.PARTICLE_TYPE.getId(getType()), - color.x, color.y, color.z, - alpha, - radius, - offset.getX(), offset.getY(), offset.getZ() - ); - } } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/SpiralParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/SpiralParticleEffect.java index d40d9325..2c68bace 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/SpiralParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/SpiralParticleEffect.java @@ -1,48 +1,35 @@ package com.minelittlepony.unicopia.particle; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.RegistryByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; +import net.minecraft.particle.ParticleTypes; public record SpiralParticleEffect( WeakTarget centerPoint, float angularVelocity, ParticleEffect effect ) implements ParticleEffect { - @SuppressWarnings("deprecation") - public static final Factory FACTORY = ParticleFactoryHelper.of(SpiralParticleEffect::new, SpiralParticleEffect::new); - - protected SpiralParticleEffect(ParticleType type, StringReader reader) throws CommandSyntaxException { - this(new WeakTarget(reader), - ParticleFactoryHelper.readFloat(reader), - ParticleFactoryHelper.read(reader) - ); - } - - protected SpiralParticleEffect(ParticleType type, PacketByteBuf buf) { - this(new WeakTarget(buf), - buf.readFloat(), - ParticleFactoryHelper.PARTICLE_EFFECT_CODEC.read(buf) - ); - } + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + WeakTarget.CODEC.fieldOf("centerPoint").forGetter(SpiralParticleEffect::centerPoint), + Codec.FLOAT.fieldOf("angularVelocity").forGetter(SpiralParticleEffect::angularVelocity), + ParticleTypes.TYPE_CODEC.fieldOf("effect").forGetter(SpiralParticleEffect::effect) + ).apply(instance, SpiralParticleEffect::new)); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( + WeakTarget.PACKET_CODEC, SpiralParticleEffect::centerPoint, + PacketCodecs.FLOAT, SpiralParticleEffect::angularVelocity, + ParticleTypes.PACKET_CODEC, SpiralParticleEffect::effect, + SpiralParticleEffect::new + ); @Override public ParticleType getType() { return UParticles.SPIRAL; } - - @Override - public void write(PacketByteBuf buffer) { - centerPoint.write(buffer); - buffer.writeFloat(angularVelocity); - ParticleFactoryHelper.PARTICLE_EFFECT_CODEC.write(buffer, effect); - } - - @Override - public String asString() { - return null; - } } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/TargetBoundParticleEffect.java b/src/main/java/com/minelittlepony/unicopia/particle/TargetBoundParticleEffect.java index 76d84b03..4db38f2d 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/TargetBoundParticleEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/TargetBoundParticleEffect.java @@ -1,57 +1,36 @@ package com.minelittlepony.unicopia.particle; -import java.util.Locale; - import org.jetbrains.annotations.Nullable; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import io.netty.buffer.ByteBuf; import net.minecraft.entity.Entity; -import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleType; -import net.minecraft.registry.Registries; -public class TargetBoundParticleEffect implements ParticleEffect { - @SuppressWarnings("deprecation") - public static final Factory FACTORY = ParticleFactoryHelper.of(TargetBoundParticleEffect::new, TargetBoundParticleEffect::new); - - private final ParticleType type; - private final int targetId; - - protected TargetBoundParticleEffect(ParticleType type, StringReader reader) throws CommandSyntaxException { - this.type = type; - this.targetId = -1; +public record TargetBoundParticleEffect ( + ParticleType type, + int targetId + ) implements ParticleEffect { + public static MapCodec createCodec(ParticleType type) { + return Codec.INT.fieldOf("targetId").xmap(targetId -> new TargetBoundParticleEffect(type, targetId), TargetBoundParticleEffect::targetId); } - protected TargetBoundParticleEffect(ParticleType type, PacketByteBuf buf) { - this.type = type; - this.targetId = buf.readInt(); + public static final PacketCodec createPacketCodec(ParticleType type) { + return PacketCodecs.INTEGER.xmap(targetId -> new TargetBoundParticleEffect(type, targetId), TargetBoundParticleEffect::targetId); } public TargetBoundParticleEffect(ParticleType type, @Nullable Entity target) { - this.type = type; - this.targetId = target == null ? -1 : target.getId(); - } - - public int getTargetId() { - return targetId; + this(type, target == null ? -1 : target.getId()); } @Override public ParticleType getType() { return type; } - - @Override - public void write(PacketByteBuf buf) { - buf.writeInt(targetId); - } - - @Override - public String asString() { - return String.format(Locale.ROOT, "%s", Registries.PARTICLE_TYPE.getId(getType()), targetId); - } } diff --git a/src/main/java/com/minelittlepony/unicopia/particle/UParticles.java b/src/main/java/com/minelittlepony/unicopia/particle/UParticles.java index 35423ecd..3b5ad522 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/UParticles.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/UParticles.java @@ -10,29 +10,28 @@ import net.minecraft.registry.Registry; import net.minecraft.registry.Registries; public interface UParticles { - - ParticleType UNICORN_MAGIC = register("unicorn_magic", FabricParticleTypes.complex(MagicParticleEffect.FACTORY)); + ParticleType UNICORN_MAGIC = register("unicorn_magic", FabricParticleTypes.complex(MagicParticleEffect.CODEC, MagicParticleEffect.PACKET_CODEC)); SimpleParticleType CHANGELING_MAGIC = register("changeling_magic", FabricParticleTypes.simple()); SimpleParticleType BUBBLE = register("bubble", FabricParticleTypes.simple()); - ParticleType FOOTPRINT = register("footprint", FabricParticleTypes.complex(FootprintParticleEffect.FACTORY)); - ParticleType DUST_CLOUD = register("dust_cloud", FabricParticleTypes.complex(BlockStateParticleEffect.PARAMETERS_FACTORY)); + ParticleType FOOTPRINT = register("footprint", FabricParticleTypes.complex(FootprintParticleEffect.CODEC, FootprintParticleEffect.PACKET_CODEC)); + ParticleType DUST_CLOUD = register("dust_cloud", FabricParticleTypes.complex(BlockStateParticleEffect::createCodec, BlockStateParticleEffect::createPacketCodec)); - ParticleType RAINBOOM_RING = register("rainboom_ring", FabricParticleTypes.complex(OrientedBillboardParticleEffect.FACTORY)); - ParticleType RAINBOOM_TRAIL = register("rainboom_trail", FabricParticleTypes.complex(TargetBoundParticleEffect.FACTORY)); - ParticleType WIND = register("wind", FabricParticleTypes.complex(TargetBoundParticleEffect.FACTORY)); + ParticleType RAINBOOM_RING = register("rainboom_ring", FabricParticleTypes.complex(OrientedBillboardParticleEffect::createCodec, OrientedBillboardParticleEffect::createPacketCodec)); + ParticleType RAINBOOM_TRAIL = register("rainboom_trail", FabricParticleTypes.complex(TargetBoundParticleEffect::createCodec, TargetBoundParticleEffect::createPacketCodec)); + ParticleType WIND = register("wind", FabricParticleTypes.complex(TargetBoundParticleEffect::createCodec, TargetBoundParticleEffect::createPacketCodec)); SimpleParticleType RAIN_DROPS = register("rain_drops", FabricParticleTypes.simple()); - ParticleType SPHERE = register("sphere", FabricParticleTypes.complex(true, SphereParticleEffect.FACTORY)); - ParticleType DISK = register("disk", FabricParticleTypes.complex(true, SphereParticleEffect.FACTORY)); + ParticleType SPHERE = register("sphere", FabricParticleTypes.complex(true, SphereParticleEffect::createCodec, SphereParticleEffect::createPacketCodec)); + ParticleType DISK = register("disk", FabricParticleTypes.complex(true, SphereParticleEffect::createCodec, SphereParticleEffect::createPacketCodec)); - ParticleType HEALTH_DRAIN = register("health_drain", FabricParticleTypes.complex(true, FollowingParticleEffect.FACTORY)); - ParticleType SPIRAL = register("spiral", FabricParticleTypes.complex(true, SpiralParticleEffect.FACTORY)); + ParticleType HEALTH_DRAIN = register("health_drain", FabricParticleTypes.complex(true, FollowingParticleEffect::createCodec, FollowingParticleEffect::createPacketCodec)); + ParticleType SPIRAL = register("spiral", FabricParticleTypes.complex(true, SpiralParticleEffect.CODEC, SpiralParticleEffect.PACKET_CODEC)); SimpleParticleType GROUND_POUND = register("ground_pound", FabricParticleTypes.simple()); SimpleParticleType CLOUDS_ESCAPING = register("clouds_escaping", FabricParticleTypes.simple(true)); - ParticleType LIGHTNING_BOLT = register("lightning_bolt", FabricParticleTypes.complex(true, LightningBoltParticleEffect.FACTORY)); + ParticleType LIGHTNING_BOLT = register("lightning_bolt", FabricParticleTypes.complex(true, LightningBoltParticleEffect.CODEC, LightningBoltParticleEffect.PACKET_CODEC)); SimpleParticleType SHOCKWAVE = register("shockwave", FabricParticleTypes.simple(true)); static > T register(String name, T type) { diff --git a/src/main/java/com/minelittlepony/unicopia/particle/WeakTarget.java b/src/main/java/com/minelittlepony/unicopia/particle/WeakTarget.java index 770ea2db..e0b8f512 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/WeakTarget.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/WeakTarget.java @@ -2,30 +2,42 @@ package com.minelittlepony.unicopia.particle; import org.jetbrains.annotations.Nullable; -import com.mojang.brigadier.StringReader; -import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.minelittlepony.unicopia.util.CodecUtils; +import com.minelittlepony.unicopia.util.serialization.PacketCodecUtils; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.entity.Entity; import net.minecraft.network.PacketByteBuf; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; public class WeakTarget { + public static final Codec CODEC = CodecUtils.xor( + RecordCodecBuilder.create(instance -> instance.group( + CodecUtils.VECTOR.fieldOf("position").forGetter(i -> i.fixedPosition), + Codec.INT.fieldOf("targetId").forGetter(i -> i.targetId) + ).apply(instance, WeakTarget::new)), + CodecUtils.VECTOR.xmap(pos -> new WeakTarget(pos, null), target -> target.fixedPosition) + ); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( + PacketCodecUtils.VECTOR, i -> i.fixedPosition, + PacketCodecs.INTEGER, i -> i.targetId, + WeakTarget::new + ); + Vec3d fixedPosition; private int targetId; - public WeakTarget(Vec3d fixedPosition, @Nullable Entity entity) { + private WeakTarget(Vec3d fixedPosition, int targetId) { this.fixedPosition = fixedPosition; - targetId = entity == null ? -1 : entity.getId(); + this.targetId = targetId; } - public WeakTarget(PacketByteBuf buf) { - fixedPosition = ParticleFactoryHelper.VECTOR_CODEC.read(buf); - targetId = buf.readInt(); - } - - public WeakTarget(StringReader reader) throws CommandSyntaxException { - this(ParticleFactoryHelper.readVector(reader), null); + public WeakTarget(Vec3d fixedPosition, @Nullable Entity entity) { + this(fixedPosition, entity == null ? -1 : entity.getId()); } public Vec3d getPosition(World world) { @@ -47,9 +59,4 @@ public class WeakTarget { } return "Fixed(" + fixedPosition + ")"; } - - public void write(PacketByteBuf buf) { - ParticleFactoryHelper.VECTOR_CODEC.write(buf, fixedPosition); - buf.writeInt(targetId); - } } diff --git a/src/main/java/com/minelittlepony/unicopia/util/CodecUtils.java b/src/main/java/com/minelittlepony/unicopia/util/CodecUtils.java index b4df030f..8289ea93 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/CodecUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/util/CodecUtils.java @@ -14,15 +14,23 @@ import com.mojang.serialization.Decoder; import com.mojang.serialization.DynamicOps; import com.mojang.serialization.Encoder; import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + import net.fabricmc.fabric.api.util.TriState; import net.minecraft.item.ItemConvertible; import net.minecraft.registry.Registries; import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; public interface CodecUtils { Codec ITEM = Registries.ITEM.getCodec().xmap(i -> () -> i, ItemConvertible::asItem); Codec> OPTIONAL_POS = Codecs.optional(BlockPos.CODEC); + Codec VECTOR = RecordCodecBuilder.create(instance -> instance.group( + Codec.DOUBLE.fieldOf("x").forGetter(Vec3d::getX), + Codec.DOUBLE.fieldOf("y").forGetter(Vec3d::getY), + Codec.DOUBLE.fieldOf("z").forGetter(Vec3d::getZ) + ).apply(instance, Vec3d::new)); /** * Combines the result of two unrelated codecs into a single object. *