mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 09:20:28 +00:00
Clean up turtle inventory reading
This commit is contained in:
parent
0abd107348
commit
afe16cc593
@ -24,10 +24,9 @@ import net.minecraft.core.BlockPos;
|
|||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
|
||||||
import net.minecraft.nbt.Tag;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
|
import net.minecraft.world.ContainerHelper;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||||
@ -136,17 +135,8 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba
|
|||||||
super.loadServer(nbt);
|
super.loadServer(nbt);
|
||||||
|
|
||||||
// Read inventory
|
// Read inventory
|
||||||
var nbttaglist = nbt.getList("Items", Tag.TAG_COMPOUND);
|
ContainerHelper.loadAllItems(nbt, inventory);
|
||||||
inventory.clear();
|
for (var i = 0; i < inventory.size(); i++) inventorySnapshot.set(i, inventory.get(i).copy());
|
||||||
inventorySnapshot.clear();
|
|
||||||
for (var i = 0; i < nbttaglist.size(); i++) {
|
|
||||||
var tag = nbttaglist.getCompound(i);
|
|
||||||
var slot = tag.getByte("Slot") & 0xff;
|
|
||||||
if (slot < getContainerSize()) {
|
|
||||||
inventory.set(slot, ItemStack.of(tag));
|
|
||||||
inventorySnapshot.set(slot, inventory.get(slot).copy());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read state
|
// Read state
|
||||||
brain.readFromNBT(nbt);
|
brain.readFromNBT(nbt);
|
||||||
@ -155,16 +145,7 @@ public class TurtleBlockEntity extends AbstractComputerBlockEntity implements Ba
|
|||||||
@Override
|
@Override
|
||||||
public void saveAdditional(CompoundTag nbt) {
|
public void saveAdditional(CompoundTag nbt) {
|
||||||
// Write inventory
|
// Write inventory
|
||||||
var nbttaglist = new ListTag();
|
ContainerHelper.saveAllItems(nbt, inventory);
|
||||||
for (var i = 0; i < INVENTORY_SIZE; i++) {
|
|
||||||
if (!inventory.get(i).isEmpty()) {
|
|
||||||
var tag = new CompoundTag();
|
|
||||||
tag.putByte("Slot", (byte) i);
|
|
||||||
inventory.get(i).save(tag);
|
|
||||||
nbttaglist.add(tag);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
nbt.put("Items", nbttaglist);
|
|
||||||
|
|
||||||
// Write brain
|
// Write brain
|
||||||
nbt = brain.writeToNBT(nbt);
|
nbt = brain.writeToNBT(nbt);
|
||||||
|
@ -249,7 +249,10 @@ modPublishing {
|
|||||||
// Make sure configureReobfTaskForReobfJarJar runs after compilation
|
// Make sure configureReobfTaskForReobfJarJar runs after compilation
|
||||||
// see - https://github.com/SpongePowered/MixinGradle/pull/51
|
// see - https://github.com/SpongePowered/MixinGradle/pull/51
|
||||||
tasks.configureEach {
|
tasks.configureEach {
|
||||||
if (name == "configureReobfTaskForReobfJarJar") mustRunAfter(tasks.jarJar)
|
when (name) {
|
||||||
|
"configureReobfTaskForReobfJar" -> mustRunAfter(tasks.jar)
|
||||||
|
"configureReobfTaskForReobfJarJar" -> mustRunAfter(tasks.jarJar)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't publish the slim jar
|
// Don't publish the slim jar
|
||||||
|
Loading…
Reference in New Issue
Block a user