3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 08:30:09 +01:00

Clean up Particle

Dieser Commit ist enthalten in:
Nassim Jahnke 2023-10-21 13:00:39 +10:00
Ursprung c7c38e70c0
Commit faedf26b5b
23 geänderte Dateien mit 76 neuen und 72 gelöschten Zeilen

Datei anzeigen

@ -20,17 +20,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.viaversion.viaversion.api.type.types;
package com.viaversion.viaversion.api.minecraft;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
public class Particle {
private List<ParticleData> arguments = new ArrayList<>(4);
public final class Particle {
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
private int id;
public Particle(int id) {
public Particle(final int id) {
this.id = id;
}
@ -38,50 +40,50 @@ public class Particle {
return id;
}
public void setId(int id) {
public void setId(final int id) {
this.id = id;
}
public List<ParticleData> getArguments() {
public <T> ParticleData<T> getArgument(final int id) {
//noinspection unchecked
return (ParticleData<T>) arguments.get(id);
}
public List<ParticleData<?>> getArguments() {
return arguments;
}
@Deprecated/*(forRemoval = true)*/
public void setArguments(List<ParticleData> arguments) {
this.arguments = arguments;
public <T> void add(final Type<T> type, final T value) {
arguments.add(new ParticleData<>(type, value));
}
public <T> void add(Type<T> type, T value) {
arguments.add(new ParticleData(type, value));
}
public static final class ParticleData<T> {
private final Type<T> type;
private T value;
public static class ParticleData {
private Type type;
private Object value;
public ParticleData(Type type, Object value) {
public ParticleData(final Type<T> type, final T value) {
this.type = type;
this.value = value;
}
public Type getType() {
public Type<T> getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public Object getValue() {
public T getValue() {
return value;
}
public <T> T get() {
return (T) value;
public void setValue(final T value) {
this.value = value;
}
public void setValue(Object value) {
this.value = value;
public void write(final ByteBuf buf) throws Exception {
type.write(buf, value);
}
public void write(final PacketWrapper wrapper) {
wrapper.write(type, value);
}
@Override

Datei anzeigen

@ -209,7 +209,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
private final String typeName;
protected Type(Class<? super T> outputClass) {
this(outputClass.getSimpleName(), outputClass);
this(null, outputClass);
}
protected Type(String typeName, Class<? super T> outputClass) {
@ -232,7 +232,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
* @return type name
*/
public String getTypeName() {
return typeName;
return typeName != null ? typeName : this.getClass().getSimpleName();
}
/**
@ -247,6 +247,9 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
@Override
public String toString() {
return typeName;
return "Type{" +
"outputClass=" + outputClass +
", typeName='" + typeName + '\'' +
'}';
}
}

Datei anzeigen

@ -34,7 +34,7 @@ public class ChunkSectionType1_13 extends Type<ChunkSection> {
private static final int GLOBAL_PALETTE = 14;
public ChunkSectionType1_13() {
super("Chunk Section Type", ChunkSection.class);
super(ChunkSection.class);
}
@Override

Datei anzeigen

@ -34,7 +34,7 @@ public class ChunkSectionType1_16 extends Type<ChunkSection> {
private static final int GLOBAL_PALETTE = 15;
public ChunkSectionType1_16() {
super("Chunk Section Type", ChunkSection.class);
super(ChunkSection.class);
}
@Override

Datei anzeigen

@ -34,7 +34,7 @@ public final class ChunkSectionType1_18 extends Type<ChunkSection> {
private final PaletteType1_18 biomePaletteType;
public ChunkSectionType1_18(final int globalPaletteBlockBits, final int globalPaletteBiomeBits) {
super("Chunk Section Type", ChunkSection.class);
super(ChunkSection.class);
this.blockPaletteType = new PaletteType1_18(PaletteType.BLOCKS, globalPaletteBlockBits);
this.biomePaletteType = new PaletteType1_18(PaletteType.BIOMES, globalPaletteBiomeBits);
}

Datei anzeigen

@ -33,7 +33,7 @@ import java.nio.ByteOrder;
public class ChunkSectionType1_8 extends Type<ChunkSection> {
public ChunkSectionType1_8() {
super("Chunk Section Type", ChunkSection.class);
super(ChunkSection.class);
}
@Override

Datei anzeigen

@ -34,7 +34,7 @@ public class ChunkSectionType1_9 extends Type<ChunkSection> {
private static final int GLOBAL_PALETTE = 13;
public ChunkSectionType1_9() {
super("Chunk Section Type", ChunkSection.class);
super(ChunkSection.class);
}
@Override

Datei anzeigen

@ -30,7 +30,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_13 extends Type<Item> {
public ItemType1_13() {
super("FlatItem", Item.class);
super(Item.class);
}
@Override

Datei anzeigen

@ -30,7 +30,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_13_2 extends Type<Item> {
public ItemType1_13_2() {
super("FlatVarIntItem", Item.class);
super(Item.class);
}
@Override

Datei anzeigen

@ -31,7 +31,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_20_2 extends Type<Item> {
public ItemType1_20_2() {
super("ItemType1_20_2", Item.class);
super(Item.class);
}
@Override

Datei anzeigen

@ -31,7 +31,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ItemType1_8 extends Type<Item> {
public ItemType1_8() {
super("Item", Item.class);
super(Item.class);
}
@Override

Datei anzeigen

@ -27,7 +27,7 @@ import com.viaversion.viaversion.api.data.ParticleMappings;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.util.Key;
import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap;
@ -57,8 +57,8 @@ public class ParticleType extends Type<Particle> {
@Override
public void write(final ByteBuf buffer, final Particle object) throws Exception {
Type.VAR_INT.writePrimitive(buffer, object.getId());
for (final Particle.ParticleData data : object.getArguments()) {
data.getType().write(buffer, data.getValue());
for (final Particle.ParticleData<?> data : object.getArguments()) {
data.write(buffer);
}
}

Datei anzeigen

@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;

Datei anzeigen

@ -21,7 +21,7 @@ import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.item.DataItem;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets.WorldPackets;
import java.util.ArrayList;
@ -121,10 +121,10 @@ public class ParticleRewriter {
// Randomized because the previous one was a lot of different colors at once! :)
private static ParticleDataHandler reddustHandler() {
return (particle, data) -> {
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomBool() ? 1f : 0f)); // Red 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 0f)); // Green 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, randomBool() ? 1f : 0f)); // Blue 0 - 1
particle.getArguments().add(new Particle.ParticleData(Type.FLOAT, 1f));// Scale 0.01 - 4
particle.add(Type.FLOAT, randomBool() ? 1f : 0f); // Red 0 - 1
particle.add(Type.FLOAT, 0f); // Green 0 - 1
particle.add(Type.FLOAT, randomBool() ? 1f : 0f); // Blue 0 - 1
particle.add(Type.FLOAT, 1f);// Scale 0.01 - 4
return particle;
};
}
@ -148,7 +148,7 @@ public class ParticleRewriter {
// Transform to new Item
Via.getManager().getProtocolManager().getProtocol(Protocol1_13To1_12_2.class).getItemRewriter().handleItemToClient(item);
particle.getArguments().add(new Particle.ParticleData(Type.ITEM1_13, item)); // Item Slot The item that will be used.
particle.add(Type.ITEM1_13, item); // Item Slot The item that will be used.
return particle;
};
}
@ -160,7 +160,7 @@ public class ParticleRewriter {
int combined = (((value & 4095) << 4) | (value >> 12 & 15));
int newId = WorldPackets.toNewId(combined);
particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, newId)); // BlockState VarInt The ID of the block state.
particle.add(Type.VAR_INT, newId); // BlockState VarInt The ID of the block state.
return particle;
};
}

Datei anzeigen

@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_13;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ChatRewriter;

Datei anzeigen

@ -32,7 +32,7 @@ import com.viaversion.viaversion.api.minecraft.chunks.PaletteType;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
@ -516,7 +516,6 @@ public class WorldPackets {
wrapper.set(Type.INT, 1, 1);
wrapper.set(Type.FLOAT, 6, 0f);
List<Particle.ParticleData> arguments = particle.getArguments();
for (int i = 0; i < 3; i++) {
//RGB values are represented by the X/Y/Z offset
float colorValue = wrapper.get(Type.FLOAT, i + 3) * speed;
@ -524,15 +523,15 @@ public class WorldPackets {
// https://minecraft.gamepedia.com/User:Alphappy/reddust
colorValue = 1;
}
arguments.get(i).setValue(colorValue);
particle.<Float>getArgument(i).setValue(colorValue);
wrapper.set(Type.FLOAT, i + 3, 0f);
}
}
}
wrapper.set(Type.INT, 0, particle.getId());
for (Particle.ParticleData particleData : particle.getArguments())
wrapper.write(particleData.getType(), particleData.getValue());
for (Particle.ParticleData<?> particleData : particle.getArguments())
particleData.write(wrapper);
});
}

Datei anzeigen

@ -28,7 +28,7 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13;
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;

Datei anzeigen

@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_14;
import com.viaversion.viaversion.protocols.protocol1_14_4to1_14_3.ClientboundPackets1_14_4;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;

Datei anzeigen

@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16_2;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;

Datei anzeigen

@ -23,7 +23,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_16;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_16;
import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;

Datei anzeigen

@ -22,7 +22,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_17;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_17;
import com.viaversion.viaversion.api.type.types.version.Types1_18;
import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1;
@ -87,9 +87,9 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_17_1
final Particle particle = (Particle) meta.getValue();
if (particle.getId() == 2) { // Barrier
particle.setId(3); // Block marker
particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, 7754)); // Barrier state
particle.add(Type.VAR_INT, 7754); // Barrier state
} else if (particle.getId() == 3) { // Light block
particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, 7786)); // Light block state
particle.add(Type.VAR_INT, 7786); // Light block state
} else {
rewriteParticle(particle);
}

Datei anzeigen

@ -35,7 +35,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.type.types.version.Types1_18;
import com.viaversion.viaversion.api.type.types.version.Types1_19;
import com.viaversion.viaversion.data.entity.DimensionDataImpl;
@ -363,10 +363,10 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_18,
// Remove the position
particle.getArguments().remove(0);
final String resourceLocation = Key.stripMinecraftNamespace(particle.getArguments().get(0).get());
final String resourceLocation = Key.stripMinecraftNamespace(particle.<String>getArgument(0).getValue());
if (resourceLocation.equals("entity")) {
// Add Y offset
particle.getArguments().add(2, new Particle.ParticleData(Type.FLOAT, 0F));
particle.getArguments().add(2, new Particle.ParticleData<>(Type.FLOAT, 0F));
}
}

Datei anzeigen

@ -40,7 +40,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.rewriter.RewriterBase;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.data.entity.DimensionDataImpl;
import com.viaversion.viaversion.rewriter.meta.MetaFilter;
import com.viaversion.viaversion.rewriter.meta.MetaHandlerEvent;
@ -580,11 +580,11 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
int id = particle.getId();
if (mappings.isBlockParticle(id)) {
Particle.ParticleData data = particle.getArguments().get(0);
data.setValue(protocol.getMappingData().getNewBlockStateId(data.get()));
Particle.ParticleData<Integer> data = particle.getArgument(0);
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
} else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) {
Particle.ParticleData data = particle.getArguments().get(0);
Item item = data.get();
Particle.ParticleData<Item> data = particle.getArgument(0);
Item item = data.getValue();
protocol.getItemRewriter().handleItemToClient(item);
}