mirror of
https://github.com/AtlasMediaGroup/Scissors.git
synced 2024-11-18 03:06:11 +00:00
261 lines
11 KiB
Diff
261 lines
11 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Business Goose <arclicious@vivaldi.net>
|
|
Date: Sat, 11 Jun 2022 23:33:13 -0500
|
|
Subject: [PATCH] Account for items inside containers
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/ContainerHelper.java b/src/main/java/net/minecraft/world/ContainerHelper.java
|
|
index 4092c7a8c2b0d9d26e6f4d97386735236300d132..9e0ab51dd7a4f9fed8f9edde962d42d4bbf604c1 100644
|
|
--- a/src/main/java/net/minecraft/world/ContainerHelper.java
|
|
+++ b/src/main/java/net/minecraft/world/ContainerHelper.java
|
|
@@ -2,6 +2,7 @@ package net.minecraft.world;
|
|
|
|
import java.util.List;
|
|
import java.util.function.Predicate;
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.core.NonNullList;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
import net.minecraft.nbt.ListTag;
|
|
@@ -22,10 +23,13 @@ public class ContainerHelper {
|
|
|
|
public static CompoundTag saveAllItems(CompoundTag nbt, NonNullList<ItemStack> stacks, boolean setIfEmpty) {
|
|
ListTag listTag = new ListTag();
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
|
|
for(int i = 0; i < stacks.size(); ++i) {
|
|
ItemStack itemStack = stacks.get(i);
|
|
if (!itemStack.isEmpty()) {
|
|
+ total += NbtUtility.getTagSize(itemStack.getTag()); // Scissors
|
|
CompoundTag compoundTag = new CompoundTag();
|
|
compoundTag.putByte("Slot", (byte)i);
|
|
itemStack.save(compoundTag);
|
|
@@ -33,7 +37,7 @@ public class ContainerHelper {
|
|
}
|
|
}
|
|
|
|
- if (!listTag.isEmpty() || setIfEmpty) {
|
|
+ if ((!listTag.isEmpty() || setIfEmpty) && !(total > NbtUtility.MAXIMUM_SIZE)) { // Scissors
|
|
nbt.put("Items", listTag);
|
|
}
|
|
|
|
@@ -42,11 +46,18 @@ public class ContainerHelper {
|
|
|
|
public static void loadAllItems(CompoundTag nbt, NonNullList<ItemStack> stacks) {
|
|
ListTag listTag = nbt.getList("Items", 10);
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
|
|
for(int i = 0; i < listTag.size(); ++i) {
|
|
CompoundTag compoundTag = listTag.getCompound(i);
|
|
int j = compoundTag.getByte("Slot") & 255;
|
|
if (j >= 0 && j < stacks.size()) {
|
|
+ total += NbtUtility.getTagSize(compoundTag);
|
|
+ if (total >= NbtUtility.MAXIMUM_SIZE) {
|
|
+ stacks.clear();
|
|
+ break;
|
|
+ }
|
|
stacks.set(j, ItemStack.of(compoundTag));
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
index 2a786c9fd29dc2139cf487fa645cd43345d60167..dbdc66620ae4284cfe96f633b1f4db46866b597b 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/AbstractFurnaceBlockEntity.java
|
|
@@ -9,6 +9,7 @@ import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import javax.annotation.Nullable;
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.SharedConstants;
|
|
import net.minecraft.Util;
|
|
import net.minecraft.core.BlockPos;
|
|
@@ -212,6 +213,16 @@ public abstract class AbstractFurnaceBlockEntity extends BaseContainerBlockEntit
|
|
public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
|
|
|
|
public List<ItemStack> getContents() {
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
+
|
|
+ for (ItemStack item : this.items) {
|
|
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
|
+ }
|
|
+
|
|
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
|
+ this.items.clear();
|
|
+ }
|
|
return this.items;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
|
|
index 416aa989ebb18a8741cc9d605a1180ab830f6643..893cf89dd2b022e2b785318e7e86eb5d75be8ed8 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
|
|
@@ -1,5 +1,6 @@
|
|
package net.minecraft.world.level.block.entity;
|
|
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.NonNullList;
|
|
@@ -34,6 +35,16 @@ public class BarrelBlockEntity extends RandomizableContainerBlockEntity {
|
|
|
|
@Override
|
|
public List<ItemStack> getContents() {
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
+
|
|
+ for (ItemStack item : this.items) {
|
|
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
|
+ }
|
|
+
|
|
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
|
+ this.items.clear();
|
|
+ }
|
|
return this.items;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
|
|
index c57efcb9a79337ec791e4e8f6671612f0a82b441..2963b72061a9ede734842d6fb46a67a1c41d4740 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/BrewingStandBlockEntity.java
|
|
@@ -3,6 +3,7 @@ package net.minecraft.world.level.block.entity;
|
|
import java.util.Arrays;
|
|
import java.util.Iterator;
|
|
import javax.annotation.Nullable;
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.NonNullList;
|
|
@@ -73,6 +74,16 @@ public class BrewingStandBlockEntity extends BaseContainerBlockEntity implements
|
|
}
|
|
|
|
public List<ItemStack> getContents() {
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
+
|
|
+ for (ItemStack item : this.items) {
|
|
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
|
+ }
|
|
+
|
|
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
|
+ this.items.clear();
|
|
+ }
|
|
return this.items;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
|
index a71414397bd45ee7bcacfeef0041d80dfa25f114..1b6f91055eb01627761e83e5e99e1731029b32ab 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/ChestBlockEntity.java
|
|
@@ -1,5 +1,6 @@
|
|
package net.minecraft.world.level.block.entity;
|
|
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.NonNullList;
|
|
@@ -40,6 +41,16 @@ public class ChestBlockEntity extends RandomizableContainerBlockEntity implement
|
|
private int maxStack = MAX_STACK;
|
|
|
|
public List<ItemStack> getContents() {
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
+
|
|
+ for (ItemStack item : this.items) {
|
|
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
|
+ }
|
|
+
|
|
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
|
+ this.items.clear();
|
|
+ }
|
|
return this.items;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
|
index 881379681c39230a00b3a1f11cd87498984396c7..1be5d600573f7632e6630224530dd76522e1b191 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/DispenserBlockEntity.java
|
|
@@ -1,5 +1,6 @@
|
|
package net.minecraft.world.level.block.entity;
|
|
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.NonNullList;
|
|
import net.minecraft.nbt.CompoundTag;
|
|
@@ -28,6 +29,16 @@ public class DispenserBlockEntity extends RandomizableContainerBlockEntity {
|
|
private int maxStack = MAX_STACK;
|
|
|
|
public List<ItemStack> getContents() {
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
+
|
|
+ for (ItemStack item : this.items) {
|
|
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
|
+ }
|
|
+
|
|
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
|
+ this.items.clear();
|
|
+ }
|
|
return this.items;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
index 789e5458f4a137694563a22612455506807de51b..84c721da46b7786857677b56f439c2b9448ba4b8 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
|
@@ -6,6 +6,7 @@ import java.util.function.BooleanSupplier;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.IntStream;
|
|
import javax.annotation.Nullable;
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.NonNullList;
|
|
@@ -56,6 +57,16 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
|
private int maxStack = MAX_STACK;
|
|
|
|
public List<ItemStack> getContents() {
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
+
|
|
+ for (ItemStack item : this.items) {
|
|
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
|
+ }
|
|
+
|
|
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
|
+ this.items.clear();
|
|
+ }
|
|
return this.items;
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
|
index b7686fd63b7c5d88c3a12ec4ee9bc01a17f997e0..c2904048625bb4439c7f0ba8a2605d3194b66070 100644
|
|
--- a/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/level/block/entity/ShulkerBoxBlockEntity.java
|
|
@@ -3,6 +3,7 @@ package net.minecraft.world.level.block.entity;
|
|
import java.util.List;
|
|
import java.util.stream.IntStream;
|
|
import javax.annotation.Nullable;
|
|
+import me.totalfreedom.scissors.NbtUtility;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.NonNullList;
|
|
@@ -60,6 +61,16 @@ public class ShulkerBoxBlockEntity extends RandomizableContainerBlockEntity impl
|
|
public boolean opened;
|
|
|
|
public List<ItemStack> getContents() {
|
|
+ // Scissors - Account for items inside containers
|
|
+ long total = 0;
|
|
+
|
|
+ for (ItemStack item : this.itemStacks) {
|
|
+ total += NbtUtility.getTagSize(item.getOrCreateTag());
|
|
+ }
|
|
+
|
|
+ if (total > NbtUtility.MAXIMUM_SIZE) {
|
|
+ this.itemStacks.clear();
|
|
+ }
|
|
return this.itemStacks;
|
|
}
|
|
|