mirror of
https://github.com/GTMEGA/EndlessIDs.git
synced 2026-11-12 18:57:37 +00:00
better item ID saving in nbt
This commit is contained in:
2 files changed
+35
-2
No files matched your search
+4
-2
@@ -1,5 +1,7 @@
|
||||
package com.falsepattern.endlessids.mixin.mixins.common.blockitem.vanilla;
|
||||
|
||||
import com.falsepattern.endlessids.constants.VanillaConstants;
|
||||
import com.falsepattern.endlessids.util.DataUtil;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@@ -29,7 +31,7 @@ public abstract class ItemStackMixin {
|
||||
*/
|
||||
@Overwrite
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("id", Item.getIdFromItem(this.field_151002_e));
|
||||
DataUtil.writeIDToNBT(nbt, Item.getIdFromItem(this.field_151002_e));
|
||||
nbt.setByte("Count", (byte) this.stackSize);
|
||||
nbt.setShort("Damage", (short) this.itemDamage);
|
||||
|
||||
@@ -46,7 +48,7 @@ public abstract class ItemStackMixin {
|
||||
*/
|
||||
@Overwrite
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
func_150996_a(Item.getItemById(nbt.getInteger("id")));
|
||||
func_150996_a(Item.getItemById(DataUtil.readIDFromNBT(nbt)));
|
||||
this.stackSize = nbt.getByte("Count");
|
||||
this.itemDamage = nbt.getShort("Damage");
|
||||
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package com.falsepattern.endlessids.util;
|
||||
|
||||
import com.falsepattern.endlessids.constants.VanillaConstants;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.chunk.NibbleArray;
|
||||
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.falsepattern.endlessids.constants.ExtendedConstants.blocksPerSubChunk;
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_INT;
|
||||
import static net.minecraftforge.common.util.Constants.NBT.TAG_SHORT;
|
||||
|
||||
public class DataUtil {
|
||||
public static byte[] ensureSubChunkByteArray(byte[] arr) {
|
||||
@@ -14,4 +21,28 @@ public class DataUtil {
|
||||
public static NibbleArray ensureSubChunkNibbleArray(byte[] data) {
|
||||
return data == null ? null : new NibbleArray(data.length == (blocksPerSubChunk >>> 1) ? data : Arrays.copyOf(data, (blocksPerSubChunk >>> 1)), 4);
|
||||
}
|
||||
|
||||
public static int readIDFromNBT(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey("idExt", TAG_INT))
|
||||
return nbt.getInteger("idExt");
|
||||
else if (nbt.hasKey("id", TAG_INT))
|
||||
return nbt.getInteger("id");
|
||||
else if (nbt.hasKey("id", TAG_SHORT))
|
||||
return nbt.getShort("id");
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void writeIDToNBT(NBTTagCompound nbt, int id) {
|
||||
if (id > VanillaConstants.maxItemID) {
|
||||
nbt.setShort("id", (short)0);
|
||||
nbt.setInteger("idExt", id);
|
||||
} else {
|
||||
nbt.setShort("id", (short) id);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean nbtHasID(NBTTagCompound nbt) {
|
||||
return nbt.hasKey("id", TAG_INT) || nbt.hasKey("idExt", TAG_INT) || nbt.hasKey("id", TAG_SHORT);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user