Skip to content

Commit

Permalink
Updated Via API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Jan 5, 2024
1 parent b08b72f commit 8c40cb8
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public JsonBlockStateUpgradeSchema(final JsonObject jsonObject) {
}

if (matches) {
final CompoundTag newStates = mapping.newStateTag.clone();
final CompoundTag newStates = mapping.newStateTag.copy();
for (String property : mapping.copiedStates) {
if (states.contains(property)) {
newStates.put(property, states.get(property));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ValTagBlockStateUpgradeSchema() {
blockState = BedrockProtocol.MAPPINGS.getBedrockLegacyBlockStates().get(id << 6);
}

tag.put("states", blockState.blockStateTag().get("states").clone());
tag.put("states", blockState.blockStateTag().get("states").copy());

throw StopUpgrade.INSTANCE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
import com.viaversion.viaversion.libs.gson.JsonElement;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
import com.viaversion.viaversion.libs.opennbt.NBTIO;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.*;
import com.viaversion.viaversion.libs.opennbt.tag.io.NBTIO;
import com.viaversion.viaversion.libs.opennbt.tag.limiter.TagLimiter;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.Protocol1_20_3To1_20_2;
import com.viaversion.viaversion.util.GsonUtil;
import com.viaversion.viaversion.util.Key;
Expand All @@ -50,10 +51,7 @@

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -731,7 +729,7 @@ private CompoundTag readNBT(String file) {
return null;
}

return NBTIO.readTag(new GZIPInputStream(inputStream));
return NBTIO.readTag(new DataInputStream(new GZIPInputStream(inputStream)), TagLimiter.noop(), true, CompoundTag.class);
} catch (IOException e) {
this.getLogger().log(Level.SEVERE, "Could not read " + file, e);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void setNetId(final int netId) {

@Override
public BedrockItem copy() {
return new BedrockItem(this.id, this.data, this.amount, this.tag != null ? this.tag.clone() : null, this.canPlace.clone(), this.canBreak.clone(), this.blockingTicks, this.blockRuntimeId, this.usingNetId, this.netId);
return new BedrockItem(this.id, this.data, this.amount, this.tag != null ? this.tag.copy() : null, this.canPlace.clone(), this.canBreak.clone(), this.blockingTicks, this.blockRuntimeId, this.usingNetId, this.netId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public BlockProperties(final String name, final CompoundTag properties) {

public BlockProperties(final BlockProperties blockProperties) {
this.name = blockProperties.name;
this.properties = blockProperties.properties.clone();
this.properties = blockProperties.properties.copy();
}

public String name() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static void register(final BedrockProtocol protocol) {
version = new Semver("99.99.99");
}

final CompoundTag registries = BedrockProtocol.MAPPINGS.getJavaRegistries().clone();
final CompoundTag registries = BedrockProtocol.MAPPINGS.getJavaRegistries().copy();
final CompoundTag dimensionRegistry = registries.get("minecraft:dimension_type");
final CompoundTag biomeRegistry = registries.get("minecraft:worldgen/biome");
final ListTag dimensions = dimensionRegistry.get("value");
Expand Down Expand Up @@ -234,7 +234,7 @@ public static void register(final BedrockProtocol protocol) {
clientPlayer.setName(wrapper.user().getProtocolInfo().getUsername());

final PacketWrapper registryData = PacketWrapper.create(ClientboundConfigurationPackets1_20_3.REGISTRY_DATA, wrapper.user());
registryData.write(Type.COMPOUND_TAG, registries.clone()); // registries
registryData.write(Type.COMPOUND_TAG, registries.copy()); // registries
registryData.send(BedrockProtocol.class);

if (!enabledFeatures.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public BlockStateRewriter(final BlockProperties[] blockProperties, final boolean
.map(stringTagMap -> {
final CompoundTag combination = new CompoundTag();
for (Map.Entry<String, Tag> entry : stringTagMap.entrySet()) {
combination.put(entry.getKey(), entry.getValue().clone());
combination.put(entry.getKey(), entry.getValue().copy());
}
return combination;
}).collect(Collectors.toList());
Expand Down Expand Up @@ -203,7 +203,7 @@ public BlockStateRewriter(final BlockProperties[] blockProperties, final boolean
}

public int bedrockId(final CompoundTag bedrockBlockStateTag) {
final CompoundTag bedrockBlockStateTagClone = bedrockBlockStateTag.clone();
final CompoundTag bedrockBlockStateTagClone = bedrockBlockStateTag.copy();
try {
BedrockProtocol.MAPPINGS.getBedrockBlockStateUpgrader().upgradeToLatest(bedrockBlockStateTagClone);
this.blockStateSanitizer.sanitize(bedrockBlockStateTagClone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Item toJava(final UserConnection user, final BedrockItem bedrockItem) {

final CompoundTag javaTag = new CompoundTag();
if (this.overrideTag != null) {
javaTag.setValue(this.overrideTag.clone().getValue());
javaTag.setValue(this.overrideTag.copy().getValue());
}
if (this.displayName != null) {
final String newName = "Bedrock " + this.displayName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package net.raphimc.viabedrock.protocol.types.primitive;

import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.NamedCompoundTagType;
import com.viaversion.viaversion.libs.opennbt.tag.TagRegistry;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.libs.opennbt.tag.limiter.TagLimiter;
import io.netty.buffer.ByteBuf;
import net.raphimc.viabedrock.api.io.LittleEndianByteBufInputStream;
import net.raphimc.viabedrock.api.io.LittleEndianByteBufOutputStream;
Expand All @@ -37,10 +39,7 @@ public Tag read(ByteBuf buffer) throws Exception {
BedrockTypes.UTF8_STRING.read(buffer);
if (id == 0) return null;

final Tag tag = TagRegistry.createInstance(id);
tag.read(new LittleEndianByteBufInputStream(buffer));

return tag;
return TagRegistry.read(id, new LittleEndianByteBufInputStream(buffer), TagLimiter.create(NamedCompoundTagType.MAX_NBT_BYTES, NamedCompoundTagType.MAX_NESTING_LEVEL), 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
package net.raphimc.viabedrock.protocol.types.primitive;

import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.misc.NamedCompoundTagType;
import com.viaversion.viaversion.libs.opennbt.tag.TagRegistry;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.libs.opennbt.tag.limiter.TagLimiter;
import io.netty.buffer.ByteBuf;
import net.raphimc.viabedrock.api.io.NetworkByteBufInputStream;
import net.raphimc.viabedrock.api.io.NetworkByteBufOutputStream;
Expand All @@ -37,10 +39,7 @@ public Tag read(ByteBuf buffer) throws Exception {
BedrockTypes.STRING.read(buffer);
if (id == 0) return null;

final Tag tag = TagRegistry.createInstance(id);
tag.read(new NetworkByteBufInputStream(buffer));

return tag;
return TagRegistry.read(id, new NetworkByteBufInputStream(buffer), TagLimiter.create(NamedCompoundTagType.MAX_NBT_BYTES, NamedCompoundTagType.MAX_NESTING_LEVEL), 0);
}

@Override
Expand Down

0 comments on commit 8c40cb8

Please sign in to comment.