Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Handle color in area effect cloud
Dieser Commit ist enthalten in:
Ursprung
9f1ee27afc
Commit
d04aaeb926
@ -73,6 +73,18 @@ public final class Particle implements IdHolder {
|
|||||||
arguments.add(index, new ParticleData<>(type, value));
|
arguments.add(index, new ParticleData<>(type, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> void set(final int index, final Type<T> type, final T value) {
|
||||||
|
arguments.set(index, new ParticleData<>(type, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Particle{" +
|
||||||
|
"arguments=" + arguments +
|
||||||
|
", id=" + id +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
public static final class ParticleData<T> {
|
public static final class ParticleData<T> {
|
||||||
private final Type<T> type;
|
private final Type<T> type;
|
||||||
private T value;
|
private T value;
|
||||||
|
@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.Particle;
|
|||||||
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
@ -285,6 +286,30 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
});
|
});
|
||||||
|
|
||||||
filter().type(EntityTypes1_20_5.LLAMA).removeIndex(20); // Carpet color
|
filter().type(EntityTypes1_20_5.LLAMA).removeIndex(20); // Carpet color
|
||||||
|
filter().type(EntityTypes1_20_5.AREA_EFFECT_CLOUD).handler((event, meta) -> {
|
||||||
|
// Color removed - Now put into the actual particle
|
||||||
|
final int metaIndex = event.index();
|
||||||
|
if (metaIndex == 9) {
|
||||||
|
// If the color is found first
|
||||||
|
final Metadata particleData = event.metaAtIndex(11);
|
||||||
|
addColor(particleData, meta.value());
|
||||||
|
|
||||||
|
event.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metaIndex > 9) {
|
||||||
|
event.setIndex(metaIndex - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (metaIndex == 11) {
|
||||||
|
// If the particle is found first
|
||||||
|
final Metadata colorData = event.metaAtIndex(9);
|
||||||
|
if (colorData != null) {
|
||||||
|
addColor(meta, colorData.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
filter().type(EntityTypes1_20_5.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
filter().type(EntityTypes1_20_5.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||||
final int blockState = meta.value();
|
final int blockState = meta.value();
|
||||||
@ -292,11 +317,22 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addColor(@Nullable final Metadata particleMeta, final int color) {
|
||||||
|
if (particleMeta == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Particle particle = particleMeta.value();
|
||||||
|
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
|
||||||
|
particle.getArgument(0).setValue(color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void rewriteParticle(final Particle particle) {
|
public void rewriteParticle(final Particle particle) {
|
||||||
super.rewriteParticle(particle);
|
super.rewriteParticle(particle);
|
||||||
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
|
if (particle.id() == protocol.getMappingData().getParticleMappings().mappedId("entity_effect")) {
|
||||||
particle.add(Type.INT, 0); // rgb // TODO
|
particle.add(Type.INT, 0); // Default color, changed in the area effect handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
|||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
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.rewriter.RewriterBase;
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.data.entity.DimensionDataImpl;
|
import com.viaversion.viaversion.data.entity.DimensionDataImpl;
|
||||||
@ -586,14 +587,20 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
|
|
||||||
public void rewriteParticle(Particle particle) {
|
public void rewriteParticle(Particle particle) {
|
||||||
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
ParticleMappings mappings = protocol.getMappingData().getParticleMappings();
|
||||||
int id = particle.getId();
|
int id = particle.id();
|
||||||
if (mappings.isBlockParticle(id)) {
|
if (mappings.isBlockParticle(id)) {
|
||||||
Particle.ParticleData<Integer> data = particle.getArgument(0);
|
Particle.ParticleData<Integer> data = particle.getArgument(0);
|
||||||
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
|
data.setValue(protocol.getMappingData().getNewBlockStateId(data.getValue()));
|
||||||
} else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) {
|
} else if (mappings.isItemParticle(id) && protocol.getItemRewriter() != null) {
|
||||||
Particle.ParticleData<Item> data = particle.getArgument(0);
|
Particle.ParticleData<Item> data = particle.getArgument(0);
|
||||||
Item item = data.getValue();
|
ItemRewriter<?> itemRewriter = protocol.getItemRewriter();
|
||||||
protocol.getItemRewriter().handleItemToClient(item);
|
Item item = itemRewriter.handleItemToClient(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));
|
particle.setId(protocol.getMappingData().getNewParticleId(id));
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren