refactor access to context data

This commit is contained in:
gnembon committed 2023-01-16 19:01:10 +01:00
1 parent bc31faca21
commit 8dd08d5cb1
15 files changed
+239 -194

No files matched your search

@@ -51,7 +51,7 @@ public class BlockValue extends Value
public static BlockValue fromCoords(CarpetContext c, int x, int y, int z)
{
BlockPos pos = locateBlockPos(c, x,y,z);
return new BlockValue(null, c.s.getLevel(), pos);
return new BlockValue(null, c.level(), pos);
}
private static final Map<String, BlockValue> bvCache= new HashMap<>();
@@ -82,7 +82,8 @@ public class BlockValue extends Value
public static BlockPos locateBlockPos(CarpetContext c, int xpos, int ypos, int zpos)
{
return new BlockPos(c.origin.getX() + xpos, c.origin.getY() + ypos, c.origin.getZ() + zpos);
final BlockPos pos = c.origin();
return new BlockPos(pos.getX() + xpos, pos.getY() + ypos, pos.getZ() + zpos);
}
public BlockState getBlockState()
@@ -208,7 +208,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
if (strVal.equals("enderchest"))
{
Value v2 = params.get(1 + offset);
ServerPlayer player = EntityValue.getPlayerByValue(c.s.getServer(), v2);
ServerPlayer player = EntityValue.getPlayerByValue(c.server(), v2);
if (player == null) throw new InternalExpressionException("enderchest inventory requires player argument");
return new InventoryLocator(player, player.blockPosition(), player.getEnderChestInventory(), offset + 2, true);
}
@@ -222,7 +222,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
}
boolean isEnder = strVal.startsWith("enderchest_");
if (isEnder) strVal = strVal.substring(11); // len("enderchest_")
ServerPlayer player = c.s.getServer().getPlayerList().getPlayerByName(strVal);
ServerPlayer player = c.server().getPlayerList().getPlayerByName(strVal);
if (player == null) throw new InternalExpressionException("String description of an inventory should either denote a player or player's enderchest");
return new InventoryLocator(
player,
@@ -251,7 +251,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
BlockPos pos = ((BlockValue) v1).getPos();
if (pos == null)
throw new InternalExpressionException("Block to access inventory needs to be positioned in the world");
Container inv = getInventoryAt(c.s.getLevel(), pos);
Container inv = getInventoryAt(c.level(), pos);
if (inv == null)
return null;
return new InventoryLocator(pos, pos, inv, offset+1);
@@ -263,7 +263,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
NumericValue.asNumber(args.get(0)).getDouble(),
NumericValue.asNumber(args.get(1)).getDouble(),
NumericValue.asNumber(args.get(2)).getDouble());
Container inv = getInventoryAt(c.s.getLevel(), pos);
Container inv = getInventoryAt(c.level(), pos);
if (inv == null)
return null;
return new InventoryLocator(pos, pos, inv, offset+1);
@@ -277,7 +277,7 @@ public class NBTSerializableValue extends Value implements ContainerValueInterfa
NumericValue.asNumber(v1).getDouble(),
NumericValue.asNumber(params.get(1 + offset)).getDouble(),
NumericValue.asNumber(params.get(2 + offset)).getDouble());
Container inv = getInventoryAt(c.s.getLevel(), pos);
Container inv = getInventoryAt(c.level(), pos);
if (inv == null)
return null;
return new InventoryLocator(pos, pos, inv, offset + 3);