Added mixin to properly handle Long Arrays

This commit is contained in:
rycbar0 2022-09-26 21:04:09 +02:00
parent 52aa0d9b8a
commit a091c17b83
4 changed files with 68 additions and 9 deletions

View File

@ -0,0 +1,37 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.launch.mixins;
import baritone.utils.accessor.INBTTagLongArray;
import net.minecraft.nbt.NBTTagLongArray;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
/**
* @author rycbar
* @since 26.09.2022
*/
@Mixin(NBTTagLongArray.class)
public abstract class MixinNBTTagLongArray implements INBTTagLongArray {
@Accessor("data")
@Override
public abstract long[] getLongArray();
}

View File

@ -31,6 +31,7 @@
"MixinStateImplementation", "MixinStateImplementation",
"MixinTabCompleter", "MixinTabCompleter",
"MixinVboRenderList", "MixinVboRenderList",
"MixinWorldClient" "MixinWorldClient",
"MixinNBTTagLongArray"
] ]
} }

View File

@ -0,0 +1,27 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/
package baritone.utils.accessor;
/**
* @author rycbar
* @since 26.09.2022
*/
public interface INBTTagLongArray {
long[] getLongArray();
}

View File

@ -18,6 +18,7 @@
package baritone.utils.schematic.format.defaults; package baritone.utils.schematic.format.defaults;
import baritone.utils.schematic.StaticSchematic; import baritone.utils.schematic.StaticSchematic;
import baritone.utils.accessor.INBTTagLongArray;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
import net.minecraft.nbt.*; import net.minecraft.nbt.*;
@ -180,14 +181,7 @@ public final class LitematicaSchematic extends StaticSchematic {
* @return array of Long values. * @return array of Long values.
*/ */
private static long[] getBlockStates() { private static long[] getBlockStates() {
String rawBlockString = Objects.requireNonNull((nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt))).toString(); return ((INBTTagLongArray) nbt.getCompoundTag(reg).getCompoundTag(subReg).getTag(blSt)).getLongArray();
rawBlockString = rawBlockString.substring(3,rawBlockString.length()-1);
String[] rawBlockArrayString = rawBlockString.split(",");
long[] rawBlockData = new long[rawBlockArrayString.length];
for (int i = 0; i < rawBlockArrayString.length; i++) {
rawBlockData[i] = Long.parseLong(rawBlockArrayString[i].substring(0,rawBlockArrayString[i].length()-1));
}
return rawBlockData;
} }
/** /**