添加粒子属性

This commit is contained in:
17146 2025-06-28 18:31:12 +08:00 committed by Light_Quanta
parent ca6e687b78
commit b6e58c411a
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 54 additions and 12 deletions

View file

@ -17,7 +17,10 @@ public class BulletDecalOption implements ParticleOptions {
public static final Codec<BulletDecalOption> CODEC = RecordCodecBuilder.create(builder ->
builder.group(
Codec.INT.fieldOf("dir").forGetter(option -> option.direction.ordinal()),
Codec.LONG.fieldOf("pos").forGetter(option -> option.pos.asLong())
Codec.LONG.fieldOf("pos").forGetter(option -> option.pos.asLong()),
Codec.FLOAT.fieldOf("r").forGetter(option -> option.red),
Codec.FLOAT.fieldOf("g").forGetter(option -> option.green),
Codec.FLOAT.fieldOf("b").forGetter(option -> option.blue)
).apply(builder, BulletDecalOption::new));
@SuppressWarnings("deprecation")
@ -28,26 +31,45 @@ public class BulletDecalOption implements ParticleOptions {
int dir = reader.readInt();
reader.expect(' ');
long pos = reader.readLong();
return new BulletDecalOption(dir, pos);
reader.expect(' ');
float r = reader.readFloat();
reader.expect(' ');
float g = reader.readFloat();
reader.expect(' ');
float b = reader.readFloat();
return new BulletDecalOption(dir, pos, r, g, b);
}
@Override
public BulletDecalOption fromNetwork(ParticleType<BulletDecalOption> particleType, FriendlyByteBuf buffer) {
return new BulletDecalOption(buffer.readVarInt(), buffer.readLong());
return new BulletDecalOption(buffer.readVarInt(), buffer.readLong(), buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
}
};
private final Direction direction;
private final BlockPos pos;
private final float red;
private final float green;
private final float blue;
public BulletDecalOption(int dir, long pos) {
this.direction = Direction.values()[dir];
this.pos = BlockPos.of(pos);
this(Direction.values()[dir], BlockPos.of(pos), 0f, 0f, 0f);
}
public BulletDecalOption(int dir, long pos, float r, float g, float b) {
this(Direction.values()[dir], BlockPos.of(pos), r, g, b);
}
public BulletDecalOption(Direction dir, BlockPos pos) {
this(dir, pos, 0f, 0f, 0f);
}
public BulletDecalOption(Direction dir, BlockPos pos, float r, float g, float b) {
this.direction = dir;
this.pos = pos;
this.red = r;
this.green = g;
this.blue = b;
}
public Direction getDirection() {
@ -58,6 +80,18 @@ public class BulletDecalOption implements ParticleOptions {
return this.pos;
}
public float getRed() {
return red;
}
public float getGreen() {
return green;
}
public float getBlue() {
return blue;
}
@Override
public ParticleType<?> getType() {
return ModParticleTypes.BULLET_DECAL.get();
@ -67,6 +101,9 @@ public class BulletDecalOption implements ParticleOptions {
public void writeToNetwork(FriendlyByteBuf buffer) {
buffer.writeEnum(this.direction);
buffer.writeBlockPos(this.pos);
buffer.writeFloat(this.red);
buffer.writeFloat(this.green);
buffer.writeFloat(this.blue);
}
@Override

View file

@ -37,8 +37,12 @@ public class BulletDecalParticle extends TextureSheetParticle {
private int vOffset;
private float textureDensity;
public BulletDecalParticle(ClientLevel world, double x, double y, double z, Direction direction, BlockPos pos) {
super(world, x, y, z);
public BulletDecalParticle(ClientLevel level, double x, double y, double z, Direction direction, BlockPos pos) {
this(level, x, y, z, direction, pos, 0f, 0f, 0f);
}
public BulletDecalParticle(ClientLevel level, double x, double y, double z, Direction direction, BlockPos pos, float rCol, float gCol, float bCol) {
super(level, x, y, z);
this.setSprite(this.getSprite(pos));
this.direction = direction;
this.pos = pos;
@ -51,9 +55,9 @@ public class BulletDecalParticle extends TextureSheetParticle {
this.remove();
}
this.rCol = 0;
this.gCol = 0;
this.bCol = 0;
this.rCol = rCol;
this.gCol = gCol;
this.bCol = bCol;
this.alpha = 0.9F;
}
@ -184,7 +188,7 @@ public class BulletDecalParticle extends TextureSheetParticle {
@Override
public BulletDecalParticle createParticle(@NotNull BulletDecalOption option, @NotNull ClientLevel world, double x, double y, double z, double pXSpeed, double pYSpeed, double pZSpeed) {
return new BulletDecalParticle(world, x, y, z, option.getDirection(), option.getPos());
return new BulletDecalParticle(world, x, y, z, option.getDirection(), option.getPos(), option.getRed(), option.getGreen(), option.getBlue());
}
}
}

View file

@ -510,7 +510,8 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
if (this.beast) {
ParticleTool.sendParticle(serverLevel, ParticleTypes.END_ROD, location.x, location.y, location.z, 15, 0.1, 0.1, 0.1, 0.05, true);
} else {
BulletDecalOption bulletDecalOption = new BulletDecalOption(result.getDirection(), result.getBlockPos());
BulletDecalOption bulletDecalOption = new BulletDecalOption(result.getDirection(), result.getBlockPos(),
this.entityData.get(COLOR_R), this.entityData.get(COLOR_G), this.entityData.get(COLOR_B));
serverLevel.sendParticles(bulletDecalOption, location.x, location.y, location.z, 1, 0, 0, 0, 0);
ParticleTool.sendParticle(serverLevel, ParticleTypes.SMOKE, location.x, location.y, location.z, 3, vx, vy, vz, 0.01, true);