Port new changes to 1.16

This commit is contained in:
simibubi 2020-11-06 20:56:19 +01:00
parent 0a98171384
commit fb06dc5e72
10 changed files with 75 additions and 24 deletions

View File

@ -6,22 +6,22 @@ import com.simibubi.create.content.contraptions.processing.BasinTileEntity;
import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.foundation.utility.VecHelper;
import net.minecraft.client.renderer.ActiveRenderInfo; 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.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.vector.Quaternion;
import net.minecraft.world.World; import net.minecraft.util.math.vector.Vector3d;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
public class BasinFluidParticle extends FluidStackParticle { public class BasinFluidParticle extends FluidStackParticle {
BlockPos basinPos; BlockPos basinPos;
Vec3d targetPos; Vector3d targetPos;
Vec3d centerOfBasin; Vector3d centerOfBasin;
float yOffset; 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) { double vz) {
super(world, fluid, x, y, z, vx, vy, vz); super(world, fluid, x, y, z, vx, vy, vz);
particleGravity = 0; particleGravity = 0;
@ -32,14 +32,14 @@ public class BasinFluidParticle extends FluidStackParticle {
posY += yOffset; posY += yOffset;
particleScale = 0; particleScale = 0;
maxAge = 60; maxAge = 60;
Vec3d currentPos = new Vec3d(posX, posY, posZ); Vector3d currentPos = new Vector3d(posX, posY, posZ);
basinPos = new BlockPos(currentPos); basinPos = new BlockPos(currentPos);
centerOfBasin = VecHelper.getCenterOf(basinPos); centerOfBasin = VecHelper.getCenterOf(basinPos);
if (vx != 0) { if (vx != 0) {
maxAge = 20; maxAge = 20;
Vec3d centerOf = VecHelper.getCenterOf(basinPos); Vector3d centerOf = VecHelper.getCenterOf(basinPos);
Vec3d diff = currentPos.subtract(centerOf) Vector3d diff = currentPos.subtract(centerOf)
.mul(1, 0, 1) .mul(1, 0, 1)
.normalize() .normalize()
.scale(.375); .scale(.375);
@ -74,7 +74,7 @@ public class BasinFluidParticle extends FluidStackParticle {
if (targetPos != null) { if (targetPos != null) {
float progess = (1f * age) / maxAge; float progess = (1f * age) / maxAge;
Vec3d currentPos = centerOfBasin.add(targetPos.subtract(centerOfBasin) Vector3d currentPos = centerOfBasin.add(targetPos.subtract(centerOfBasin)
.scale(progess)); .scale(progess));
posX = currentPos.x; posX = currentPos.x;
posZ = currentPos.z; posZ = currentPos.z;

View File

@ -1,14 +1,21 @@
package com.simibubi.create.content.contraptions.fluids.particle; package com.simibubi.create.content.contraptions.fluids.particle;
import java.util.Optional;
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.content.contraptions.particle.ICustomParticleData; import com.simibubi.create.content.contraptions.particle.ICustomParticleData;
import net.minecraft.client.particle.IParticleFactory; import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.fluid.Fluids; import net.minecraft.fluid.Fluids;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.PacketBuffer;
import net.minecraft.particles.IParticleData; import net.minecraft.particles.IParticleData;
import net.minecraft.particles.ParticleType; import net.minecraft.particles.ParticleType;
import net.minecraft.util.registry.Registry;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
@ -50,6 +57,32 @@ public class FluidParticleData implements IParticleData, ICustomParticleData<Flu
.getRegistryName(); .getRegistryName();
} }
public static final Codec<FluidStack> 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<FluidParticleData> 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<FluidParticleData> 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<FluidParticleData> 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<FluidParticleData> DESERIALIZER = public static final IParticleData.IDeserializer<FluidParticleData> DESERIALIZER =
new IParticleData.IDeserializer<FluidParticleData>() { new IParticleData.IDeserializer<FluidParticleData>() {
@ -69,4 +102,13 @@ public class FluidParticleData implements IParticleData, ICustomParticleData<Flu
return DESERIALIZER; return DESERIALIZER;
} }
@Override
public Codec<FluidParticleData> getCodec(ParticleType<FluidParticleData> type) {
if (type == AllParticleTypes.BASIN_FLUID.get())
return BASIN_CODEC;
if (type == AllParticleTypes.FLUID_DRIP.get())
return DRIP_CODEC;
return CODEC;
}
} }

View File

@ -7,11 +7,11 @@ import com.simibubi.create.foundation.utility.ColorHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.IParticleRenderType; import net.minecraft.client.particle.IParticleRenderType;
import net.minecraft.client.particle.SpriteTexturedParticle; import net.minecraft.client.particle.SpriteTexturedParticle;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.inventory.container.PlayerContainer; import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.particles.ParticleType; import net.minecraft.particles.ParticleType;
import net.minecraft.particles.ParticleTypes; import net.minecraft.particles.ParticleTypes;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidStack;
public class FluidStackParticle extends SpriteTexturedParticle { public class FluidStackParticle extends SpriteTexturedParticle {
@ -19,14 +19,14 @@ public class FluidStackParticle extends SpriteTexturedParticle {
private final float field_217588_H; private final float field_217588_H;
private FluidStack fluid; private FluidStack fluid;
public static FluidStackParticle create(ParticleType<FluidParticleData> type, World world, FluidStack fluid, double x, public static FluidStackParticle create(ParticleType<FluidParticleData> type, ClientWorld world, FluidStack fluid, double x,
double y, double z, double vx, double vy, double vz) { double y, double z, double vx, double vy, double vz) {
if (type == AllParticleTypes.BASIN_FLUID.get()) if (type == AllParticleTypes.BASIN_FLUID.get())
return new BasinFluidParticle(world, fluid, x, y, z, vx, vy, vz); return new BasinFluidParticle(world, fluid, x, y, z, vx, vy, vz);
return new FluidStackParticle(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) { double vz) {
super(world, x, y, z, vx, vy, vz); super(world, x, y, z, vx, vy, vz);
this.fluid = fluid; this.fluid = fluid;
@ -98,7 +98,7 @@ public class FluidStackParticle extends SpriteTexturedParticle {
if (!onGround && world.rand.nextFloat() < 1 / 8f) if (!onGround && world.rand.nextFloat() < 1 / 8f)
return; return;
Vec3d rgb = ColorHelper.getRGB(fluid.getFluid() Vector3d rgb = ColorHelper.getRGB(fluid.getFluid()
.getAttributes() .getAttributes()
.getColor(fluid)); .getColor(fluid));
world.addParticle(ParticleTypes.ENTITY_EFFECT, posX, posY, posZ, rgb.x, rgb.y, rgb.z); world.addParticle(ParticleTypes.ENTITY_EFFECT, posX, posY, posZ, rgb.x, rgb.y, rgb.z);

View File

@ -29,7 +29,7 @@ public class BracketBlock extends ProperDirectionalBlock {
PIPE, COG, SHAFT; PIPE, COG, SHAFT;
@Override @Override
public String getName() { public String getString() {
return Lang.asId(name()); return Lang.asId(name());
} }

View File

@ -29,7 +29,7 @@ public class BracketGenerator extends DirectionalAxisBlockStateGen {
public <T extends Block> ModelFile getModel(DataGenContext<Block, T> ctx, RegistrateBlockstateProvider prov, public <T extends Block> ModelFile getModel(DataGenContext<Block, T> ctx, RegistrateBlockstateProvider prov,
BlockState state) { BlockState state) {
String type = state.get(BracketBlock.TYPE) String type = state.get(BracketBlock.TYPE)
.getName(); .getString();
boolean vertical = state.get(BracketBlock.FACING) boolean vertical = state.get(BracketBlock.FACING)
.getAxis() .getAxis()
.isVertical(); .isVertical();

View File

@ -73,7 +73,7 @@ public class AirParticleData implements IParticleData, ICustomParticleDataWithSp
} }
@Override @Override
public Codec<AirParticleData> getCodec() { public Codec<AirParticleData> getCodec(ParticleType<AirParticleData> type) {
return CODEC; return CODEC;
} }

View File

@ -77,7 +77,7 @@ public class CubeParticleData implements IParticleData, ICustomParticleData<Cube
} }
@Override @Override
public Codec<CubeParticleData> getCodec() { public Codec<CubeParticleData> getCodec(ParticleType<CubeParticleData> type) {
return CODEC; return CODEC;
} }

View File

@ -69,7 +69,7 @@ public class HeaterParticleData implements IParticleData, ICustomParticleDataWit
} }
@Override @Override
public Codec<HeaterParticleData> getCodec() { public Codec<HeaterParticleData> getCodec(ParticleType<HeaterParticleData> type) {
return CODEC; return CODEC;
} }

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.IParticleFactory; import net.minecraft.client.particle.IParticleFactory;
import net.minecraft.client.particle.ParticleManager; import net.minecraft.client.particle.ParticleManager;
import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory; import net.minecraft.client.particle.ParticleManager.IParticleMetaFactory;
@ -11,13 +13,20 @@ import net.minecraftforge.api.distmarker.OnlyIn;
public interface ICustomParticleDataWithSprite<T extends IParticleData> extends ICustomParticleData<T> { public interface ICustomParticleDataWithSprite<T extends IParticleData> extends ICustomParticleData<T> {
public IDeserializer<T> getDeserializer(); IDeserializer<T> getDeserializer();
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 ICustomParticleDataWithSprite.this.getCodec(this);
}
};
} }
@Override @Override
@OnlyIn(Dist.CLIENT)
default IParticleFactory<T> getFactory() { default IParticleFactory<T> getFactory() {
throw new IllegalAccessError("This particle type uses a metaFactory!"); throw new IllegalAccessError("This particle type uses a metaFactory!");
} }

View File

@ -14,7 +14,7 @@ import net.minecraft.client.renderer.model.BakedQuad;
import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.math.BlockPos; 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.IModelData;
import net.minecraftforge.client.model.data.ModelDataMap; import net.minecraftforge.client.model.data.ModelDataMap;
import net.minecraftforge.client.model.data.ModelProperty; import net.minecraftforge.client.model.data.ModelProperty;
@ -28,7 +28,7 @@ public class BracketedKineticBlockModel extends WrappedBakedModel {
} }
@Override @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) if (tileData == VirtualEmptyModelData.INSTANCE)
return tileData; return tileData;
BracketedModelData data = new BracketedModelData(); BracketedModelData data = new BracketedModelData();