Skip to content

Commit

Permalink
1.18-rc3
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Nov 26, 2021
1 parent c285e99 commit efd64da
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 44 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ subprojects {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings loom.layered() {
officialMojangMappings()
parchment("org.parchmentmc.data:parchment-${rootProject.minecraft_version}:2021.10.10")
// parchment("org.parchmentmc.data:parchment-${rootProject.minecraft_version}:2021.10.10")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
def ENV = System.getenv()

architectury {
common()
common(false)
}

configurations {
Expand Down
161 changes: 127 additions & 34 deletions common/src/main/java/dev/latvian/mods/rhino/mod/util/NBTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,7 @@

import io.netty.buffer.ByteBufInputStream;
import io.netty.handler.codec.EncoderException;
import net.minecraft.nbt.ByteArrayTag;
import net.minecraft.nbt.ByteTag;
import net.minecraft.nbt.CollectionTag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.DoubleTag;
import net.minecraft.nbt.FloatTag;
import net.minecraft.nbt.IntArrayTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.LongArrayTag;
import net.minecraft.nbt.LongTag;
import net.minecraft.nbt.NbtAccounter;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.ShortTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.TagType;
import net.minecraft.nbt.TagTypes;
import net.minecraft.nbt.*;
import net.minecraft.network.FriendlyByteBuf;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -177,7 +160,7 @@ private static TagType<?> convertType(TagType<?> tagType) {
return tagType == CompoundTag.TYPE ? COMPOUND_TYPE : tagType == ListTag.TYPE ? LIST_TYPE : tagType;
}

private static final TagType<OrderedCompoundTag> COMPOUND_TYPE = new TagType<OrderedCompoundTag>() {
private static final TagType<OrderedCompoundTag> COMPOUND_TYPE = new TagType.VariableSize<OrderedCompoundTag>() {
@Override
public OrderedCompoundTag load(DataInput dataInput, int i, NbtAccounter nbtAccounter) throws IOException {
nbtAccounter.accountBits(384L);
Expand All @@ -186,14 +169,14 @@ public OrderedCompoundTag load(DataInput dataInput, int i, NbtAccounter nbtAccou
} else {
Map<String, Tag> map = new LinkedHashMap<>();

byte b;
while ((b = dataInput.readByte()) != 0) {
String string = dataInput.readUTF();
nbtAccounter.accountBits(224L + 16L * string.length());
TagType<?> tagType = convertType(TagTypes.getType(b));
Tag tag = tagType.load(dataInput, i + 1, nbtAccounter);
byte typeId;
while ((typeId = dataInput.readByte()) != 0) {
String key = dataInput.readUTF();
nbtAccounter.accountBits(224L + 16L * key.length());
TagType<?> valueType = convertType(TagTypes.getType(typeId));
Tag value = valueType.load(dataInput, i + 1, nbtAccounter);

if (map.put(string, tag) != null) {
if (map.put(key, value) != null) {
nbtAccounter.accountBits(288L);
}
}
Expand All @@ -202,6 +185,66 @@ public OrderedCompoundTag load(DataInput dataInput, int i, NbtAccounter nbtAccou
}
}

@Override
public StreamTagVisitor.ValueResult parse(DataInput dataInput, StreamTagVisitor visitor) throws IOException {
while (true) {
byte typeId;
if ((typeId = dataInput.readByte()) != 0) {
TagType<?> valueType = convertType(TagTypes.getType(typeId));
switch (visitor.visitEntry(valueType)) {
case HALT:
return StreamTagVisitor.ValueResult.HALT;
case BREAK:
StringTag.skipString(dataInput);
valueType.skip(dataInput);
break;
case SKIP:
StringTag.skipString(dataInput);
valueType.skip(dataInput);
continue;
default:
String key = dataInput.readUTF();
switch (visitor.visitEntry(valueType, key)) {
case HALT:
return StreamTagVisitor.ValueResult.HALT;
case BREAK:
valueType.skip(dataInput);
break;
case SKIP:
valueType.skip(dataInput);
continue;
default:
switch (valueType.parse(dataInput, visitor)) {
case HALT:
return StreamTagVisitor.ValueResult.HALT;
case BREAK:
default:
continue;
}
}
}
}

if (typeId != 0) {
while ((typeId = dataInput.readByte()) != 0) {
StringTag.skipString(dataInput);
convertType(TagTypes.getType(typeId)).skip(dataInput);
}
}

return visitor.visitContainerEnd();
}
}

@Override
public void skip(DataInput dataInput) throws IOException {
byte typeId;
while ((typeId = dataInput.readByte()) != 0) {
StringTag.skipString(dataInput);
convertType(TagTypes.getType(typeId)).skip(dataInput);
}
}

@Override
public String getName() {
return "COMPOUND";
Expand All @@ -213,31 +256,81 @@ public String getPrettyName() {
}
};

private static final TagType<ListTag> LIST_TYPE = new TagType<ListTag>() {
private static final TagType<ListTag> LIST_TYPE = new TagType.VariableSize<ListTag>() {
@Override
public ListTag load(DataInput dataInput, int i, NbtAccounter nbtAccounter) throws IOException {
nbtAccounter.accountBits(296L);
if (i > 512) {
throw new RuntimeException("Tried to read NBT tag with too high complexity, depth > 512");
} else {
byte b = dataInput.readByte();
int j = dataInput.readInt();
if (b == 0 && j > 0) {
byte typeId = dataInput.readByte();
int size = dataInput.readInt();
if (typeId == 0 && size > 0) {
throw new RuntimeException("Missing type on ListTag");
} else {
nbtAccounter.accountBits(32L * (long) j);
TagType<?> tagType = convertType(TagTypes.getType(b));
nbtAccounter.accountBits(32L * (long) size);
TagType<?> valueType = convertType(TagTypes.getType(typeId));
ListTag list = new ListTag();

for (int k = 0; k < j; ++k) {
list.add(tagType.load(dataInput, i + 1, nbtAccounter));
for (int k = 0; k < size; ++k) {
list.add(valueType.load(dataInput, i + 1, nbtAccounter));
}

return list;
}
}
}

@Override
public StreamTagVisitor.ValueResult parse(DataInput dataInput, StreamTagVisitor visitor) throws IOException {
TagType<?> tagType = convertType(TagTypes.getType(dataInput.readByte()));
int size = dataInput.readInt();
switch (visitor.visitList(tagType, size)) {
case HALT:
return StreamTagVisitor.ValueResult.HALT;
case BREAK:
tagType.skip(dataInput, size);
return visitor.visitContainerEnd();
default:
int i = 0;

out:
for (; i < size; ++i) {
switch (visitor.visitElement(tagType, i)) {
case HALT:
return StreamTagVisitor.ValueResult.HALT;
case BREAK:
tagType.skip(dataInput);
break out;
case SKIP:
tagType.skip(dataInput);
break;
default:
switch (tagType.parse(dataInput, visitor)) {
case HALT:
return StreamTagVisitor.ValueResult.HALT;
case BREAK:
break out;
}
}
}

int toSkip = size - 1 - i;
if (toSkip > 0) {
tagType.skip(dataInput, toSkip);
}

return visitor.visitContainerEnd();
}
}

@Override
public void skip(DataInput visitor) throws IOException {
TagType<?> tagType = convertType(TagTypes.getType(visitor.readByte()));
int size = visitor.readInt();
tagType.skip(visitor, size);
}

@Override
public String getName() {
return "LIST";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;

/**
* @author LatvianModder
Expand All @@ -23,7 +24,11 @@ static AABB ofBlock(BlockPos pos) {
}

static AABB ofSize(double x, double y, double z) {
return AABB.ofSize(x, y, z);
return ofSize(Vec3.ZERO, x, y, z);
}

static AABB ofSize(Vec3 vec3, double x, double y, double z) {
return AABB.ofSize(vec3, x, y, z);
}

static AABB wrap(Object o) {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
mod_id=rhino
mod_name=rhino
mod_version=1605.1.5
mod_version=1800.1.5
mod_package=dev.latvian.mods
mod_author=LatvianModder
curseforge_id_forge=416294
curseforge_id_fabric=416294
curseforge_type=release
minecraft_version=1.16.5
architectury_version=1.20.28
fabric_loader_version=0.11.1
fabric_api_version=0.30.0+1.16
minecraft_version=1.18-rc3
architectury_version=3.0.39
fabric_loader_version=0.12.5
fabric_api_version=0.43.1+1.18
forge_version=36.2.2
kubejs_version=1605.3.16-build.112
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ pluginManagement {
}
}

include "common", "fabric", "forge"
include "common", "fabric" //, "forge"

rootProject.name = 'Rhino'

0 comments on commit efd64da

Please sign in to comment.