diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/BasinFluidParticle.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/BasinFluidParticle.java index 44c1bafab..302976de8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/BasinFluidParticle.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/BasinFluidParticle.java @@ -6,22 +6,22 @@ import com.simibubi.create.content.contraptions.processing.BasinTileEntity; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.client.renderer.ActiveRenderInfo; -import net.minecraft.client.renderer.Quaternion; +import net.minecraft.client.world.ClientWorld; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; +import net.minecraft.util.math.vector.Quaternion; +import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.fluids.FluidStack; public class BasinFluidParticle extends FluidStackParticle { BlockPos basinPos; - Vec3d targetPos; - Vec3d centerOfBasin; + Vector3d targetPos; + Vector3d centerOfBasin; float yOffset; - public BasinFluidParticle(World world, FluidStack fluid, double x, double y, double z, double vx, double vy, + public BasinFluidParticle(ClientWorld world, FluidStack fluid, double x, double y, double z, double vx, double vy, double vz) { super(world, fluid, x, y, z, vx, vy, vz); particleGravity = 0; @@ -32,14 +32,14 @@ public class BasinFluidParticle extends FluidStackParticle { posY += yOffset; particleScale = 0; maxAge = 60; - Vec3d currentPos = new Vec3d(posX, posY, posZ); + Vector3d currentPos = new Vector3d(posX, posY, posZ); basinPos = new BlockPos(currentPos); centerOfBasin = VecHelper.getCenterOf(basinPos); if (vx != 0) { maxAge = 20; - Vec3d centerOf = VecHelper.getCenterOf(basinPos); - Vec3d diff = currentPos.subtract(centerOf) + Vector3d centerOf = VecHelper.getCenterOf(basinPos); + Vector3d diff = currentPos.subtract(centerOf) .mul(1, 0, 1) .normalize() .scale(.375); @@ -74,7 +74,7 @@ public class BasinFluidParticle extends FluidStackParticle { if (targetPos != null) { float progess = (1f * age) / maxAge; - Vec3d currentPos = centerOfBasin.add(targetPos.subtract(centerOfBasin) + Vector3d currentPos = centerOfBasin.add(targetPos.subtract(centerOfBasin) .scale(progess)); posX = currentPos.x; posZ = currentPos.z; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidParticleData.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidParticleData.java index 2812d3d76..14c324e72 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidParticleData.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidParticleData.java @@ -1,14 +1,21 @@ package com.simibubi.create.content.contraptions.fluids.particle; +import java.util.Optional; + 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 com.simibubi.create.content.contraptions.particle.ICustomParticleData; import net.minecraft.client.particle.IParticleFactory; import net.minecraft.fluid.Fluids; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.PacketBuffer; import net.minecraft.particles.IParticleData; import net.minecraft.particles.ParticleType; +import net.minecraft.util.registry.Registry; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fluids.FluidStack; @@ -50,6 +57,32 @@ public class FluidParticleData implements IParticleData, ICustomParticleData FLUID_CODEC = RecordCodecBuilder.create(i -> i.group( + Registry.FLUID.fieldOf("FluidName") + .forGetter(FluidStack::getFluid), + Codec.INT.fieldOf("Amount") + .forGetter(FluidStack::getAmount), + CompoundNBT.CODEC.optionalFieldOf("tag") + .forGetter((fs) -> { + return Optional.ofNullable(fs.getTag()); + })) + .apply(i, (f, a, t) -> new FluidStack(f, a, t.orElse(null)))); + + public static final Codec CODEC = RecordCodecBuilder.create(i -> i + .group(FLUID_CODEC.fieldOf("fluid") + .forGetter(p -> p.fluid)) + .apply(i, fs -> new FluidParticleData(AllParticleTypes.FLUID_PARTICLE.get(), fs))); + + public static final Codec BASIN_CODEC = RecordCodecBuilder.create(i -> i + .group(FLUID_CODEC.fieldOf("fluid") + .forGetter(p -> p.fluid)) + .apply(i, fs -> new FluidParticleData(AllParticleTypes.BASIN_FLUID.get(), fs))); + + public static final Codec DRIP_CODEC = RecordCodecBuilder.create(i -> i + .group(FLUID_CODEC.fieldOf("fluid") + .forGetter(p -> p.fluid)) + .apply(i, fs -> new FluidParticleData(AllParticleTypes.FLUID_DRIP.get(), fs))); + public static final IParticleData.IDeserializer DESERIALIZER = new IParticleData.IDeserializer() { @@ -69,4 +102,13 @@ public class FluidParticleData implements IParticleData, ICustomParticleData getCodec(ParticleType type) { + if (type == AllParticleTypes.BASIN_FLUID.get()) + return BASIN_CODEC; + if (type == AllParticleTypes.FLUID_DRIP.get()) + return DRIP_CODEC; + return CODEC; + } + } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java index d0868a468..1119601b4 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java @@ -7,11 +7,11 @@ import com.simibubi.create.foundation.utility.ColorHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.particle.IParticleRenderType; import net.minecraft.client.particle.SpriteTexturedParticle; +import net.minecraft.client.world.ClientWorld; import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.particles.ParticleType; import net.minecraft.particles.ParticleTypes; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; +import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.fluids.FluidStack; public class FluidStackParticle extends SpriteTexturedParticle { @@ -19,14 +19,14 @@ public class FluidStackParticle extends SpriteTexturedParticle { private final float field_217588_H; private FluidStack fluid; - public static FluidStackParticle create(ParticleType type, World world, FluidStack fluid, double x, + public static FluidStackParticle create(ParticleType type, ClientWorld world, FluidStack fluid, double x, double y, double z, double vx, double vy, double vz) { if (type == AllParticleTypes.BASIN_FLUID.get()) return new BasinFluidParticle(world, fluid, x, y, z, vx, vy, vz); return new FluidStackParticle(world, fluid, x, y, z, vx, vy, vz); } - public FluidStackParticle(World world, FluidStack fluid, double x, double y, double z, double vx, double vy, + public FluidStackParticle(ClientWorld world, FluidStack fluid, double x, double y, double z, double vx, double vy, double vz) { super(world, x, y, z, vx, vy, vz); this.fluid = fluid; @@ -98,7 +98,7 @@ public class FluidStackParticle extends SpriteTexturedParticle { if (!onGround && world.rand.nextFloat() < 1 / 8f) return; - Vec3d rgb = ColorHelper.getRGB(fluid.getFluid() + Vector3d rgb = ColorHelper.getRGB(fluid.getFluid() .getAttributes() .getColor(fluid)); world.addParticle(ParticleTypes.ENTITY_EFFECT, posX, posY, posZ, rgb.x, rgb.y, rgb.z); diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlock.java index 90c72f341..538da53e8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketBlock.java @@ -29,7 +29,7 @@ public class BracketBlock extends ProperDirectionalBlock { PIPE, COG, SHAFT; @Override - public String getName() { + public String getString() { return Lang.asId(name()); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketGenerator.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketGenerator.java index 16b06b1d4..456ee4766 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketGenerator.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/BracketGenerator.java @@ -29,7 +29,7 @@ public class BracketGenerator extends DirectionalAxisBlockStateGen { public ModelFile getModel(DataGenContext ctx, RegistrateBlockstateProvider prov, BlockState state) { String type = state.get(BracketBlock.TYPE) - .getName(); + .getString(); boolean vertical = state.get(BracketBlock.FACING) .getAxis() .isVertical(); 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 017c1bbab..7159756f8 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 @@ -73,7 +73,7 @@ public class AirParticleData implements IParticleData, ICustomParticleDataWithSp } @Override - public Codec getCodec() { + public Codec getCodec(ParticleType type) { return CODEC; } 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 cd896ecda..442a68b49 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 @@ -77,7 +77,7 @@ public class CubeParticleData implements IParticleData, ICustomParticleData getCodec() { + public Codec getCodec(ParticleType type) { return CODEC; } 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 f82f54c71..a547ba995 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 @@ -69,7 +69,7 @@ public class HeaterParticleData implements IParticleData, ICustomParticleDataWit } @Override - public Codec getCodec() { + public Codec getCodec(ParticleType type) { return CODEC; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticleDataWithSprite.java b/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticleDataWithSprite.java index 1800fe514..65dd04908 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticleDataWithSprite.java +++ b/src/main/java/com/simibubi/create/content/contraptions/particle/ICustomParticleDataWithSprite.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.contraptions.particle; +import com.mojang.serialization.Codec; + import net.minecraft.client.particle.IParticleFactory; import net.minecraft.client.particle.ParticleManager; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; @@ -11,13 +13,20 @@ import net.minecraftforge.api.distmarker.OnlyIn; public interface ICustomParticleDataWithSprite extends ICustomParticleData { - public IDeserializer getDeserializer(); + IDeserializer getDeserializer(); public default ParticleType createType() { - return new ParticleType(false, getDeserializer()); + return new ParticleType(false, getDeserializer()) { + + @Override + public Codec getCodec() { + return ICustomParticleDataWithSprite.this.getCodec(this); + } + }; } @Override + @OnlyIn(Dist.CLIENT) default IParticleFactory getFactory() { throw new IllegalAccessError("This particle type uses a metaFactory!"); } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java index abc89b9a4..b0d587c34 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/elementary/BracketedKineticBlockModel.java @@ -14,7 +14,7 @@ import net.minecraft.client.renderer.model.BakedQuad; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.util.Direction; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.ILightReader; +import net.minecraft.world.IBlockDisplayReader; import net.minecraftforge.client.model.data.IModelData; import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelProperty; @@ -28,7 +28,7 @@ public class BracketedKineticBlockModel extends WrappedBakedModel { } @Override - public IModelData getModelData(ILightReader world, BlockPos pos, BlockState state, IModelData tileData) { + public IModelData getModelData(IBlockDisplayReader world, BlockPos pos, BlockState state, IModelData tileData) { if (tileData == VirtualEmptyModelData.INSTANCE) return tileData; BracketedModelData data = new BracketedModelData();