use of com.viaversion.viabackwards.api.rewriters.SoundRewriter in project ViaBackwards by ViaVersion.
the class Protocol1_15_2To1_16 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_16To1_15_2.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_16.BOSSBAR);
translatableRewriter.registerCombatEvent(ClientboundPackets1_16.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_16.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_16.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_16.TITLE);
translatableRewriter.registerPing();
new CommandRewriter1_16(this).registerDeclareCommands(ClientboundPackets1_16.DECLARE_COMMANDS);
(blockItemPackets = new BlockItemPackets1_16(this)).register();
entityRewriter.register();
registerClientbound(State.STATUS, 0x00, 0x00, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
String original = wrapper.passthrough(Type.STRING);
JsonObject object = GsonUtil.getGson().fromJson(original, JsonObject.class);
JsonElement description = object.get("description");
if (description == null)
return;
translatableRewriter.processText(description);
wrapper.set(Type.STRING, 0, object.toString());
});
}
});
registerClientbound(ClientboundPackets1_16.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
map(Type.BYTE);
// Sender
map(Type.UUID, Type.NOTHING);
}
});
registerClientbound(ClientboundPackets1_16.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Window Id
map(Type.VAR_INT);
// Window Type
map(Type.VAR_INT);
handler(wrapper -> translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT)));
handler(wrapper -> {
int windowType = wrapper.get(Type.VAR_INT, 1);
if (windowType == 20) {
// Smithing table
// Open anvil inventory
wrapper.set(Type.VAR_INT, 1, 7);
} else if (windowType > 20) {
wrapper.set(Type.VAR_INT, 1, --windowType);
}
});
}
});
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_16.STOP_SOUND);
// Login success
registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Transform int array to plain string
UUID uuid = wrapper.read(Type.UUID_INT_ARRAY);
wrapper.write(Type.STRING, uuid.toString());
});
}
});
new TagRewriter(this).register(ClientboundPackets1_16.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_16.STATISTICS);
registerServerbound(ServerboundPackets1_14.ENTITY_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// player id
wrapper.passthrough(Type.VAR_INT);
int action = wrapper.passthrough(Type.VAR_INT);
if (action == 0) {
wrapper.user().get(PlayerSneakStorage.class).setSneaking(true);
} else if (action == 1) {
wrapper.user().get(PlayerSneakStorage.class).setSneaking(false);
}
});
}
});
registerServerbound(ServerboundPackets1_14.INTERACT_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Entity Id
wrapper.passthrough(Type.VAR_INT);
int action = wrapper.passthrough(Type.VAR_INT);
if (action == 0 || action == 2) {
if (action == 2) {
// Location
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.FLOAT);
}
// Hand
wrapper.passthrough(Type.VAR_INT);
}
// New boolean: Whether the client is sneaking
wrapper.write(Type.BOOLEAN, wrapper.user().get(PlayerSneakStorage.class).isSneaking());
});
}
});
registerServerbound(ServerboundPackets1_14.PLAYER_ABILITIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
byte flags = wrapper.read(Type.BYTE);
// Only take the isFlying value (everything else has been removed and wasn't used anyways)
flags &= 2;
wrapper.write(Type.BYTE, flags);
wrapper.read(Type.FLOAT);
wrapper.read(Type.FLOAT);
});
}
});
cancelServerbound(ServerboundPackets1_14.UPDATE_JIGSAW_BLOCK);
}
use of com.viaversion.viabackwards.api.rewriters.SoundRewriter in project ViaBackwards by ViaVersion.
the class Protocol1_14_4To1_15 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_15To1_14_4.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR);
translatableRewriter.registerChatMessage(ClientboundPackets1_15.CHAT_MESSAGE);
translatableRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_15.DISCONNECT);
translatableRewriter.registerOpenWindow(ClientboundPackets1_15.OPEN_WINDOW);
translatableRewriter.registerTabList(ClientboundPackets1_15.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_15.TITLE);
translatableRewriter.registerPing();
(blockItemPackets = new BlockItemPackets1_15(this)).register();
entityRewriter.register();
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
soundRewriter.registerNamedSound(ClientboundPackets1_15.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_15.STOP_SOUND);
// Explosion - manually send an explosion sound
registerClientbound(ClientboundPackets1_15.EXPLOSION, new PacketRemapper() {
@Override
public void registerMap() {
// x
map(Type.FLOAT);
// y
map(Type.FLOAT);
// z
map(Type.FLOAT);
handler(wrapper -> {
PacketWrapper soundPacket = wrapper.create(ClientboundPackets1_14.SOUND);
// entity.generic.explode
soundPacket.write(Type.VAR_INT, 243);
// blocks category
soundPacket.write(Type.VAR_INT, 4);
// x
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 0)));
// y
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 1)));
// z
soundPacket.write(Type.INT, toEffectCoordinate(wrapper.get(Type.FLOAT, 2)));
// volume
soundPacket.write(Type.FLOAT, 4F);
// pitch - usually semi randomized by the server, but we don't really have to care about that
soundPacket.write(Type.FLOAT, 1F);
soundPacket.send(Protocol1_14_4To1_15.class);
});
}
private int toEffectCoordinate(float coordinate) {
return (int) (coordinate * 8);
}
});
new TagRewriter(this).register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_15.STATISTICS);
}
use of com.viaversion.viabackwards.api.rewriters.SoundRewriter in project ViaBackwards by ViaVersion.
the class Protocol1_9_4To1_10 method registerPackets.
protected void registerPackets() {
entityPackets.register();
blockItemPackets.register();
SoundRewriter soundRewriter = new SoundRewriter(this);
registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound name
map(Type.STRING);
// 1 - Sound Category
map(Type.VAR_INT);
// 2 - x
map(Type.INT);
// 3 - y
map(Type.INT);
// 4 - z
map(Type.INT);
// 5 - Volume
map(Type.FLOAT);
// 6 - Pitch
map(Type.FLOAT, TO_OLD_PITCH);
handler(soundRewriter.getNamedSoundHandler());
}
});
registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound name
map(Type.VAR_INT);
// 1 - Sound Category
map(Type.VAR_INT);
// 2 - x
map(Type.INT);
// 3 - y
map(Type.INT);
// 4 - z
map(Type.INT);
// 5 - Volume
map(Type.FLOAT);
// 6 - Pitch
map(Type.FLOAT, TO_OLD_PITCH);
handler(soundRewriter.getSoundHandler());
}
});
registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Hash
map(Type.STRING, Type.NOTHING);
// 1 - Result
map(Type.VAR_INT);
}
});
}
Aggregations