diff --git a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java index 24d713f28..11aa7656e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/base/KineticBlock.java @@ -66,10 +66,11 @@ public abstract class KineticBlock extends Block implements IRotate { @Override public abstract TileEntity createTileEntity(BlockState state, IBlockReader world); + // TODO 1.16 is this the right replacement for updateNeighbors? @Override - @SuppressWarnings("deprecation") - public void updateNeighbors(BlockState stateIn, IWorld worldIn, BlockPos pos, int flags) { - super.updateNeighbors(stateIn, worldIn, pos, flags); + @Deprecated + public void updateDiagonalNeighbors(BlockState stateIn, IWorld worldIn, BlockPos pos, int flags, int count) { + super.updateDiagonalNeighbors(stateIn, worldIn, pos, flags, count); if (worldIn.isRemote()) return; diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticleData.java b/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticleData.java index 725f2d8ef..530cd06de 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticleData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/AirFlowParticleData.java @@ -4,6 +4,8 @@ import java.util.Locale; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import com.simibubi.create.AllParticleTypes; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; @@ -15,6 +17,13 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; public class AirFlowParticleData implements IParticleData, ICustomParticle { + + public static final Codec CODEC = RecordCodecBuilder.create(i -> + i.group( + Codec.INT.fieldOf("x").forGetter(p -> p.posX), + Codec.INT.fieldOf("y").forGetter(p -> p.posY), + Codec.INT.fieldOf("z").forGetter(p -> p.posZ)) + .apply(i, AirFlowParticleData::new)); public static final IParticleData.IDeserializer DESERIALIZER = new IParticleData.IDeserializer() { public AirFlowParticleData deserialize(ParticleType particleTypeIn, StringReader reader) @@ -72,6 +81,11 @@ public class AirFlowParticleData implements IParticleData, ICustomParticle getDeserializer() { return DESERIALIZER; } + + @Override + public Codec getCodec() { + return CODEC; + } @Override @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/AirParticleData.java b/src/main/java/com/simibubi/create/content/contraptions/particle/AirParticleData.java index 3f40c9576..7c0d6e153 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/AirParticleData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/AirParticleData.java @@ -4,6 +4,8 @@ import java.util.Locale; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import com.simibubi.create.AllParticleTypes; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; @@ -15,6 +17,12 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class AirParticleData implements IParticleData, ICustomParticle { + public static final Codec CODEC = RecordCodecBuilder.create(i -> + i.group( + Codec.FLOAT.fieldOf("drag").forGetter(p -> p.drag), + Codec.FLOAT.fieldOf("speed").forGetter(p -> p.speed)) + .apply(i, AirParticleData::new)); + public static final IParticleData.IDeserializer DESERIALIZER = new IParticleData.IDeserializer() { public AirParticleData deserialize(ParticleType particleTypeIn, StringReader reader) @@ -64,6 +72,11 @@ public class AirParticleData implements IParticleData, ICustomParticle getCodec() { + return CODEC; + } + @Override @OnlyIn(Dist.CLIENT) public IParticleMetaFactory getFactory() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/CubeParticleData.java b/src/main/java/com/simibubi/create/content/contraptions/particle/CubeParticleData.java index dc22608c7..78c5bdb49 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/CubeParticleData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/CubeParticleData.java @@ -4,6 +4,8 @@ import java.util.Locale; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import com.simibubi.create.AllParticleTypes; import net.minecraft.client.particle.ParticleManager; @@ -15,6 +17,16 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class CubeParticleData implements IParticleData, ICustomParticle { + public static final Codec CODEC = RecordCodecBuilder.create(i -> + i.group( + Codec.FLOAT.fieldOf("r").forGetter(p -> p.r), + Codec.FLOAT.fieldOf("g").forGetter(p -> p.g), + Codec.FLOAT.fieldOf("b").forGetter(p -> p.b), + Codec.FLOAT.fieldOf("scale").forGetter(p -> p.scale), + Codec.INT.fieldOf("avgAge").forGetter(p -> p.avgAge), + Codec.BOOL.fieldOf("hot").forGetter(p -> p.hot)) + .apply(i, CubeParticleData::new)); + public static final IParticleData.IDeserializer DESERIALIZER = new IParticleData.IDeserializer() { @Override public CubeParticleData deserialize(ParticleType type, StringReader reader) throws CommandSyntaxException { @@ -64,6 +76,11 @@ public class CubeParticleData implements IParticleData, ICustomParticle getCodec() { + return CODEC; + } + @Override @OnlyIn(Dist.CLIENT) public ParticleManager.IParticleMetaFactory getFactory() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/HeaterParticleData.java b/src/main/java/com/simibubi/create/content/contraptions/particle/HeaterParticleData.java index 54d5e1626..1cddd3dcb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/HeaterParticleData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/HeaterParticleData.java @@ -6,6 +6,8 @@ import javax.annotation.ParametersAreNonnullByDefault; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import com.simibubi.create.AllParticleTypes; import mcp.MethodsReturnNonnullByDefault; @@ -20,6 +22,13 @@ import net.minecraftforge.api.distmarker.OnlyIn; @MethodsReturnNonnullByDefault public class HeaterParticleData implements IParticleData, ICustomParticle { + public static final Codec CODEC = RecordCodecBuilder.create(i -> + i.group( + Codec.FLOAT.fieldOf("r").forGetter(p -> p.r), + Codec.FLOAT.fieldOf("g").forGetter(p -> p.g), + Codec.FLOAT.fieldOf("b").forGetter(p -> p.b)) + .apply(i, HeaterParticleData::new)); + public static final IParticleData.IDeserializer DESERIALIZER = new IParticleData.IDeserializer() { @Override @@ -59,6 +68,11 @@ public class HeaterParticleData implements IParticleData, ICustomParticle getCodec() { + return CODEC; + } + @Override @OnlyIn(Dist.CLIENT) public IParticleMetaFactory getFactory() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticle.java b/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticle.java index 341094dcb..d288b6317 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticle.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticle.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.contraptions.particle; +import com.mojang.serialization.Codec; + import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; import net.minecraft.particles.IParticleData; import net.minecraft.particles.IParticleData.IDeserializer; @@ -9,10 +11,18 @@ import net.minecraftforge.api.distmarker.OnlyIn; public interface ICustomParticle { - public IDeserializer getDeserializer(); + IDeserializer getDeserializer(); + + Codec getCodec(); public default ParticleType createType() { - return new ParticleType(false, getDeserializer()); + return new ParticleType(false, getDeserializer()) { + + @Override + public Codec getCodec() { + return ICustomParticle.this.getCodec(); + } + }; } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticleData.java b/src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticleData.java index 846ed9085..7520e477a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticleData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/RotationIndicatorParticleData.java @@ -4,6 +4,11 @@ import java.util.Locale; import com.mojang.brigadier.StringReader; import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.codecs.PrimitiveCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import com.simibubi.create.AllParticleTypes; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; @@ -16,6 +21,36 @@ import net.minecraftforge.api.distmarker.OnlyIn; public class RotationIndicatorParticleData implements IParticleData, ICustomParticle { + // TODO 1.16 make this unnecessary + public static final PrimitiveCodec CHAR = new PrimitiveCodec() { + @Override + public DataResult read(final DynamicOps ops, final T input) { + return ops + .getNumberValue(input) + .map(n -> (char) n.shortValue()); + } + + @Override + public T write(final DynamicOps ops, final Character value) { + return ops.createShort((short) value.charValue()); + } + + @Override + public String toString() { + return "Bool"; + } + }; + + public static final Codec CODEC = RecordCodecBuilder.create(i -> + i.group( + Codec.INT.fieldOf("color").forGetter(p -> p.color), + Codec.FLOAT.fieldOf("speed").forGetter(p -> p.speed), + Codec.FLOAT.fieldOf("radius1").forGetter(p -> p.radius1), + Codec.FLOAT.fieldOf("radius2").forGetter(p -> p.radius2), + Codec.INT.fieldOf("lifeSpan").forGetter(p -> p.lifeSpan), + CHAR.fieldOf("axis").forGetter(p -> p.axis)) + .apply(i, RotationIndicatorParticleData::new)); + public static final IParticleData.IDeserializer DESERIALIZER = new IParticleData.IDeserializer() { public RotationIndicatorParticleData deserialize(ParticleType particleTypeIn, StringReader reader) throws CommandSyntaxException { @@ -92,6 +127,11 @@ public class RotationIndicatorParticleData implements IParticleData, ICustomPart return DESERIALIZER; } + @Override + public Codec getCodec() { + return CODEC; + } + @Override @OnlyIn(Dist.CLIENT) public IParticleMetaFactory getFactory() {