More porting, fix updateNeighbors and particle codecs

This commit is contained in:
tterrag 2020-10-03 16:14:14 -04:00
parent 92a6e32b19
commit 74fadd94d6
7 changed files with 114 additions and 5 deletions

View file

@ -66,10 +66,11 @@ public abstract class KineticBlock extends Block implements IRotate {
@Override @Override
public abstract TileEntity createTileEntity(BlockState state, IBlockReader world); public abstract TileEntity createTileEntity(BlockState state, IBlockReader world);
// TODO 1.16 is this the right replacement for updateNeighbors?
@Override @Override
@SuppressWarnings("deprecation") @Deprecated
public void updateNeighbors(BlockState stateIn, IWorld worldIn, BlockPos pos, int flags) { public void updateDiagonalNeighbors(BlockState stateIn, IWorld worldIn, BlockPos pos, int flags, int count) {
super.updateNeighbors(stateIn, worldIn, pos, flags); super.updateDiagonalNeighbors(stateIn, worldIn, pos, flags, count);
if (worldIn.isRemote()) if (worldIn.isRemote())
return; return;

View file

@ -4,6 +4,8 @@ import java.util.Locale;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.simibubi.create.AllParticleTypes; import com.simibubi.create.AllParticleTypes;
import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory;
@ -16,6 +18,13 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public class AirFlowParticleData implements IParticleData, ICustomParticle<AirFlowParticleData> { public class AirFlowParticleData implements IParticleData, ICustomParticle<AirFlowParticleData> {
public static final Codec<AirFlowParticleData> 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<AirFlowParticleData> DESERIALIZER = new IParticleData.IDeserializer<AirFlowParticleData>() { public static final IParticleData.IDeserializer<AirFlowParticleData> DESERIALIZER = new IParticleData.IDeserializer<AirFlowParticleData>() {
public AirFlowParticleData deserialize(ParticleType<AirFlowParticleData> particleTypeIn, StringReader reader) public AirFlowParticleData deserialize(ParticleType<AirFlowParticleData> particleTypeIn, StringReader reader)
throws CommandSyntaxException { throws CommandSyntaxException {
@ -73,6 +82,11 @@ public class AirFlowParticleData implements IParticleData, ICustomParticle<AirFl
return DESERIALIZER; return DESERIALIZER;
} }
@Override
public Codec<AirFlowParticleData> getCodec() {
return CODEC;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IParticleMetaFactory<AirFlowParticleData> getFactory() { public IParticleMetaFactory<AirFlowParticleData> getFactory() {

View file

@ -4,6 +4,8 @@ import java.util.Locale;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.simibubi.create.AllParticleTypes; import com.simibubi.create.AllParticleTypes;
import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory;
@ -15,6 +17,12 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public class AirParticleData implements IParticleData, ICustomParticle<AirParticleData> { public class AirParticleData implements IParticleData, ICustomParticle<AirParticleData> {
public static final Codec<AirParticleData> 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<AirParticleData> DESERIALIZER = public static final IParticleData.IDeserializer<AirParticleData> DESERIALIZER =
new IParticleData.IDeserializer<AirParticleData>() { new IParticleData.IDeserializer<AirParticleData>() {
public AirParticleData deserialize(ParticleType<AirParticleData> particleTypeIn, StringReader reader) public AirParticleData deserialize(ParticleType<AirParticleData> particleTypeIn, StringReader reader)
@ -64,6 +72,11 @@ public class AirParticleData implements IParticleData, ICustomParticle<AirPartic
return DESERIALIZER; return DESERIALIZER;
} }
@Override
public Codec<AirParticleData> getCodec() {
return CODEC;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IParticleMetaFactory<AirParticleData> getFactory() { public IParticleMetaFactory<AirParticleData> getFactory() {

View file

@ -4,6 +4,8 @@ import java.util.Locale;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.simibubi.create.AllParticleTypes; import com.simibubi.create.AllParticleTypes;
import net.minecraft.client.particle.ParticleManager; import net.minecraft.client.particle.ParticleManager;
@ -15,6 +17,16 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public class CubeParticleData implements IParticleData, ICustomParticle<CubeParticleData> { public class CubeParticleData implements IParticleData, ICustomParticle<CubeParticleData> {
public static final Codec<CubeParticleData> 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<CubeParticleData> DESERIALIZER = new IParticleData.IDeserializer<CubeParticleData>() { public static final IParticleData.IDeserializer<CubeParticleData> DESERIALIZER = new IParticleData.IDeserializer<CubeParticleData>() {
@Override @Override
public CubeParticleData deserialize(ParticleType<CubeParticleData> type, StringReader reader) throws CommandSyntaxException { public CubeParticleData deserialize(ParticleType<CubeParticleData> type, StringReader reader) throws CommandSyntaxException {
@ -64,6 +76,11 @@ public class CubeParticleData implements IParticleData, ICustomParticle<CubePart
return DESERIALIZER; return DESERIALIZER;
} }
@Override
public Codec<CubeParticleData> getCodec() {
return CODEC;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public ParticleManager.IParticleMetaFactory<CubeParticleData> getFactory() { public ParticleManager.IParticleMetaFactory<CubeParticleData> getFactory() {

View file

@ -6,6 +6,8 @@ import javax.annotation.ParametersAreNonnullByDefault;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.simibubi.create.AllParticleTypes; import com.simibubi.create.AllParticleTypes;
import mcp.MethodsReturnNonnullByDefault; import mcp.MethodsReturnNonnullByDefault;
@ -20,6 +22,13 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@MethodsReturnNonnullByDefault @MethodsReturnNonnullByDefault
public class HeaterParticleData implements IParticleData, ICustomParticle<HeaterParticleData> { public class HeaterParticleData implements IParticleData, ICustomParticle<HeaterParticleData> {
public static final Codec<HeaterParticleData> 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<HeaterParticleData> DESERIALIZER = public static final IParticleData.IDeserializer<HeaterParticleData> DESERIALIZER =
new IParticleData.IDeserializer<HeaterParticleData>() { new IParticleData.IDeserializer<HeaterParticleData>() {
@Override @Override
@ -59,6 +68,11 @@ public class HeaterParticleData implements IParticleData, ICustomParticle<Heater
return DESERIALIZER; return DESERIALIZER;
} }
@Override
public Codec<HeaterParticleData> getCodec() {
return CODEC;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IParticleMetaFactory<HeaterParticleData> getFactory() { public IParticleMetaFactory<HeaterParticleData> getFactory() {

View file

@ -1,5 +1,7 @@
package com.simibubi.create.content.contraptions.particle; package com.simibubi.create.content.contraptions.particle;
import com.mojang.serialization.Codec;
import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory;
import net.minecraft.particles.IParticleData; import net.minecraft.particles.IParticleData;
import net.minecraft.particles.IParticleData.IDeserializer; import net.minecraft.particles.IParticleData.IDeserializer;
@ -9,10 +11,18 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public interface ICustomParticle<T extends IParticleData> { public interface ICustomParticle<T extends IParticleData> {
public IDeserializer<T> getDeserializer(); IDeserializer<T> getDeserializer();
Codec<T> getCodec();
public default ParticleType<T> createType() { public default ParticleType<T> createType() {
return new ParticleType<T>(false, getDeserializer()); return new ParticleType<T>(false, getDeserializer()) {
@Override
public Codec<T> getCodec() {
return ICustomParticle.this.getCodec();
}
};
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)

View file

@ -4,6 +4,11 @@ import java.util.Locale;
import com.mojang.brigadier.StringReader; import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; 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 com.simibubi.create.AllParticleTypes;
import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory;
@ -16,6 +21,36 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public class RotationIndicatorParticleData implements IParticleData, ICustomParticle<RotationIndicatorParticleData> { public class RotationIndicatorParticleData implements IParticleData, ICustomParticle<RotationIndicatorParticleData> {
// TODO 1.16 make this unnecessary
public static final PrimitiveCodec<Character> CHAR = new PrimitiveCodec<Character>() {
@Override
public <T> DataResult<Character> read(final DynamicOps<T> ops, final T input) {
return ops
.getNumberValue(input)
.map(n -> (char) n.shortValue());
}
@Override
public <T> T write(final DynamicOps<T> ops, final Character value) {
return ops.createShort((short) value.charValue());
}
@Override
public String toString() {
return "Bool";
}
};
public static final Codec<RotationIndicatorParticleData> 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<RotationIndicatorParticleData> DESERIALIZER = new IParticleData.IDeserializer<RotationIndicatorParticleData>() { public static final IParticleData.IDeserializer<RotationIndicatorParticleData> DESERIALIZER = new IParticleData.IDeserializer<RotationIndicatorParticleData>() {
public RotationIndicatorParticleData deserialize(ParticleType<RotationIndicatorParticleData> particleTypeIn, public RotationIndicatorParticleData deserialize(ParticleType<RotationIndicatorParticleData> particleTypeIn,
StringReader reader) throws CommandSyntaxException { StringReader reader) throws CommandSyntaxException {
@ -92,6 +127,11 @@ public class RotationIndicatorParticleData implements IParticleData, ICustomPart
return DESERIALIZER; return DESERIALIZER;
} }
@Override
public Codec<RotationIndicatorParticleData> getCodec() {
return CODEC;
}
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public IParticleMetaFactory<RotationIndicatorParticleData> getFactory() { public IParticleMetaFactory<RotationIndicatorParticleData> getFactory() {