Update particles and fix errors in the ability package

This commit is contained in:
Sollace 2024-09-29 22:54:24 +01:00
parent c2ab69ef1a
commit c8fd6fa4ea
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
47 changed files with 282 additions and 493 deletions

View file

@ -5,7 +5,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellTyp
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; 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.network.codec.PacketCodec;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
@ -54,7 +54,7 @@ abstract class AbstractSpellCastingAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -6,7 +6,7 @@ import com.minelittlepony.unicopia.ability.data.Multi;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; 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.network.codec.PacketCodec;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -45,7 +45,7 @@ public class BatPonyHangAbility implements Ability<Multi> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Multi> getSerializer() { public PacketCodec<? super RegistryByteBuf, Multi> getSerializer() {
return Multi.CODEC; return Multi.CODEC;
} }

View file

@ -11,10 +11,10 @@ import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -50,7 +50,7 @@ public class CarryAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -15,7 +15,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.FriendshipBraceletItem; import com.minelittlepony.unicopia.item.FriendshipBraceletItem;
import com.minelittlepony.unicopia.item.UItems; 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.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
@ -62,7 +62,7 @@ public class ChangeFormAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -15,7 +15,6 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.HostileEntity; 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.PigEntity;
import net.minecraft.entity.passive.SheepEntity; import net.minecraft.entity.passive.SheepEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
@ -56,7 +56,7 @@ public class ChangelingFeedAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -5,7 +5,6 @@ import java.util.function.DoubleSupplier;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.UTags;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.data.Pos; import com.minelittlepony.unicopia.ability.data.Pos;
import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.block.UBlocks;
import com.minelittlepony.unicopia.entity.player.Pony; 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.TraceHelper;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
@ -27,6 +25,7 @@ import net.minecraft.block.FarmlandBlock;
import net.minecraft.item.BoneMealItem; import net.minecraft.item.BoneMealItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -56,7 +55,7 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Pos> getSerializer() { public PacketCodec<? super RegistryByteBuf, Pos> getSerializer() {
return Pos.CODEC; return Pos.CODEC;
} }

View file

@ -19,7 +19,6 @@ import com.minelittlepony.unicopia.server.world.BlockDestructionManager;
import com.minelittlepony.unicopia.server.world.ModificationType; import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.*; import com.minelittlepony.unicopia.util.*;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.BeehiveBlock; import net.minecraft.block.BeehiveBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -30,6 +29,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.BeeEntity; import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
@ -146,7 +146,7 @@ public class EarthPonyKickAbility implements Ability<Pos> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Pos> getSerializer() { public PacketCodec<? super RegistryByteBuf, Pos> getSerializer() {
return Pos.CODEC; return Pos.CODEC;
} }

View file

@ -23,7 +23,6 @@ import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.PosHelper; import com.minelittlepony.unicopia.util.PosHelper;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentHelper;
@ -32,6 +31,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.BlockTags;
@ -96,7 +96,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -7,7 +7,7 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.entity.player.Pony; 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.network.codec.PacketCodec;
/** /**
@ -32,7 +32,7 @@ public class FlyingDashAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -11,7 +11,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.block.state.StateMaps; import com.minelittlepony.unicopia.block.state.StateMaps;
import com.minelittlepony.unicopia.entity.player.Pony; 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.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
@ -38,7 +38,7 @@ public class KirinRageAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -11,10 +11,10 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation.Recipient
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.ExplosionUtil; import com.minelittlepony.unicopia.util.ExplosionUtil;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageTypes; import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
@ -44,7 +44,7 @@ public class NirikBlastAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -10,13 +10,13 @@ import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.BlockTags;
@ -60,7 +60,7 @@ public class PeckAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -9,8 +9,8 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket; import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
@ -41,7 +41,7 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -10,7 +10,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; 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.network.codec.PacketCodec;
/** /**
@ -35,7 +35,7 @@ public class PegasusRainboomAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -16,8 +16,8 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.RegistryUtils; import com.minelittlepony.unicopia.util.RegistryUtils;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -60,7 +60,7 @@ public class ScreechAbility implements Ability<Numeric> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Numeric> getSerializer() { public PacketCodec<? super RegistryByteBuf, Numeric> getSerializer() {
return Numeric.CODEC; return Numeric.CODEC;
} }

View file

@ -13,12 +13,12 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.ParticleUtils; import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.particle.UParticles;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.ChestBlock; import net.minecraft.block.ChestBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.registry.tag.FluidTags; import net.minecraft.registry.tag.FluidTags;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
@ -46,7 +46,7 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -9,7 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.server.world.UGameRules; import com.minelittlepony.unicopia.server.world.UGameRules;
import io.netty.buffer.ByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
public class TimeChangeAbility implements Ability<Rot> { public class TimeChangeAbility implements Ability<Rot> {
@ -35,7 +35,7 @@ public class TimeChangeAbility implements Ability<Rot> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Rot> getSerializer() { public PacketCodec<? super RegistryByteBuf, Rot> getSerializer() {
return Rot.CODEC; return Rot.CODEC;
} }

View file

@ -10,7 +10,7 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; 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.network.codec.PacketCodec;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -34,7 +34,7 @@ public class ToggleFlightAbility implements Ability<Hit> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Hit> getSerializer() { public PacketCodec<? super RegistryByteBuf, Hit> getSerializer() {
return Hit.CODEC; return Hit.CODEC;
} }

View file

@ -14,7 +14,7 @@ import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import com.minelittlepony.unicopia.util.VecHelper; 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.network.codec.PacketCodec;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -45,7 +45,7 @@ public class UnicornDispellAbility implements Ability<Pos> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Pos> getSerializer() { public PacketCodec<? super RegistryByteBuf, Pos> getSerializer() {
return Pos.CODEC; return Pos.CODEC;
} }

View file

@ -13,7 +13,6 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.util.Trace; import com.minelittlepony.unicopia.util.Trace;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.LeavesBlock; import net.minecraft.block.LeavesBlock;
@ -21,6 +20,7 @@ import net.minecraft.block.PowderSnowBlock;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
@ -132,7 +132,7 @@ public class UnicornTeleportAbility implements Ability<Pos> {
} }
@Override @Override
public PacketCodec<? extends ByteBuf, Pos> getSerializer() { public PacketCodec<? super RegistryByteBuf, Pos> getSerializer() {
return Pos.CODEC; return Pos.CODEC;
} }

View file

@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.client.gui.spellbook.SpellbookChapterList.Dra
import com.minelittlepony.unicopia.container.SpellbookChapterLoader.Flow; import com.minelittlepony.unicopia.container.SpellbookChapterLoader.Flow;
import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.DrawContext;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -45,7 +46,7 @@ public interface PageElement extends Drawable {
return switch (type) { return switch (type) {
case 0 -> new Image(buffer.readIdentifier(), boundsFromBuffer(buffer), buffer.readEnumConstant(Flow.class)); case 0 -> new Image(buffer.readIdentifier(), boundsFromBuffer(buffer), buffer.readEnumConstant(Flow.class));
case 1 -> new Recipe(page, buffer.readIdentifier(), Bounds.empty()); 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 3 -> new TextBlock(page, List.of(Suppliers.ofInstance(buffer.readText())));
case 4 -> new TextBlock(page, buffer.readList(b -> { case 4 -> new TextBlock(page, buffer.readList(b -> {
int count = b.readVarInt(); int count = b.readVarInt();

View file

@ -137,8 +137,8 @@ class BodyPartGear<M extends ClientPonyModel<LivingEntity>> implements Gear {
} }
@Override @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) {
part.renderPart(stack, consumer, light, overlay, red, green, blue, alpha, model.getAttributes()); part.renderPart(stack, consumer, light, overlay, color, model.getAttributes());
} }
static final class WingsGearModel extends PegasusModel<LivingEntity> { static final class WingsGearModel extends PegasusModel<LivingEntity> {

View file

@ -38,11 +38,11 @@ class GlassesGear extends GlassesModel implements Gear {
@Override @Override
public <T extends Entity> Identifier getTexture(T entity, Context<T, ?> context) { public <T extends Entity> Identifier getTexture(T entity, Context<T, ?> 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 @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, consumer, light, overlay, red, green, blue, 1); render(stack, consumer, light, overlay, color);
} }
} }

View file

@ -49,13 +49,13 @@ class HeldEntityGear extends HeldEntityFeatureRenderer<LivingEntity> implements
} }
@Override @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( render(
stack, stack,
MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(), MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(),
light, entity, light, entity,
0, 0, 0, 0,
MinecraftClient.getInstance().getTickDelta(), 0, 0, 0 MinecraftClient.getInstance().getRenderTickCounter().getTickDelta(false), 0, 0, 0
); );
} }
} }

View file

@ -50,13 +50,13 @@ class SpellEffectGear implements Gear {
} }
@Override @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( SpellEffectsRenderDispatcher.INSTANCE.render(
stack, stack,
MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(), MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(),
light, caster, light, caster,
limbAngle, limbDistance, limbAngle, limbDistance,
MinecraftClient.getInstance().getTickDelta(), animationProgress, 0, 0 MinecraftClient.getInstance().getRenderTickCounter().getTickDelta(false), animationProgress, 0, 0
); );
} }
} }

View file

@ -2,7 +2,6 @@ package com.minelittlepony.unicopia.client.particle;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Camera; import net.minecraft.client.render.Camera;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
@ -19,9 +18,6 @@ public abstract class AbstractBillboardParticle extends AbstractGeometryBasedPar
@Override @Override
public void buildGeometry(VertexConsumer drawer, Camera camera, float tickDelta) { public void buildGeometry(VertexConsumer drawer, Camera camera, float tickDelta) {
Tessellator te = Tessellator.getInstance();
BufferBuilder buffer = te.getBuffer();
RenderSystem.setShaderTexture(0, getTexture()); RenderSystem.setShaderTexture(0, getTexture());
RenderSystem.disableCull(); RenderSystem.disableCull();
@ -35,13 +31,13 @@ public abstract class AbstractBillboardParticle extends AbstractGeometryBasedPar
float renderY = (float)(MathHelper.lerp(tickDelta, prevPosY, y) - cam.getY()); float renderY = (float)(MathHelper.lerp(tickDelta, prevPosY, y) - cam.getY());
float renderZ = (float)(MathHelper.lerp(tickDelta, prevPosZ, z) - cam.getZ()); 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.enableCull();
RenderSystem.disableDepthTest(); 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(); protected abstract Identifier getTexture();
} }

View file

@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.client.render.RenderUtil;
import net.minecraft.client.particle.Particle; import net.minecraft.client.particle.Particle;
import net.minecraft.client.particle.ParticleTextureSheet; import net.minecraft.client.particle.ParticleTextureSheet;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormat;
@ -27,42 +28,42 @@ public abstract class AbstractGeometryBasedParticle extends Particle {
return ParticleTextureSheet.CUSTOM; 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); 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);
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[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).next(); 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).next(); 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).next(); 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); 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) { for (RenderUtil.Vertex corner : corners) {
var position = corner.position(matrices.peek().getPositionMatrix()); 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); 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) { 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) { protected final void renderQuad(VertexConsumer buffer, Vector3f[] corners, float alpha, float tickDelta) {
int light = getBrightness(tickDelta); int light = getBrightness(tickDelta);
for (Vector3f corner : corners) { 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);
} }
} }

View file

@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.client.render.model.VertexLightSource;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
@ -70,7 +71,7 @@ public class DustCloudParticle extends AbstractBillboardParticle {
} }
@Override @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 scale = getScale(tickDelta) * 0.5F;
float alpha = this.alpha * (1 - ((float)age / maxAge)); float alpha = this.alpha * (1 - ((float)age / maxAge));
MatrixStack matrices = new MatrixStack(); MatrixStack matrices = new MatrixStack();
@ -86,9 +87,9 @@ public class DustCloudParticle extends AbstractBillboardParticle {
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees((SEPARATION * i + angle))); matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees((SEPARATION * i + angle)));
float ringScale = 1 + MathHelper.sin(((i * 10) + age + tickDelta) * 0.05F) * 0.1F; 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); model.render(matrices, buffer, 0, scale * ringScale, 1, 1, 1, alpha);
te.draw(); BufferRenderer.drawWithGlobalProgram(buffer.end());
matrices.pop(); matrices.pop();
} }
} }

View file

@ -65,10 +65,10 @@ public class FootprintParticle extends SpriteBillboardParticle {
float minV = this.sprite.getMinV(); float minV = this.sprite.getMinV();
float maxV = this.sprite.getMaxV(); 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[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).next(); 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).next(); 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).next(); drawer.vertex(corners[3].x, corners[3].y, corners[3].z).texture(minU, maxV).color(red, green, blue, alpha).light(light);
} }
} }

View file

@ -5,7 +5,6 @@ import org.joml.Vector3f;
import com.minelittlepony.unicopia.particle.OrientedBillboardParticleEffect; import com.minelittlepony.unicopia.particle.OrientedBillboardParticleEffect;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Camera; import net.minecraft.client.render.Camera;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.VertexConsumer;
@ -36,7 +35,7 @@ public abstract class OrientedBillboardParticle extends AbstractBillboardParticl
} }
@Override @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[]{ Vector3f[] corners = new Vector3f[]{
new Vector3f(-1, -1, 0), new Vector3f(-1, -1, 0),
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)); float alpha = this.alpha * (1 - ((float)age / maxAge));
renderQuad(te, buffer, corners, alpha, tickDelta); renderQuad(te, corners, alpha, tickDelta);
} }
} }

View file

@ -10,7 +10,6 @@ import com.minelittlepony.unicopia.client.render.bezier.BezierSegment;
import com.minelittlepony.unicopia.client.render.bezier.Trail; import com.minelittlepony.unicopia.client.render.bezier.Trail;
import com.minelittlepony.unicopia.particle.TargetBoundParticleEffect; import com.minelittlepony.unicopia.particle.TargetBoundParticleEffect;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -35,10 +34,10 @@ public class RainbowTrailParticle extends AbstractBillboardParticle {
this.velocityY = velocityY; this.velocityY = velocityY;
this.velocityZ = velocityZ; this.velocityZ = velocityZ;
if (effect.getTargetId() <= 0) { if (effect.targetId() <= 0) {
this.target = world.getOtherEntities(null, Box.from(trail.pos)).get(0); this.target = world.getOtherEntities(null, Box.from(trail.pos)).get(0);
} else { } else {
this.target = world.getEntityById(effect.getTargetId()); this.target = world.getEntityById(effect.targetId());
} }
isAbility = Caster.of(target).filter(caster -> SpellType.RAINBOOM.isOn(caster)).isPresent(); isAbility = Caster.of(target).filter(caster -> SpellType.RAINBOOM.isOn(caster)).isPresent();
} }
@ -54,7 +53,7 @@ public class RainbowTrailParticle extends AbstractBillboardParticle {
} }
@Override @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); float alpha = this.alpha * (1 - (float)age / maxAge);
List<Trail.Segment> segments = trail.getSegments(); List<Trail.Segment> segments = trail.getSegments();
@ -67,7 +66,7 @@ public class RainbowTrailParticle extends AbstractBillboardParticle {
corner.position().mul(scale).add(x, y, z); 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);
} }
} }

View file

@ -4,7 +4,6 @@ import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.render.RenderUtil; import com.minelittlepony.unicopia.client.render.RenderUtil;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.LightmapTextureManager; import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.util.math.MatrixStack; import net.minecraft.client.util.math.MatrixStack;
@ -32,7 +31,7 @@ public class ShockwaveParticle extends AbstractBillboardParticle {
} }
@Override @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) { if (age < 5 || age % 6 == 0) {
BlockState state = world.getBlockState(BlockPos.ofFloored(this.x, this.y - 0.5, this.z)); BlockState state = world.getBlockState(BlockPos.ofFloored(this.x, this.y - 0.5, this.z));
if (!state.isAir()) { if (!state.isAir()) {
@ -51,7 +50,7 @@ public class ShockwaveParticle extends AbstractBillboardParticle {
matrices.translate(-0.5, 0, -0.5); matrices.translate(-0.5, 0, -0.5);
int sides = 5; int sides = 5;
for (int i = 0; i < sides; i++) { 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.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(360 / sides));
matrices.translate(-1, 0, 0); matrices.translate(-1, 0, 0);
} }

View file

@ -9,7 +9,6 @@ import com.minelittlepony.unicopia.client.render.bezier.Trail;
import com.minelittlepony.unicopia.particle.TargetBoundParticleEffect; import com.minelittlepony.unicopia.particle.TargetBoundParticleEffect;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -39,11 +38,11 @@ public class WindParticle extends AbstractBillboardParticle {
this.velocityY = velocityY; this.velocityY = velocityY;
this.velocityZ = velocityZ; this.velocityZ = velocityZ;
this.attachmentTicks = (int)world.random.nextTriangular(15, 12); this.attachmentTicks = (int)world.random.nextTriangular(15, 12);
this.passive = effect.getTargetId() <= 0; this.passive = effect.targetId() <= 0;
this.collidesWithWorld = false; this.collidesWithWorld = false;
if (effect.getTargetId() > 0) { if (effect.targetId() > 0) {
this.target = world.getEntityById(effect.getTargetId()); this.target = world.getEntityById(effect.targetId());
} }
offset = target == null ? Vec3d.ZERO : new Vec3d(x, y, z).subtract(target.getPos()); offset = target == null ? Vec3d.ZERO : new Vec3d(x, y, z).subtract(target.getPos());
} }
@ -59,7 +58,7 @@ public class WindParticle extends AbstractBillboardParticle {
} }
@Override @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); float alpha = this.alpha * (1 - (float)age / maxAge);
List<Trail.Segment> segments = trail.getSegments(); List<Trail.Segment> segments = trail.getSegments();
@ -72,7 +71,7 @@ public class WindParticle extends AbstractBillboardParticle {
corner.position().mul(scale).add(x, y, z); 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() { public void tick() {
super.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 sin = MathHelper.sin(animationFrame / 5F) * 0.1F;
float cos = MathHelper.cos(animationFrame / 10F) * 0.2F; float cos = MathHelper.cos(animationFrame / 10F) * 0.2F;

View file

@ -5,6 +5,7 @@ import org.joml.Vector3f;
import org.joml.Vector4f; import org.joml.Vector4f;
import net.minecraft.client.render.BufferBuilder; import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.BufferRenderer;
import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.Tessellator;
import net.minecraft.client.render.VertexFormat; import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats; import net.minecraft.client.render.VertexFormats;
@ -27,21 +28,18 @@ public class RenderUtil {
new Vertex(0, 0, 0, 0, 1) new Vertex(0, 0, 0, 0, 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) {
renderFace(matrices, te, buffer, 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) { public static void renderFace(MatrixStack matrices, Tessellator te, float r, float g, float b, float a, int light, float uScale, float vScale) {
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT); BufferBuilder buffer = te.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR_LIGHT);
Matrix4f positionmatrix = matrices.peek().getPositionMatrix(); Matrix4f positionmatrix = matrices.peek().getPositionMatrix();
for (Vertex vertex : UNIT_FACE) { for (Vertex vertex : UNIT_FACE) {
Vector4f position = vertex.position(positionmatrix); 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) { public record Vertex(Vector3f position, Vector3f texture) {

View file

@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.ColorHelper; import com.minelittlepony.unicopia.util.ColorHelper;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.block.enums.CameraSubmersionType;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.*; import net.minecraft.client.render.*;
import net.minecraft.client.render.BackgroundRenderer.FogType; import net.minecraft.client.render.BackgroundRenderer.FogType;

View file

@ -1,17 +1,19 @@
package com.minelittlepony.unicopia.particle; package com.minelittlepony.unicopia.particle;
import java.util.Locale;
import java.util.Optional; import java.util.Optional;
import com.mojang.brigadier.StringReader; import com.mojang.serialization.Codec;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType; import net.minecraft.particle.ParticleType;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.entity.Entity; 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.util.math.Vec3d;
import net.minecraft.registry.Registries;
public record FollowingParticleEffect ( public record FollowingParticleEffect (
ParticleType<FollowingParticleEffect> type, ParticleType<FollowingParticleEffect> type,
@ -19,21 +21,20 @@ public record FollowingParticleEffect (
float followSpeed, float followSpeed,
Optional<ParticleEffect> childEffect Optional<ParticleEffect> childEffect
) implements ParticleEffect { ) implements ParticleEffect {
@SuppressWarnings("deprecation") public static MapCodec<FollowingParticleEffect> createCodec(ParticleType<FollowingParticleEffect> type) {
public static final Factory<FollowingParticleEffect> FACTORY = ParticleFactoryHelper.of(FollowingParticleEffect::new, FollowingParticleEffect::new); return RecordCodecBuilder.mapCodec(instance -> instance.group(
WeakTarget.CODEC.fieldOf("target").forGetter(FollowingParticleEffect::target),
protected FollowingParticleEffect(ParticleType<FollowingParticleEffect> type, StringReader reader) throws CommandSyntaxException { Codec.FLOAT.fieldOf("follow_speed").forGetter(FollowingParticleEffect::followSpeed),
this(type, ParticleTypes.TYPE_CODEC.optionalFieldOf("child_effect").forGetter(FollowingParticleEffect::childEffect)
new WeakTarget(reader), ).apply(instance, (target, speed, effect) -> new FollowingParticleEffect(type, target, speed, effect)));
ParticleFactoryHelper.readFloat(reader),
ParticleFactoryHelper.readOptional(reader, r -> ParticleFactoryHelper.read(r)));
} }
protected FollowingParticleEffect(ParticleType<FollowingParticleEffect> type, PacketByteBuf buf) { public static final PacketCodec<RegistryByteBuf, FollowingParticleEffect> createPacketCodec(ParticleType<FollowingParticleEffect> type) {
this(type, return PacketCodec.tuple(
new WeakTarget(buf), WeakTarget.PACKET_CODEC, FollowingParticleEffect::target,
buf.readFloat(), PacketCodecs.FLOAT, FollowingParticleEffect::followSpeed,
ParticleFactoryHelper.OPTIONAL_PARTICLE_EFFECT_CODEC.read(buf) 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() { public ParticleType<?> getType() {
return type; 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);
});
}
} }

View file

@ -1,42 +1,22 @@
package com.minelittlepony.unicopia.particle; package com.minelittlepony.unicopia.particle;
import java.util.Locale; import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import io.netty.buffer.ByteBuf;
import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType; import net.minecraft.particle.ParticleType;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.registry.Registries; import net.minecraft.network.codec.PacketCodecs;
public record FootprintParticleEffect ( public record FootprintParticleEffect (
float yaw float yaw
) implements ParticleEffect { ) implements ParticleEffect {
@SuppressWarnings("deprecation") public static final MapCodec<FootprintParticleEffect> CODEC = Codec.FLOAT.fieldOf("yaw").xmap(FootprintParticleEffect::new, FootprintParticleEffect::yaw);
public static final ParticleEffect.Factory<FootprintParticleEffect> FACTORY = ParticleFactoryHelper.of(FootprintParticleEffect::new, FootprintParticleEffect::new); public static final PacketCodec<ByteBuf, FootprintParticleEffect> PACKET_CODEC = PacketCodecs.FLOAT.xmap(FootprintParticleEffect::new, FootprintParticleEffect::yaw);
protected FootprintParticleEffect(ParticleType<FootprintParticleEffect> type, StringReader reader) throws CommandSyntaxException {
this(ParticleFactoryHelper.readFloat(reader));
}
protected FootprintParticleEffect(ParticleType<FootprintParticleEffect> particleType, PacketByteBuf buf) {
this(buf.readFloat());
}
@Override @Override
public ParticleType<?> getType() { public ParticleType<?> getType() {
return UParticles.FOOTPRINT; 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);
}
} }

View file

@ -2,10 +2,15 @@ package com.minelittlepony.unicopia.particle;
import java.util.Optional; import java.util.Optional;
import com.mojang.brigadier.StringReader; import com.minelittlepony.unicopia.util.CodecUtils;
import com.mojang.brigadier.exceptions.CommandSyntaxException; 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.ParticleEffect;
import net.minecraft.particle.ParticleType; import net.minecraft.particle.ParticleType;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -18,40 +23,25 @@ public record LightningBoltParticleEffect (
Optional<Vec3d> pathEndPoint Optional<Vec3d> pathEndPoint
) implements ParticleEffect { ) implements ParticleEffect {
public static final LightningBoltParticleEffect DEFAULT = new LightningBoltParticleEffect(false, 10, 6, 3, Optional.empty()); public static final LightningBoltParticleEffect DEFAULT = new LightningBoltParticleEffect(false, 10, 6, 3, Optional.empty());
@SuppressWarnings("deprecation")
public static final ParticleEffect.Factory<LightningBoltParticleEffect> FACTORY = ParticleFactoryHelper.of(LightningBoltParticleEffect::new, LightningBoltParticleEffect::new);
protected LightningBoltParticleEffect(ParticleType<LightningBoltParticleEffect> particleType, StringReader reader) throws CommandSyntaxException { public static final MapCodec<LightningBoltParticleEffect> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
this( Codec.BOOL.fieldOf("silent").forGetter(LightningBoltParticleEffect::silent),
ParticleFactoryHelper.readBoolean(reader), Codec.INT.fieldOf("changeFrequency").forGetter(LightningBoltParticleEffect::changeFrequency),
ParticleFactoryHelper.readInt(reader), Codec.INT.fieldOf("maxBranches").forGetter(LightningBoltParticleEffect::maxBranches),
ParticleFactoryHelper.readInt(reader), Codec.FLOAT.fieldOf("maxDeviation").forGetter(LightningBoltParticleEffect::maxDeviation),
ParticleFactoryHelper.readFloat(reader), CodecUtils.VECTOR.optionalFieldOf("pathEndPoint").forGetter(LightningBoltParticleEffect::pathEndPoint)
ParticleFactoryHelper.readOptional(reader, ParticleFactoryHelper::readVector) ).apply(instance, LightningBoltParticleEffect::new));
); public static final PacketCodec<RegistryByteBuf, LightningBoltParticleEffect> PACKET_CODEC = PacketCodec.tuple(
} PacketCodecs.BOOL, LightningBoltParticleEffect::silent,
PacketCodecs.INTEGER, LightningBoltParticleEffect::changeFrequency,
protected LightningBoltParticleEffect(ParticleType<LightningBoltParticleEffect> particleType, PacketByteBuf buf) { PacketCodecs.INTEGER, LightningBoltParticleEffect::maxBranches,
this(buf.readBoolean(), buf.readInt(), buf.readInt(), buf.readFloat(), ParticleFactoryHelper.OPTIONAL_VECTOR_CODEC.read(buf)); PacketCodecs.FLOAT, LightningBoltParticleEffect::maxDeviation,
} PacketCodecUtils.OPTIONAL_VECTOR, LightningBoltParticleEffect::pathEndPoint,
LightningBoltParticleEffect::new
);
@Override @Override
public ParticleType<?> getType() { public ParticleType<?> getType() {
return UParticles.LIGHTNING_BOLT; 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);
}
} }

View file

@ -1,35 +1,34 @@
package com.minelittlepony.unicopia.particle; package com.minelittlepony.unicopia.particle;
import java.util.Locale;
import org.joml.Vector3f; import org.joml.Vector3f;
import com.minelittlepony.common.util.Color; import com.minelittlepony.common.util.Color;
import com.mojang.brigadier.StringReader; import com.mojang.serialization.Codec;
import com.mojang.brigadier.exceptions.CommandSyntaxException; 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.ParticleEffect;
import net.minecraft.particle.ParticleType; 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.util.math.random.Random;
import net.minecraft.registry.Registries;
public record MagicParticleEffect ( public record MagicParticleEffect (
boolean tinted, boolean tinted,
Vector3f color Vector3f color
) implements ParticleEffect { ) implements ParticleEffect {
public static final MagicParticleEffect UNICORN = new MagicParticleEffect(false, new Vector3f()); public static final MagicParticleEffect UNICORN = new MagicParticleEffect(false, new Vector3f());
@SuppressWarnings("deprecation") public static final MapCodec<MagicParticleEffect> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
public static final ParticleEffect.Factory<MagicParticleEffect> FACTORY = ParticleFactoryHelper.of(MagicParticleEffect::new, MagicParticleEffect::new); Codec.BOOL.fieldOf("tinted").forGetter(MagicParticleEffect::tinted),
Codecs.VECTOR_3F.fieldOf("color").forGetter(MagicParticleEffect::color)
protected MagicParticleEffect(ParticleType<MagicParticleEffect> particleType, StringReader reader) throws CommandSyntaxException { ).apply(instance, MagicParticleEffect::new));
this(ParticleFactoryHelper.readBoolean(reader), AbstractDustParticleEffect.readColor(reader)); public static final PacketCodec<ByteBuf, MagicParticleEffect> PACKET_CODEC = PacketCodec.tuple(
} PacketCodecs.BOOL, MagicParticleEffect::tinted,
PacketCodecs.VECTOR3F, MagicParticleEffect::color,
protected MagicParticleEffect(ParticleType<MagicParticleEffect> particleType, PacketByteBuf buf) { MagicParticleEffect::new
this(buf.readBoolean(), AbstractDustParticleEffect.readColor(buf)); );
}
public MagicParticleEffect(int tint) { public MagicParticleEffect(int tint) {
this(true, new Vector3f(Color.r(tint), Color.g(tint), Color.b(tint))); this(true, new Vector3f(Color.r(tint), Color.g(tint), Color.b(tint)));
@ -61,18 +60,4 @@ public record MagicParticleEffect (
public ParticleType<?> getType() { public ParticleType<?> getType() {
return UParticles.UNICORN_MAGIC; 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);
}
} }

View file

@ -1,15 +1,15 @@
package com.minelittlepony.unicopia.particle; package com.minelittlepony.unicopia.particle;
import java.util.Locale; import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.brigadier.StringReader; import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.particle.ParticleEffect; import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleType; 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.util.math.Vec3d;
import net.minecraft.registry.Registries;
public record OrientedBillboardParticleEffect ( public record OrientedBillboardParticleEffect (
ParticleType<OrientedBillboardParticleEffect> type, ParticleType<OrientedBillboardParticleEffect> type,
@ -17,15 +17,21 @@ public record OrientedBillboardParticleEffect (
float yaw, float yaw,
float pitch float pitch
) implements ParticleEffect { ) implements ParticleEffect {
@SuppressWarnings("deprecation") public static MapCodec<OrientedBillboardParticleEffect> createCodec(ParticleType<OrientedBillboardParticleEffect> type) {
public static final ParticleEffect.Factory<OrientedBillboardParticleEffect> FACTORY = ParticleFactoryHelper.of(OrientedBillboardParticleEffect::new, OrientedBillboardParticleEffect::new); return RecordCodecBuilder.mapCodec(instance -> instance.group(
Codec.BOOL.fieldOf("fixed").forGetter(OrientedBillboardParticleEffect::fixed),
protected OrientedBillboardParticleEffect(ParticleType<OrientedBillboardParticleEffect> type, StringReader reader) throws CommandSyntaxException { Codec.FLOAT.fieldOf("yaw").forGetter(OrientedBillboardParticleEffect::yaw),
this(type, ParticleFactoryHelper.readBoolean(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readFloat(reader)); Codec.FLOAT.fieldOf("pitch").forGetter(OrientedBillboardParticleEffect::pitch)
).apply(instance, (fixed, yaw, pitch) -> new OrientedBillboardParticleEffect(type, fixed, yaw, pitch)));
} }
protected OrientedBillboardParticleEffect(ParticleType<OrientedBillboardParticleEffect> particleType, PacketByteBuf buf) { public static final PacketCodec<RegistryByteBuf, OrientedBillboardParticleEffect> createPacketCodec(ParticleType<OrientedBillboardParticleEffect> type) {
this(particleType, buf.readBoolean(), buf.readFloat(), buf.readFloat()); 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<OrientedBillboardParticleEffect> type, Vec3d orientation) { public OrientedBillboardParticleEffect(ParticleType<OrientedBillboardParticleEffect> type, Vec3d orientation) {
@ -40,17 +46,4 @@ public record OrientedBillboardParticleEffect (
public ParticleType<?> getType() { public ParticleType<?> getType() {
return type; 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);
}
} }

View file

@ -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<ParticleEffect> 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<ParticleEffect>> OPTIONAL_PARTICLE_EFFECT_CODEC = PARTICLE_EFFECT_CODEC.asOptional();
PacketCodec<Vec3d> 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<Vec3d>> OPTIONAL_VECTOR_CODEC = VECTOR_CODEC.asOptional();
@SuppressWarnings("unchecked")
static <T extends ParticleEffect> 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 <T> Optional<T> readOptional(StringReader reader, ReaderFunc<T> 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 <T extends ParticleEffect> ParticleEffect.Factory<T> of(CommandReader<T> commandReader, PacketReader<T> packetReader) {
return new ParticleEffect.Factory<>() {
@Override
public T read(ParticleType<T> type, StringReader reader) throws CommandSyntaxException {
return commandReader.read(type, reader);
}
@Override
public T read(ParticleType<T> type, PacketByteBuf buf) {
return packetReader.read(type, buf);
}
};
}
interface ReaderFunc<T> {
T read(StringReader reader) throws CommandSyntaxException;
}
interface CommandReader<T extends ParticleEffect> {
T read(ParticleType<T> type, StringReader reader) throws CommandSyntaxException;
}
interface PacketReader<T extends ParticleEffect> {
T read(ParticleType<T> type, PacketByteBuf buf);
}
}

View file

@ -1,19 +1,21 @@
package com.minelittlepony.unicopia.particle; package com.minelittlepony.unicopia.particle;
import java.util.Locale;
import org.joml.Vector3f; import org.joml.Vector3f;
import com.minelittlepony.common.util.Color; import com.minelittlepony.common.util.Color;
import com.mojang.brigadier.StringReader; import com.minelittlepony.unicopia.util.CodecUtils;
import com.mojang.brigadier.exceptions.CommandSyntaxException; 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.ParticleEffect;
import net.minecraft.particle.ParticleType; 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.util.math.Vec3d;
import net.minecraft.registry.Registries;
public record SphereParticleEffect ( public record SphereParticleEffect (
ParticleType<? extends SphereParticleEffect> type, ParticleType<? extends SphereParticleEffect> type,
@ -22,17 +24,24 @@ public record SphereParticleEffect (
float radius, float radius,
Vec3d offset Vec3d offset
) implements ParticleEffect { ) implements ParticleEffect {
@SuppressWarnings("deprecation")
public static final Factory<SphereParticleEffect> FACTORY = ParticleFactoryHelper.of(SphereParticleEffect::new, SphereParticleEffect::new);
private static final Vec3d DEFAULT_OFFSET = new Vec3d(0, 0.5, 0); private static final Vec3d DEFAULT_OFFSET = new Vec3d(0, 0.5, 0);
public static MapCodec<SphereParticleEffect> createCodec(ParticleType<SphereParticleEffect> type) {
protected SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, StringReader reader) throws CommandSyntaxException { return RecordCodecBuilder.mapCodec(instance -> instance.group(
this(type, AbstractDustParticleEffect.readColor(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readFloat(reader), ParticleFactoryHelper.readVector(reader)); 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<? extends SphereParticleEffect> type, PacketByteBuf buf) { public static final PacketCodec<RegistryByteBuf, SphereParticleEffect> createPacketCodec(ParticleType<SphereParticleEffect> type) {
this(type, buf.readVector3f(), buf.readFloat(), buf.readFloat(), ParticleFactoryHelper.VECTOR_CODEC.read(buf)); 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<? extends SphereParticleEffect> type, int tint, float alpha, float rad) { public SphereParticleEffect(ParticleType<? extends SphereParticleEffect> type, int tint, float alpha, float rad) {
@ -55,23 +64,4 @@ public record SphereParticleEffect (
public ParticleType<?> getType() { public ParticleType<?> getType() {
return type; 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()
);
}
} }

View file

@ -1,48 +1,35 @@
package com.minelittlepony.unicopia.particle; package com.minelittlepony.unicopia.particle;
import com.mojang.brigadier.StringReader; import com.mojang.serialization.Codec;
import com.mojang.brigadier.exceptions.CommandSyntaxException; 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.ParticleEffect;
import net.minecraft.particle.ParticleType; import net.minecraft.particle.ParticleType;
import net.minecraft.particle.ParticleTypes;
public record SpiralParticleEffect( public record SpiralParticleEffect(
WeakTarget centerPoint, WeakTarget centerPoint,
float angularVelocity, float angularVelocity,
ParticleEffect effect ParticleEffect effect
) implements ParticleEffect { ) implements ParticleEffect {
@SuppressWarnings("deprecation") public static final MapCodec<SpiralParticleEffect> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
public static final Factory<SpiralParticleEffect> FACTORY = ParticleFactoryHelper.of(SpiralParticleEffect::new, SpiralParticleEffect::new); WeakTarget.CODEC.fieldOf("centerPoint").forGetter(SpiralParticleEffect::centerPoint),
Codec.FLOAT.fieldOf("angularVelocity").forGetter(SpiralParticleEffect::angularVelocity),
protected SpiralParticleEffect(ParticleType<SpiralParticleEffect> type, StringReader reader) throws CommandSyntaxException { ParticleTypes.TYPE_CODEC.fieldOf("effect").forGetter(SpiralParticleEffect::effect)
this(new WeakTarget(reader), ).apply(instance, SpiralParticleEffect::new));
ParticleFactoryHelper.readFloat(reader), public static final PacketCodec<RegistryByteBuf, SpiralParticleEffect> PACKET_CODEC = PacketCodec.tuple(
ParticleFactoryHelper.read(reader) WeakTarget.PACKET_CODEC, SpiralParticleEffect::centerPoint,
); PacketCodecs.FLOAT, SpiralParticleEffect::angularVelocity,
} ParticleTypes.PACKET_CODEC, SpiralParticleEffect::effect,
SpiralParticleEffect::new
protected SpiralParticleEffect(ParticleType<SpiralParticleEffect> type, PacketByteBuf buf) { );
this(new WeakTarget(buf),
buf.readFloat(),
ParticleFactoryHelper.PARTICLE_EFFECT_CODEC.read(buf)
);
}
@Override @Override
public ParticleType<?> getType() { public ParticleType<?> getType() {
return UParticles.SPIRAL; 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;
}
} }

View file

@ -1,57 +1,36 @@
package com.minelittlepony.unicopia.particle; package com.minelittlepony.unicopia.particle;
import java.util.Locale;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.mojang.brigadier.StringReader; import com.mojang.serialization.Codec;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.serialization.MapCodec;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; 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.ParticleEffect;
import net.minecraft.particle.ParticleType; import net.minecraft.particle.ParticleType;
import net.minecraft.registry.Registries;
public class TargetBoundParticleEffect implements ParticleEffect { public record TargetBoundParticleEffect (
@SuppressWarnings("deprecation") ParticleType<TargetBoundParticleEffect> type,
public static final Factory<TargetBoundParticleEffect> FACTORY = ParticleFactoryHelper.of(TargetBoundParticleEffect::new, TargetBoundParticleEffect::new); int targetId
) implements ParticleEffect {
private final ParticleType<TargetBoundParticleEffect> type; public static MapCodec<TargetBoundParticleEffect> createCodec(ParticleType<TargetBoundParticleEffect> type) {
private final int targetId; return Codec.INT.fieldOf("targetId").xmap(targetId -> new TargetBoundParticleEffect(type, targetId), TargetBoundParticleEffect::targetId);
protected TargetBoundParticleEffect(ParticleType<TargetBoundParticleEffect> type, StringReader reader) throws CommandSyntaxException {
this.type = type;
this.targetId = -1;
} }
protected TargetBoundParticleEffect(ParticleType<TargetBoundParticleEffect> type, PacketByteBuf buf) { public static final PacketCodec<ByteBuf, TargetBoundParticleEffect> createPacketCodec(ParticleType<TargetBoundParticleEffect> type) {
this.type = type; return PacketCodecs.INTEGER.xmap(targetId -> new TargetBoundParticleEffect(type, targetId), TargetBoundParticleEffect::targetId);
this.targetId = buf.readInt();
} }
public TargetBoundParticleEffect(ParticleType<TargetBoundParticleEffect> type, @Nullable Entity target) { public TargetBoundParticleEffect(ParticleType<TargetBoundParticleEffect> type, @Nullable Entity target) {
this.type = type; this(type, target == null ? -1 : target.getId());
this.targetId = target == null ? -1 : target.getId();
}
public int getTargetId() {
return targetId;
} }
@Override @Override
public ParticleType<?> getType() { public ParticleType<?> getType() {
return type; 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);
}
} }

View file

@ -10,29 +10,28 @@ import net.minecraft.registry.Registry;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
public interface UParticles { public interface UParticles {
ParticleType<MagicParticleEffect> UNICORN_MAGIC = register("unicorn_magic", FabricParticleTypes.complex(MagicParticleEffect.CODEC, MagicParticleEffect.PACKET_CODEC));
ParticleType<MagicParticleEffect> UNICORN_MAGIC = register("unicorn_magic", FabricParticleTypes.complex(MagicParticleEffect.FACTORY));
SimpleParticleType CHANGELING_MAGIC = register("changeling_magic", FabricParticleTypes.simple()); SimpleParticleType CHANGELING_MAGIC = register("changeling_magic", FabricParticleTypes.simple());
SimpleParticleType BUBBLE = register("bubble", FabricParticleTypes.simple()); SimpleParticleType BUBBLE = register("bubble", FabricParticleTypes.simple());
ParticleType<FootprintParticleEffect> FOOTPRINT = register("footprint", FabricParticleTypes.complex(FootprintParticleEffect.FACTORY)); ParticleType<FootprintParticleEffect> FOOTPRINT = register("footprint", FabricParticleTypes.complex(FootprintParticleEffect.CODEC, FootprintParticleEffect.PACKET_CODEC));
ParticleType<BlockStateParticleEffect> DUST_CLOUD = register("dust_cloud", FabricParticleTypes.complex(BlockStateParticleEffect.PARAMETERS_FACTORY)); ParticleType<BlockStateParticleEffect> DUST_CLOUD = register("dust_cloud", FabricParticleTypes.complex(BlockStateParticleEffect::createCodec, BlockStateParticleEffect::createPacketCodec));
ParticleType<OrientedBillboardParticleEffect> RAINBOOM_RING = register("rainboom_ring", FabricParticleTypes.complex(OrientedBillboardParticleEffect.FACTORY)); ParticleType<OrientedBillboardParticleEffect> RAINBOOM_RING = register("rainboom_ring", FabricParticleTypes.complex(OrientedBillboardParticleEffect::createCodec, OrientedBillboardParticleEffect::createPacketCodec));
ParticleType<TargetBoundParticleEffect> RAINBOOM_TRAIL = register("rainboom_trail", FabricParticleTypes.complex(TargetBoundParticleEffect.FACTORY)); ParticleType<TargetBoundParticleEffect> RAINBOOM_TRAIL = register("rainboom_trail", FabricParticleTypes.complex(TargetBoundParticleEffect::createCodec, TargetBoundParticleEffect::createPacketCodec));
ParticleType<TargetBoundParticleEffect> WIND = register("wind", FabricParticleTypes.complex(TargetBoundParticleEffect.FACTORY)); ParticleType<TargetBoundParticleEffect> WIND = register("wind", FabricParticleTypes.complex(TargetBoundParticleEffect::createCodec, TargetBoundParticleEffect::createPacketCodec));
SimpleParticleType RAIN_DROPS = register("rain_drops", FabricParticleTypes.simple()); SimpleParticleType RAIN_DROPS = register("rain_drops", FabricParticleTypes.simple());
ParticleType<SphereParticleEffect> SPHERE = register("sphere", FabricParticleTypes.complex(true, SphereParticleEffect.FACTORY)); ParticleType<SphereParticleEffect> SPHERE = register("sphere", FabricParticleTypes.complex(true, SphereParticleEffect::createCodec, SphereParticleEffect::createPacketCodec));
ParticleType<SphereParticleEffect> DISK = register("disk", FabricParticleTypes.complex(true, SphereParticleEffect.FACTORY)); ParticleType<SphereParticleEffect> DISK = register("disk", FabricParticleTypes.complex(true, SphereParticleEffect::createCodec, SphereParticleEffect::createPacketCodec));
ParticleType<FollowingParticleEffect> HEALTH_DRAIN = register("health_drain", FabricParticleTypes.complex(true, FollowingParticleEffect.FACTORY)); ParticleType<FollowingParticleEffect> HEALTH_DRAIN = register("health_drain", FabricParticleTypes.complex(true, FollowingParticleEffect::createCodec, FollowingParticleEffect::createPacketCodec));
ParticleType<SpiralParticleEffect> SPIRAL = register("spiral", FabricParticleTypes.complex(true, SpiralParticleEffect.FACTORY)); ParticleType<SpiralParticleEffect> SPIRAL = register("spiral", FabricParticleTypes.complex(true, SpiralParticleEffect.CODEC, SpiralParticleEffect.PACKET_CODEC));
SimpleParticleType GROUND_POUND = register("ground_pound", FabricParticleTypes.simple()); SimpleParticleType GROUND_POUND = register("ground_pound", FabricParticleTypes.simple());
SimpleParticleType CLOUDS_ESCAPING = register("clouds_escaping", FabricParticleTypes.simple(true)); SimpleParticleType CLOUDS_ESCAPING = register("clouds_escaping", FabricParticleTypes.simple(true));
ParticleType<LightningBoltParticleEffect> LIGHTNING_BOLT = register("lightning_bolt", FabricParticleTypes.complex(true, LightningBoltParticleEffect.FACTORY)); ParticleType<LightningBoltParticleEffect> LIGHTNING_BOLT = register("lightning_bolt", FabricParticleTypes.complex(true, LightningBoltParticleEffect.CODEC, LightningBoltParticleEffect.PACKET_CODEC));
SimpleParticleType SHOCKWAVE = register("shockwave", FabricParticleTypes.simple(true)); SimpleParticleType SHOCKWAVE = register("shockwave", FabricParticleTypes.simple(true));
static <T extends ParticleType<?>> T register(String name, T type) { static <T extends ParticleType<?>> T register(String name, T type) {

View file

@ -2,30 +2,42 @@ package com.minelittlepony.unicopia.particle;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.mojang.brigadier.StringReader; import com.minelittlepony.unicopia.util.CodecUtils;
import com.mojang.brigadier.exceptions.CommandSyntaxException; 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.entity.Entity;
import net.minecraft.network.PacketByteBuf; 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.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
public class WeakTarget { public class WeakTarget {
public static final Codec<WeakTarget> 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<PacketByteBuf, WeakTarget> PACKET_CODEC = PacketCodec.tuple(
PacketCodecUtils.VECTOR, i -> i.fixedPosition,
PacketCodecs.INTEGER, i -> i.targetId,
WeakTarget::new
);
Vec3d fixedPosition; Vec3d fixedPosition;
private int targetId; private int targetId;
public WeakTarget(Vec3d fixedPosition, @Nullable Entity entity) { private WeakTarget(Vec3d fixedPosition, int targetId) {
this.fixedPosition = fixedPosition; this.fixedPosition = fixedPosition;
targetId = entity == null ? -1 : entity.getId(); this.targetId = targetId;
} }
public WeakTarget(PacketByteBuf buf) { public WeakTarget(Vec3d fixedPosition, @Nullable Entity entity) {
fixedPosition = ParticleFactoryHelper.VECTOR_CODEC.read(buf); this(fixedPosition, entity == null ? -1 : entity.getId());
targetId = buf.readInt();
}
public WeakTarget(StringReader reader) throws CommandSyntaxException {
this(ParticleFactoryHelper.readVector(reader), null);
} }
public Vec3d getPosition(World world) { public Vec3d getPosition(World world) {
@ -47,9 +59,4 @@ public class WeakTarget {
} }
return "Fixed(" + fixedPosition + ")"; return "Fixed(" + fixedPosition + ")";
} }
public void write(PacketByteBuf buf) {
ParticleFactoryHelper.VECTOR_CODEC.write(buf, fixedPosition);
buf.writeInt(targetId);
}
} }

View file

@ -14,15 +14,23 @@ import com.mojang.serialization.Decoder;
import com.mojang.serialization.DynamicOps; import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Encoder; import com.mojang.serialization.Encoder;
import com.mojang.serialization.MapCodec; import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.fabricmc.fabric.api.util.TriState; import net.fabricmc.fabric.api.util.TriState;
import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemConvertible;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.util.dynamic.Codecs; import net.minecraft.util.dynamic.Codecs;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public interface CodecUtils { public interface CodecUtils {
Codec<ItemConvertible> ITEM = Registries.ITEM.getCodec().xmap(i -> () -> i, ItemConvertible::asItem); Codec<ItemConvertible> ITEM = Registries.ITEM.getCodec().xmap(i -> () -> i, ItemConvertible::asItem);
Codec<Optional<BlockPos>> OPTIONAL_POS = Codecs.optional(BlockPos.CODEC); Codec<Optional<BlockPos>> OPTIONAL_POS = Codecs.optional(BlockPos.CODEC);
Codec<Vec3d> 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. * Combines the result of two unrelated codecs into a single object.
* <p> * <p>