use of com.viaversion.viaversion.api.type.types.Particle in project ViaVersion by ViaVersion.
the class EntityPackets method registerRewrites.
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> {
meta.setMetaType(Types1_18.META_TYPES.byId(meta.metaType().typeId()));
if (meta.metaType() == Types1_18.META_TYPES.particleType) {
final Particle particle = (Particle) meta.getValue();
if (particle.getId() == 2) {
// Barrier
// Block marker
particle.setId(3);
// Barrier state
particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, 7754));
} else if (particle.getId() == 3) {
// Light block
// Light block state
particle.getArguments().add(new Particle.ParticleData(Type.VAR_INT, 7786));
} else {
rewriteParticle(particle);
}
}
});
registerMetaTypeHandler(Types1_18.META_TYPES.itemType, null, null);
}
use of com.viaversion.viaversion.api.type.types.Particle in project ViaBackwards by ViaVersion.
the class EntityPackets1_13 method registerRewrites.
@Override
protected void registerRewrites() {
// Rewrite new Entity 'drowned'
mapEntityTypeWithData(Entity1_13Types.EntityType.DROWNED, Entity1_13Types.EntityType.ZOMBIE_VILLAGER).plainName();
// Fishy
mapEntityTypeWithData(Entity1_13Types.EntityType.COD, Entity1_13Types.EntityType.SQUID).plainName();
mapEntityTypeWithData(Entity1_13Types.EntityType.SALMON, Entity1_13Types.EntityType.SQUID).plainName();
mapEntityTypeWithData(Entity1_13Types.EntityType.PUFFERFISH, Entity1_13Types.EntityType.SQUID).plainName();
mapEntityTypeWithData(Entity1_13Types.EntityType.TROPICAL_FISH, Entity1_13Types.EntityType.SQUID).plainName();
// Phantom
mapEntityTypeWithData(Entity1_13Types.EntityType.PHANTOM, Entity1_13Types.EntityType.PARROT).plainName().spawnMetadata(storage -> {
// The phantom is grey/blue so let's do yellow/blue
storage.add(new Metadata(15, MetaType1_12.VarInt, 3));
});
// Dolphin
mapEntityTypeWithData(Entity1_13Types.EntityType.DOLPHIN, Entity1_13Types.EntityType.SQUID).plainName();
// Turtle
mapEntityTypeWithData(Entity1_13Types.EntityType.TURTLE, Entity1_13Types.EntityType.OCELOT).plainName();
// Rewrite Meta types
filter().handler((event, meta) -> {
int typeId = meta.metaType().typeId();
// Rewrite optional chat to string
if (typeId == 5) {
// Json -> Legacy is done below
meta.setTypeAndValue(MetaType1_12.String, meta.getValue() != null ? meta.getValue().toString() : "");
} else // Rewrite items
if (typeId == 6) {
Item item = (Item) meta.getValue();
meta.setTypeAndValue(MetaType1_12.Slot, protocol.getItemRewriter().handleItemToClient(item));
} else // Discontinue particles
if (typeId == 15) {
event.cancel();
} else // Rewrite to 1.12 ids
if (typeId > 5) {
meta.setMetaType(MetaType1_12.byId(typeId - 1));
}
});
// Rewrite Custom Name from Chat to String
filter().filterFamily(Entity1_13Types.EntityType.ENTITY).index(2).handler((event, meta) -> {
String value = meta.getValue().toString();
if (!value.isEmpty()) {
meta.setValue(ChatRewriter.jsonToLegacyText(value));
}
});
// Handle zombie metadata
filter().filterFamily(Entity1_13Types.EntityType.ZOMBIE).removeIndex(15);
// Handle turtle metadata (Remove them all for now)
// Home pos
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(13);
// Has egg
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(14);
// Laying egg
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(15);
// Travel pos
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(16);
// Going home
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(17);
// Traveling
filter().type(Entity1_13Types.EntityType.TURTLE).cancel(18);
// Remove additional fish meta
filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_FISHES).cancel(12);
filter().filterFamily(Entity1_13Types.EntityType.ABSTRACT_FISHES).cancel(13);
// Remove phantom size
filter().type(Entity1_13Types.EntityType.PHANTOM).cancel(12);
// Remove boat splash timer
filter().type(Entity1_13Types.EntityType.BOAT).cancel(12);
// Remove Trident special loyalty level
filter().type(Entity1_13Types.EntityType.TRIDENT).cancel(7);
// Handle new wolf colors
filter().type(Entity1_13Types.EntityType.WOLF).index(17).handler((event, meta) -> {
meta.setValue(15 - (int) meta.getValue());
});
// Rewrite AreaEffectCloud
filter().type(Entity1_13Types.EntityType.AREA_EFFECT_CLOUD).index(9).handler((event, meta) -> {
Particle particle = (Particle) meta.getValue();
ParticleMapping.ParticleData data = ParticleMapping.getMapping(particle.getId());
int firstArg = 0;
int secondArg = 0;
int[] particleArgs = data.rewriteMeta(protocol, particle.getArguments());
if (particleArgs != null && particleArgs.length != 0) {
if (data.getHandler().isBlockHandler() && particleArgs[0] == 0) {
// Air doesn't have a break particle for sub 1.13 clients -> glass pane
particleArgs[0] = 102;
}
firstArg = particleArgs[0];
secondArg = particleArgs.length == 2 ? particleArgs[1] : 0;
}
event.createExtraMeta(new Metadata(9, MetaType1_12.VarInt, data.getHistoryId()));
event.createExtraMeta(new Metadata(10, MetaType1_12.VarInt, firstArg));
event.createExtraMeta(new Metadata(11, MetaType1_12.VarInt, secondArg));
event.cancel();
});
}
use of com.viaversion.viaversion.api.type.types.Particle in project ViaBackwards by ViaVersion.
the class EntityPackets1_14 method registerRewrites.
@Override
protected void registerRewrites() {
mapTypes(Entity1_14Types.values(), Entity1_13Types.EntityType.class);
mapEntityTypeWithData(Entity1_14Types.CAT, Entity1_14Types.OCELOT).jsonName();
mapEntityTypeWithData(Entity1_14Types.TRADER_LLAMA, Entity1_14Types.LLAMA).jsonName();
mapEntityTypeWithData(Entity1_14Types.FOX, Entity1_14Types.WOLF).jsonName();
mapEntityTypeWithData(Entity1_14Types.PANDA, Entity1_14Types.POLAR_BEAR).jsonName();
mapEntityTypeWithData(Entity1_14Types.PILLAGER, Entity1_14Types.VILLAGER).jsonName();
mapEntityTypeWithData(Entity1_14Types.WANDERING_TRADER, Entity1_14Types.VILLAGER).jsonName();
mapEntityTypeWithData(Entity1_14Types.RAVAGER, Entity1_14Types.COW).jsonName();
filter().handler((event, meta) -> {
int typeId = meta.metaType().typeId();
if (typeId <= 15) {
meta.setMetaType(Types1_13_2.META_TYPES.byId(typeId));
}
MetaType type = meta.metaType();
if (type == Types1_13_2.META_TYPES.itemType) {
Item item = (Item) meta.getValue();
meta.setValue(protocol.getItemRewriter().handleItemToClient(item));
} else if (type == Types1_13_2.META_TYPES.blockStateType) {
int blockstate = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
}
});
filter().type(Entity1_14Types.PILLAGER).cancel(15);
filter().type(Entity1_14Types.FOX).cancel(15);
filter().type(Entity1_14Types.FOX).cancel(16);
filter().type(Entity1_14Types.FOX).cancel(17);
filter().type(Entity1_14Types.FOX).cancel(18);
filter().type(Entity1_14Types.PANDA).cancel(15);
filter().type(Entity1_14Types.PANDA).cancel(16);
filter().type(Entity1_14Types.PANDA).cancel(17);
filter().type(Entity1_14Types.PANDA).cancel(18);
filter().type(Entity1_14Types.PANDA).cancel(19);
filter().type(Entity1_14Types.PANDA).cancel(20);
filter().type(Entity1_14Types.CAT).cancel(18);
filter().type(Entity1_14Types.CAT).cancel(19);
filter().type(Entity1_14Types.CAT).cancel(20);
filter().handler((event, meta) -> {
EntityType type = event.entityType();
if (type == null)
return;
if (type.isOrHasParent(Entity1_14Types.ABSTRACT_ILLAGER_BASE) || type == Entity1_14Types.RAVAGER || type == Entity1_14Types.WITCH) {
int index = event.index();
if (index == 14) {
event.cancel();
} else if (index > 14) {
event.setIndex(index - 1);
}
}
});
filter().type(Entity1_14Types.AREA_EFFECT_CLOUD).index(10).handler((event, meta) -> {
rewriteParticle((Particle) meta.getValue());
});
filter().type(Entity1_14Types.FIREWORK_ROCKET).index(8).handler((event, meta) -> {
meta.setMetaType(Types1_13_2.META_TYPES.varIntType);
Integer value = (Integer) meta.getValue();
if (value == null) {
meta.setValue(0);
}
});
filter().filterFamily(Entity1_14Types.ABSTRACT_ARROW).removeIndex(9);
// Head shake timer
filter().type(Entity1_14Types.VILLAGER).cancel(15);
MetaHandler villagerDataHandler = (event, meta) -> {
VillagerData villagerData = (VillagerData) meta.getValue();
meta.setTypeAndValue(Types1_13_2.META_TYPES.varIntType, villagerDataToProfession(villagerData));
if (meta.id() == 16) {
// decreased by 2 again in one of the following handlers
event.setIndex(15);
}
};
filter().type(Entity1_14Types.ZOMBIE_VILLAGER).index(18).handler(villagerDataHandler);
filter().type(Entity1_14Types.VILLAGER).index(16).handler(villagerDataHandler);
// Holding arms up - from bitfield into own boolean
filter().filterFamily(Entity1_14Types.ABSTRACT_SKELETON).index(13).handler((event, meta) -> {
byte value = (byte) meta.getValue();
if ((value & 4) != 0) {
event.createExtraMeta(new Metadata(14, Types1_13_2.META_TYPES.booleanType, true));
}
});
filter().filterFamily(Entity1_14Types.ZOMBIE).index(13).handler((event, meta) -> {
byte value = (byte) meta.getValue();
if ((value & 4) != 0) {
event.createExtraMeta(new Metadata(16, Types1_13_2.META_TYPES.booleanType, true));
}
});
filter().filterFamily(Entity1_14Types.ZOMBIE).addIndex(16);
// Remove bed location
filter().filterFamily(Entity1_14Types.LIVINGENTITY).handler((event, meta) -> {
int index = event.index();
if (index == 12) {
Position position = (Position) meta.getValue();
if (position != null) {
// Use bed
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_13.USE_BED, null, event.user());
wrapper.write(Type.VAR_INT, event.entityId());
wrapper.write(Type.POSITION, position);
try {
wrapper.scheduleSend(Protocol1_13_2To1_14.class);
} catch (Exception ex) {
ex.printStackTrace();
}
}
event.cancel();
} else if (index > 12) {
event.setIndex(index - 1);
}
});
// Pose
filter().removeIndex(6);
filter().type(Entity1_14Types.OCELOT).index(13).handler((event, meta) -> {
event.setIndex(15);
meta.setTypeAndValue(Types1_13_2.META_TYPES.varIntType, 0);
});
filter().type(Entity1_14Types.CAT).handler((event, meta) -> {
if (event.index() == 15) {
meta.setValue(1);
} else if (event.index() == 13) {
meta.setValue((byte) ((byte) meta.getValue() & 0x4));
}
});
filter().handler((event, meta) -> {
if (meta.metaType().typeId() > 15) {
throw new IllegalArgumentException("Unhandled metadata: " + meta);
}
});
}
use of com.viaversion.viaversion.api.type.types.Particle in project ViaBackwards by ViaVersion.
the class EntityPackets1_17 method registerRewrites.
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> {
meta.setMetaType(Types1_16.META_TYPES.byId(meta.metaType().typeId()));
MetaType type = meta.metaType();
if (type == Types1_16.META_TYPES.particleType) {
Particle particle = (Particle) meta.getValue();
if (particle.getId() == 16) {
// Dust / Dust Transition
// Remove transition target color values 4-6
particle.getArguments().subList(4, 7).clear();
} else if (particle.getId() == 37) {
// Vibration Signal
// No nice mapping possible without tracking entity positions and doing particle tasks
particle.setId(0);
particle.getArguments().clear();
return;
}
rewriteParticle(particle);
} else if (type == Types1_16.META_TYPES.poseType) {
// Goat LONG_JUMP added at 6
int pose = meta.value();
if (pose == 6) {
// FALL_FLYING
meta.setValue(1);
} else if (pose > 6) {
meta.setValue(pose - 1);
}
}
});
// Particles have already been handled
registerMetaTypeHandler(Types1_16.META_TYPES.itemType, Types1_16.META_TYPES.blockStateType, null, Types1_16.META_TYPES.optionalComponentType);
mapTypes(Entity1_17Types.values(), Entity1_16_2Types.class);
filter().type(Entity1_17Types.AXOLOTL).cancel(17);
filter().type(Entity1_17Types.AXOLOTL).cancel(18);
filter().type(Entity1_17Types.AXOLOTL).cancel(19);
filter().type(Entity1_17Types.GLOW_SQUID).cancel(16);
filter().type(Entity1_17Types.GOAT).cancel(17);
mapEntityTypeWithData(Entity1_17Types.AXOLOTL, Entity1_17Types.TROPICAL_FISH).jsonName();
mapEntityTypeWithData(Entity1_17Types.GOAT, Entity1_17Types.SHEEP).jsonName();
mapEntityTypeWithData(Entity1_17Types.GLOW_SQUID, Entity1_17Types.SQUID).jsonName();
mapEntityTypeWithData(Entity1_17Types.GLOW_ITEM_FRAME, Entity1_17Types.ITEM_FRAME);
// TODO Handle attachment pos?
filter().type(Entity1_17Types.SHULKER).addIndex(17);
// Ticks frozen
filter().removeIndex(7);
}
use of com.viaversion.viaversion.api.type.types.Particle in project ViaBackwards by ViaVersion.
the class EntityPackets1_18 method registerRewrites.
@Override
protected void registerRewrites() {
filter().handler((event, meta) -> {
meta.setMetaType(Types1_17.META_TYPES.byId(meta.metaType().typeId()));
MetaType type = meta.metaType();
if (type == Types1_17.META_TYPES.particleType) {
Particle particle = (Particle) meta.getValue();
if (particle.getId() == 3) {
// Block marker
Particle.ParticleData data = particle.getArguments().remove(0);
int blockState = (int) data.getValue();
if (blockState == 7786) {
// Light block
particle.setId(3);
} else {
// Else assume barrier block
particle.setId(2);
}
return;
}
rewriteParticle(particle);
}
});
// Particles have already been handled
registerMetaTypeHandler(Types1_17.META_TYPES.itemType, null, null, Types1_17.META_TYPES.optionalComponentType);
}
Aggregations