use of com.viaversion.viaversion.rewriter.StatisticsRewriter in project ViaVersion by ViaVersion.
the class Protocol1_16To1_15_2 method registerPackets.
@Override
protected void registerPackets() {
metadataRewriter.register();
itemRewriter.register();
EntityPackets.register(this);
WorldPackets.register(this);
tagRewriter = new TagRewriter(this);
tagRewriter.register(ClientboundPackets1_15.TAGS, RegistryType.ENTITY);
new StatisticsRewriter(this).register(ClientboundPackets1_15.STATISTICS);
// Login Success
registerClientbound(State.LOGIN, 0x02, 0x02, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
// Transform string to int array
UUID uuid = UUID.fromString(wrapper.read(Type.STRING));
wrapper.write(Type.UUID_INT_ARRAY, uuid);
});
}
});
// Motd Status - line breaks are no longer allowed for player samples
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);
JsonObject players = object.getAsJsonObject("players");
if (players == null)
return;
JsonArray sample = players.getAsJsonArray("sample");
if (sample == null)
return;
JsonArray splitSamples = new JsonArray();
for (JsonElement element : sample) {
JsonObject playerInfo = element.getAsJsonObject();
String name = playerInfo.getAsJsonPrimitive("name").getAsString();
if (name.indexOf('\n') == -1) {
splitSamples.add(playerInfo);
continue;
}
String id = playerInfo.getAsJsonPrimitive("id").getAsString();
for (String s : name.split("\n")) {
JsonObject newSample = new JsonObject();
newSample.addProperty("name", s);
newSample.addProperty("id", id);
splitSamples.add(newSample);
}
}
// Replace data if changed
if (splitSamples.size() != sample.size()) {
players.add("sample", splitSamples);
wrapper.set(Type.STRING, 0, object.toString());
}
});
}
});
ComponentRewriter componentRewriter = new TranslationMappings(this);
// Handle (relevant) component cases for translatable and score changes
registerClientbound(ClientboundPackets1_15.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.COMPONENT);
map(Type.BYTE);
handler(wrapper -> {
componentRewriter.processText(wrapper.get(Type.COMPONENT, 0));
// Sender uuid - always send as 'system'
wrapper.write(Type.UUID, ZERO_UUID);
});
}
});
componentRewriter.registerBossBar(ClientboundPackets1_15.BOSSBAR);
componentRewriter.registerTitle(ClientboundPackets1_15.TITLE);
componentRewriter.registerCombatEvent(ClientboundPackets1_15.COMBAT_EVENT);
SoundRewriter soundRewriter = new SoundRewriter(this);
soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
soundRewriter.registerSound(ClientboundPackets1_15.ENTITY_SOUND);
registerServerbound(ServerboundPackets1_16.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/pressing shift
wrapper.read(Type.BOOLEAN);
});
}
});
if (Via.getConfig().isIgnoreLong1_16ChannelNames()) {
registerServerbound(ServerboundPackets1_16.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
String channel = wrapper.passthrough(Type.STRING);
if (channel.length() > 32) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
Via.getPlatform().getLogger().warning("Ignoring incoming plugin channel, as it is longer than 32 characters: " + channel);
}
wrapper.cancel();
} else if (channel.equals("minecraft:register") || channel.equals("minecraft:unregister")) {
String[] channels = new String(wrapper.read(Type.REMAINING_BYTES), StandardCharsets.UTF_8).split("\0");
List<String> checkedChannels = new ArrayList<>(channels.length);
for (String registeredChannel : channels) {
if (registeredChannel.length() > 32) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
Via.getPlatform().getLogger().warning("Ignoring incoming plugin channel register of '" + registeredChannel + "', as it is longer than 32 characters");
}
continue;
}
checkedChannels.add(registeredChannel);
}
if (checkedChannels.isEmpty()) {
wrapper.cancel();
return;
}
wrapper.write(Type.REMAINING_BYTES, Joiner.on('\0').join(checkedChannels).getBytes(StandardCharsets.UTF_8));
}
});
}
});
}
registerServerbound(ServerboundPackets1_16.PLAYER_ABILITIES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.BYTE);
// Flying and walking speed - not important anyways
wrapper.write(Type.FLOAT, 0.05F);
wrapper.write(Type.FLOAT, 0.1F);
});
}
});
cancelServerbound(ServerboundPackets1_16.GENERATE_JIGSAW);
cancelServerbound(ServerboundPackets1_16.UPDATE_JIGSAW_BLOCK);
}
use of com.viaversion.viaversion.rewriter.StatisticsRewriter in project ViaBackwards by ViaVersion.
the class Protocol1_13To1_13_1 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_13_1To1_13.class, MAPPINGS::load);
entityRewriter.register();
itemRewriter.register();
WorldPackets1_13_1.register(this);
TranslatableRewriter translatableRewriter = new TranslatableRewriter(this);
translatableRewriter.registerChatMessage(ClientboundPackets1_13.CHAT_MESSAGE);
translatableRewriter.registerCombatEvent(ClientboundPackets1_13.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_13.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_13.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_13.TITLE);
translatableRewriter.registerPing();
new CommandRewriter1_13_1(this).registerDeclareCommands(ClientboundPackets1_13.DECLARE_COMMANDS);
registerServerbound(ServerboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.VAR_INT);
map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {
@Override
public String transform(PacketWrapper wrapper, String inputValue) {
// 1.13 starts sending slash at start, so we remove it for compatibility
return !inputValue.startsWith("/") ? "/" + inputValue : inputValue;
}
});
}
});
registerServerbound(ServerboundPackets1_13.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.FLAT_ITEM);
map(Type.BOOLEAN);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
itemRewriter.handleItemToServer(wrapper.get(Type.FLAT_ITEM, 0));
wrapper.write(Type.VAR_INT, 0);
}
});
}
});
registerClientbound(ClientboundPackets1_13.OPEN_WINDOW, new PacketRemapper() {
@Override
public void registerMap() {
// Id
map(Type.UNSIGNED_BYTE);
// Window Type
map(Type.STRING);
handler(wrapper -> {
JsonElement title = wrapper.passthrough(Type.COMPONENT);
translatableRewriter.processText(title);
if (ViaBackwards.getConfig().fix1_13FormattedInventoryTitle()) {
if (title.isJsonObject() && title.getAsJsonObject().size() == 1 && title.getAsJsonObject().has("translate")) {
// Hotfix simple translatable components from being converted to legacy text
return;
}
// https://bugs.mojang.com/browse/MC-124543
JsonObject legacyComponent = new JsonObject();
legacyComponent.addProperty("text", ChatRewriter.jsonToLegacyText(title.toString()));
wrapper.set(Type.COMPONENT, 0, legacyComponent);
}
});
}
});
registerClientbound(ClientboundPackets1_13.TAB_COMPLETE, new PacketRemapper() {
@Override
public void registerMap() {
// Transaction id
map(Type.VAR_INT);
// Start
map(Type.VAR_INT);
// Length
map(Type.VAR_INT);
// Count
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int start = wrapper.get(Type.VAR_INT, 1);
// Offset by +1 to take into account / at beginning
wrapper.set(Type.VAR_INT, 1, start - 1);
// Passthrough suggestions
int count = wrapper.get(Type.VAR_INT, 3);
for (int i = 0; i < count; i++) {
wrapper.passthrough(Type.STRING);
boolean hasTooltip = wrapper.passthrough(Type.BOOLEAN);
if (hasTooltip) {
// JSON Tooltip
wrapper.passthrough(Type.STRING);
}
}
}
});
}
});
registerClientbound(ClientboundPackets1_13.BOSSBAR, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UUID);
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 0);
if (action == 0 || action == 3) {
translatableRewriter.processText(wrapper.passthrough(Type.COMPONENT));
if (action == 0) {
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.VAR_INT);
short flags = wrapper.read(Type.UNSIGNED_BYTE);
if ((flags & 0x04) != 0)
flags |= 0x02;
wrapper.write(Type.UNSIGNED_BYTE, flags);
}
}
}
});
}
});
registerClientbound(ClientboundPackets1_13.ADVANCEMENTS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Reset/clear
wrapper.passthrough(Type.BOOLEAN);
// Mapping size
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
// Identifier
wrapper.passthrough(Type.STRING);
// Parent
if (wrapper.passthrough(Type.BOOLEAN))
wrapper.passthrough(Type.STRING);
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
// Title
wrapper.passthrough(Type.COMPONENT);
// Description
wrapper.passthrough(Type.COMPONENT);
Item icon = wrapper.passthrough(Type.FLAT_ITEM);
itemRewriter.handleItemToClient(icon);
// Frame type
wrapper.passthrough(Type.VAR_INT);
// Flags
int flags = wrapper.passthrough(Type.INT);
if ((flags & 1) != 0)
// Background texture
wrapper.passthrough(Type.STRING);
// X
wrapper.passthrough(Type.FLOAT);
// Y
wrapper.passthrough(Type.FLOAT);
}
// Criteria
wrapper.passthrough(Type.STRING_ARRAY);
int arrayLength = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < arrayLength; array++) {
// String array
wrapper.passthrough(Type.STRING_ARRAY);
}
}
}
});
}
});
new TagRewriter(this).register(ClientboundPackets1_13.TAGS, RegistryType.ITEM);
new StatisticsRewriter(this).register(ClientboundPackets1_13.STATISTICS);
}
use of com.viaversion.viaversion.rewriter.StatisticsRewriter 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.viaversion.rewriter.StatisticsRewriter 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.viaversion.rewriter.StatisticsRewriter in project ViaBackwards by ViaVersion.
the class Protocol1_13_2To1_14 method registerPackets.
@Override
protected void registerPackets() {
executeAsyncAfterLoaded(Protocol1_14To1_13_2.class, MAPPINGS::load);
translatableRewriter.registerBossBar(ClientboundPackets1_14.BOSSBAR);
translatableRewriter.registerChatMessage(ClientboundPackets1_14.CHAT_MESSAGE);
translatableRewriter.registerCombatEvent(ClientboundPackets1_14.COMBAT_EVENT);
translatableRewriter.registerDisconnect(ClientboundPackets1_14.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_14.TAB_LIST);
translatableRewriter.registerTitle(ClientboundPackets1_14.TITLE);
translatableRewriter.registerPing();
new CommandRewriter1_14(this).registerDeclareCommands(ClientboundPackets1_14.DECLARE_COMMANDS);
blockItemPackets = new BlockItemPackets1_14(this);
blockItemPackets.register();
entityRewriter.register();
new PlayerPackets1_14(this).register();
new SoundPackets1_14(this).register();
new StatisticsRewriter(this).register(ClientboundPackets1_14.STATISTICS);
cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_POSITION);
cancelClientbound(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE);
cancelClientbound(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING);
registerClientbound(ClientboundPackets1_14.TAGS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int blockTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < blockTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] blockIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < blockIds.length; j++) {
int id = blockIds[j];
// Ignore new blocktags
int blockId = getMappingData().getNewBlockId(id);
blockIds[j] = blockId;
}
}
int itemTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < itemTagsSize; i++) {
wrapper.passthrough(Type.STRING);
int[] itemIds = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
for (int j = 0; j < itemIds.length; j++) {
int itemId = itemIds[j];
// Ignore new itemtags
int oldId = getMappingData().getItemMappings().get(itemId);
itemIds[j] = oldId;
}
}
// fluid tags
int fluidTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < fluidTagsSize; i++) {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
}
// Eat entity tags
int entityTagsSize = wrapper.read(Type.VAR_INT);
for (int i = 0; i < entityTagsSize; i++) {
wrapper.read(Type.STRING);
wrapper.read(Type.VAR_INT_ARRAY_PRIMITIVE);
}
}
});
}
});
registerClientbound(ClientboundPackets1_14.UPDATE_LIGHT, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int x = wrapper.read(Type.VAR_INT);
int z = wrapper.read(Type.VAR_INT);
int skyLightMask = wrapper.read(Type.VAR_INT);
int blockLightMask = wrapper.read(Type.VAR_INT);
int emptySkyLightMask = wrapper.read(Type.VAR_INT);
int emptyBlockLightMask = wrapper.read(Type.VAR_INT);
byte[][] skyLight = new byte[16][];
// we don't need void and +256 light
if (isSet(skyLightMask, 0)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
for (int i = 0; i < 16; i++) {
if (isSet(skyLightMask, i + 1)) {
skyLight[i] = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
} else if (isSet(emptySkyLightMask, i + 1)) {
skyLight[i] = ChunkLightStorage.EMPTY_LIGHT;
}
}
if (isSet(skyLightMask, 17)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
byte[][] blockLight = new byte[16][];
if (isSet(blockLightMask, 0)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
for (int i = 0; i < 16; i++) {
if (isSet(blockLightMask, i + 1)) {
blockLight[i] = wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
} else if (isSet(emptyBlockLightMask, i + 1)) {
blockLight[i] = ChunkLightStorage.EMPTY_LIGHT;
}
}
if (isSet(blockLightMask, 17)) {
wrapper.read(Type.BYTE_ARRAY_PRIMITIVE);
}
// TODO Soft memory leak: Don't store light if chunk is already loaded
wrapper.user().get(ChunkLightStorage.class).setStoredLight(skyLight, blockLight, x, z);
wrapper.cancel();
}
private boolean isSet(int mask, int i) {
return (mask & (1 << i)) != 0;
}
});
}
});
}
Aggregations