diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index ea2e78e4..7cf338b0 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -1234,7 +1234,8 @@ public class CarpetExpression *
Most functions in this category require inventory as the first argument. Inventory could be specified by
- * an entity, or a block, or position (three coordinates) of a potential block with inventory.
+ * an entity, or a block, or position (three coordinates) of a potential block with inventory. Player enderchest inventory
+ * require two arguments, keyword 'enderchest', followed by the player entity argument.
* If the entity or a block doesn't
* have an inventory, they typically do nothing and return null.
Most items returned are in the form of @@ -1262,6 +1263,7 @@ public class CarpetExpression * don't have an inventory
*
* inventory_size(player()) => 41
+ * inventory_size('enderchest', player()) => 27 // enderchest
* inventory_size(x,y,z) => 27 // chest
* inventory_size(block(pos)) => 5 // hopper
*
@@ -1585,7 +1587,7 @@ public class CarpetExpression
}
private void syncPlayerInventory(NBTSerializableValue.InventoryLocator inventory, int int_1)
{
- if (inventory.owner instanceof ServerPlayerEntity)
+ if (inventory.owner instanceof ServerPlayerEntity && !inventory.isEnder)
{
ServerPlayerEntity player = (ServerPlayerEntity) inventory.owner;
player.networkHandler.sendPacket(new GuiSlotUpdateS2CPacket(
diff --git a/src/main/java/carpet/script/value/NBTSerializableValue.java b/src/main/java/carpet/script/value/NBTSerializableValue.java
index 7cbeaec9..19585081 100644
--- a/src/main/java/carpet/script/value/NBTSerializableValue.java
+++ b/src/main/java/carpet/script/value/NBTSerializableValue.java
@@ -11,7 +11,6 @@ import net.minecraft.block.ChestBlock;
import net.minecraft.block.InventoryProvider;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
-import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.command.arguments.ItemStackArgument;
import net.minecraft.command.arguments.ItemStringReader;
import net.minecraft.command.arguments.NbtPathArgumentType;
@@ -32,7 +31,6 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
-import net.minecraft.world.World;
import java.util.Collection;
import java.util.HashMap;
@@ -201,6 +199,17 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
return null;
return new InventoryLocator(pos, pos, inv, offset + 1);
}
+ else if (v1.getString().equalsIgnoreCase("enderchest"))
+ {
+ Value v2 = params.get(1 + offset).evalValue(c);
+ if (!(v2 instanceof EntityValue) || !(((EntityValue) v2).getEntity() instanceof PlayerEntity))
+ {
+ throw new InternalExpressionException("enderchest inventory requires player argument");
+ }
+ PlayerEntity e = (PlayerEntity)((EntityValue) v2).getEntity();
+ inv = e.getEnderChestInventory();
+ return new InventoryLocator(e, e.getBlockPos(), inv, offset + 2, true);
+ }
BlockPos pos = new BlockPos(
NumericValue.asNumber(v1).getDouble(),
NumericValue.asNumber(params.get(1 + offset).evalValue(c)).getDouble(),
@@ -516,12 +525,19 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
public BlockPos position;
public Inventory inventory;
public int offset;
+ public boolean isEnder;
InventoryLocator(Object owner, BlockPos pos, Inventory i, int o)
+ {
+ this(owner, pos, i, o, false);
+ }
+
+ InventoryLocator(Object owner, BlockPos pos, Inventory i, int o, boolean isEnder)
{
this.owner = owner;
position = pos;
inventory = i;
offset = o;
+ this.isEnder = isEnder;
}
}