mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-22 16:38:20 +01:00
Rewrite particles
This commit is contained in:
parent
7c7239a70d
commit
e82f28c1ac
@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
@ -50,6 +51,8 @@ public interface ItemRewriter<T extends Protocol<?, ?, ?, ?>> extends Rewriter<T
|
||||
@Nullable
|
||||
Item handleItemToServer(UserConnection connection, @Nullable Item item);
|
||||
|
||||
void rewriteParticle(UserConnection connection, Particle particle);
|
||||
|
||||
/**
|
||||
* Returns the item type of the current protocol.
|
||||
*
|
||||
|
@ -330,6 +330,27 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
|
||||
wrapper.write(Types.STRING, recipe.identifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rewriteParticle(final UserConnection connection, final Particle particle) {
|
||||
super.rewriteParticle(connection, particle);
|
||||
|
||||
final String identifier = protocol.getMappingData().getParticleMappings().mappedIdentifier(particle.id());
|
||||
if (identifier.equals("minecraft:dust_color_transition")) {
|
||||
floatsToARGB(particle, 0);
|
||||
floatsToARGB(particle, 1);
|
||||
} else if (identifier.equals("minecraft:dust")) {
|
||||
floatsToARGB(particle, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void floatsToARGB(final Particle particle, final int fromIndex) {
|
||||
final Particle.ParticleData<Float> r = particle.removeArgument(fromIndex);
|
||||
final Particle.ParticleData<Float> g = particle.removeArgument(fromIndex);
|
||||
final Particle.ParticleData<Float> b = particle.removeArgument(fromIndex);
|
||||
final int rgb = 255 << 24 | (int) (r.getValue() * 255) << 16 | (int) (g.getValue() * 255) << 8 | (int) (b.getValue() * 255);
|
||||
particle.add(fromIndex, Types.INT, rgb);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Item handleItemToClient(final UserConnection connection, final Item item) {
|
||||
super.handleItemToClient(connection, item);
|
||||
|
@ -35,12 +35,10 @@ import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.EntityDataType;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
@ -591,21 +589,17 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
}
|
||||
|
||||
public void rewriteParticle(UserConnection connection, Particle particle) {
|
||||
if (protocol.getItemRewriter() != null) {
|
||||
protocol.getItemRewriter().rewriteParticle(connection, particle);
|
||||
return;
|
||||
}
|
||||
|
||||
// Dupe parts of the logic if no item rewriter is available
|
||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||
int id = particle.id();
|
||||
if (mappings.isBlockParticle(id)) {
|
||||
Particle.ParticleData<Integer> data = particle.getArgument(0);
|
||||
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
|
||||
} else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) {
|
||||
Particle.ParticleData<Item> data = particle.getArgument(0);
|
||||
ItemRewriter<?> itemRewriter = protocol.getItemRewriter();
|
||||
Item item = itemRewriter.handleItemToClient(connection, data.getValue());
|
||||
if (itemRewriter.mappedItemType() != null && itemRewriter.itemType() != itemRewriter.mappedItemType()) {
|
||||
// Replace the type
|
||||
particle.set(0, itemRewriter.mappedItemType(), item);
|
||||
} else {
|
||||
data.setValue(item);
|
||||
}
|
||||
}
|
||||
|
||||
particle.setId(protocol.getMappingData().getNewParticleId(id));
|
||||
|
@ -621,7 +621,8 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
wrapper.write(itemType, item);
|
||||
}
|
||||
|
||||
protected void rewriteParticle(UserConnection connection, Particle particle) {
|
||||
@Override
|
||||
public void rewriteParticle(UserConnection connection, Particle particle) {
|
||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||
int id = particle.id();
|
||||
if (mappings.isBlockParticle(id)) {
|
||||
|
Loading…
Reference in New Issue
Block a user