fixing diamonds
This commit is contained in:
1 parent
986909c1f4
commit
7764217710
3 files changed
+65
-49
No files matched your search
+10
-9
@@ -2330,7 +2330,7 @@ This function is tentative - will likely change when chunk ticket API is properl
|
|||||||
|
|
||||||
These functions help scan larger areas of blocks without using generic loop functions, like nested `loop`.
|
These functions help scan larger areas of blocks without using generic loop functions, like nested `loop`.
|
||||||
|
|
||||||
### `scan(cx, cy, cz, dx, dy, dz, px?, py?, pz?, expr)`, `scan(center, range, lower_range?, expr)`
|
### `scan(center, range, lower_range?, expr)`
|
||||||
|
|
||||||
Evaluates expression over area of blocks defined by its center `center = (cx, cy, cz)`, expanded in all directions
|
Evaluates expression over area of blocks defined by its center `center = (cx, cy, cz)`, expanded in all directions
|
||||||
by `range = (dx, dy, dz)` blocks, or optionally in negative with `range` coords, and `upper_range` coords in
|
by `range = (dx, dy, dz)` blocks, or optionally in negative with `range` coords, and `upper_range` coords in
|
||||||
@@ -2346,7 +2346,7 @@ which would cause the expression not be evaluated for their boolean value.
|
|||||||
`scan` also handles `continue` and `break` statements, using `continue`'s return value to use in place of expression
|
`scan` also handles `continue` and `break` statements, using `continue`'s return value to use in place of expression
|
||||||
return value. `break` return value has no effect.
|
return value. `break` return value has no effect.
|
||||||
|
|
||||||
### `volume(x1, y1, z1, x2, y2, z2, expr), volume(pos1, pos2, expr)`
|
### `volume(from_pos, to_pos, expr)`
|
||||||
|
|
||||||
Evaluates expression for each block in the area, the same as the `scan` function, but using two opposite corners of
|
Evaluates expression for each block in the area, the same as the `scan` function, but using two opposite corners of
|
||||||
the rectangular cuboid. Any corners can be specified, its like you would do with `/fill` command.
|
the rectangular cuboid. Any corners can be specified, its like you would do with `/fill` command.
|
||||||
@@ -2354,7 +2354,7 @@ You can use a position or three coordinates to specify, it doesn't matter.
|
|||||||
|
|
||||||
For return value and handling `break` and `continue` statements, see `scan` function above.
|
For return value and handling `break` and `continue` statements, see `scan` function above.
|
||||||
|
|
||||||
### `neighbours(x, y, z), neighbours(block), neighbours(l(x,y,z))`
|
### `neighbours(pos)`
|
||||||
|
|
||||||
Returns the list of 6 neighbouring blocks to the argument. Commonly used with other loop functions like `for`.
|
Returns the list of 6 neighbouring blocks to the argument. Commonly used with other loop functions like `for`.
|
||||||
|
|
||||||
@@ -2362,19 +2362,20 @@ Returns the list of 6 neighbouring blocks to the argument. Commonly used with ot
|
|||||||
for(neighbours(x,y,z),air(_)) => 4 // number of air blocks around a block
|
for(neighbours(x,y,z),air(_)) => 4 // number of air blocks around a block
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
### `rect(cx, cy, cz, dx?, dy?, dz?, px?, py?, pz?), rect(centre, difference?, positive_diff?)`
|
### `rect(centre, range?, positive_range?)`
|
||||||
|
|
||||||
Returns an iterator, just like `range` function that iterates over a rectangular area of blocks. If only center
|
Returns an iterator, just like `range` function that iterates over a rectangular area of blocks. If only center
|
||||||
point is specified, it iterates over 27 blocks. If `d` (`difference`) arguments are specified, expands selection by the respective
|
point is specified, it iterates over 27 blocks. If `range` arguments are specified, expands selection by the respective
|
||||||
number of blocks in each direction. If `p` (`positive_diff`) arguments are specified, it uses `d` (`difference`) for negative offset, and `p` for positive.
|
number of blocks in each direction. If `positive_range` arguments are specified,
|
||||||
|
it uses `range` for negative offset, and `positive_range` for positive.
|
||||||
|
|
||||||
`centre` can be defined either as three coordinates, a list of three coords, or a block value.
|
`centre` can be defined either as three coordinates, a list of three coords, or a block value.
|
||||||
`difference` and `positive_diff` can have the same representations, just if its a block, it computes the distance to the center
|
`range` and `positive_range` can have the same representations, just if its a block, it computes the distance to the center
|
||||||
as range instead of taking the values as is.`
|
as range instead of taking the values as is.`
|
||||||
|
|
||||||
### `diamond(cx, cy, cz, radius?, height?), diamond(centre, radius?, height?)`
|
### `diamond(centre_pos, radius?, height?)`
|
||||||
|
|
||||||
Iterates over a diamond like area of blocks. With no radius and height, its 7 blocks centered around the middle `centre = l(cx, cy, cz)`
|
Iterates over a diamond like area of blocks. With no radius and height, its 7 blocks centered around the middle
|
||||||
(block + neighbours). With a radius specified, it expands shape on x and z coords, and with a custom height, on y.
|
(block + neighbours). With a radius specified, it expands shape on x and z coords, and with a custom height, on y.
|
||||||
Any of these can be zero as well. radius of 0 makes a stick, height of 0 makes a diamond shape pad.
|
Any of these can be zero as well. radius of 0 makes a stick, height of 0 makes a diamond shape pad.
|
||||||
# Entity API
|
# Entity API
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
These functions help scan larger areas of blocks without using generic loop functions, like nested `loop`.
|
These functions help scan larger areas of blocks without using generic loop functions, like nested `loop`.
|
||||||
|
|
||||||
### `scan(cx, cy, cz, dx, dy, dz, px?, py?, pz?, expr)`, `scan(center, range, lower_range?, expr)`
|
### `scan(center, range, lower_range?, expr)`
|
||||||
|
|
||||||
Evaluates expression over area of blocks defined by its center `center = (cx, cy, cz)`, expanded in all directions
|
Evaluates expression over area of blocks defined by its center `center = (cx, cy, cz)`, expanded in all directions
|
||||||
by `range = (dx, dy, dz)` blocks, or optionally in negative with `range` coords, and `upper_range` coords in
|
by `range = (dx, dy, dz)` blocks, or optionally in negative with `range` coords, and `upper_range` coords in
|
||||||
@@ -18,7 +18,7 @@ which would cause the expression not be evaluated for their boolean value.
|
|||||||
`scan` also handles `continue` and `break` statements, using `continue`'s return value to use in place of expression
|
`scan` also handles `continue` and `break` statements, using `continue`'s return value to use in place of expression
|
||||||
return value. `break` return value has no effect.
|
return value. `break` return value has no effect.
|
||||||
|
|
||||||
### `volume(x1, y1, z1, x2, y2, z2, expr), volume(pos1, pos2, expr)`
|
### `volume(from_pos, to_pos, expr)`
|
||||||
|
|
||||||
Evaluates expression for each block in the area, the same as the `scan` function, but using two opposite corners of
|
Evaluates expression for each block in the area, the same as the `scan` function, but using two opposite corners of
|
||||||
the rectangular cuboid. Any corners can be specified, its like you would do with `/fill` command.
|
the rectangular cuboid. Any corners can be specified, its like you would do with `/fill` command.
|
||||||
@@ -26,7 +26,7 @@ You can use a position or three coordinates to specify, it doesn't matter.
|
|||||||
|
|
||||||
For return value and handling `break` and `continue` statements, see `scan` function above.
|
For return value and handling `break` and `continue` statements, see `scan` function above.
|
||||||
|
|
||||||
### `neighbours(x, y, z), neighbours(block), neighbours(l(x,y,z))`
|
### `neighbours(pos)`
|
||||||
|
|
||||||
Returns the list of 6 neighbouring blocks to the argument. Commonly used with other loop functions like `for`.
|
Returns the list of 6 neighbouring blocks to the argument. Commonly used with other loop functions like `for`.
|
||||||
|
|
||||||
@@ -34,17 +34,18 @@ Returns the list of 6 neighbouring blocks to the argument. Commonly used with ot
|
|||||||
for(neighbours(x,y,z),air(_)) => 4 // number of air blocks around a block
|
for(neighbours(x,y,z),air(_)) => 4 // number of air blocks around a block
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
### `rect(cx, cy, cz, dx?, dy?, dz?, px?, py?, pz?), rect(centre, difference?, positive_diff?)`
|
### `rect(centre, range?, positive_range?)`
|
||||||
|
|
||||||
Returns an iterator, just like `range` function that iterates over a rectangular area of blocks. If only center
|
Returns an iterator, just like `range` function that iterates over a rectangular area of blocks. If only center
|
||||||
point is specified, it iterates over 27 blocks. If `d` (`difference`) arguments are specified, expands selection by the respective
|
point is specified, it iterates over 27 blocks. If `range` arguments are specified, expands selection by the respective
|
||||||
number of blocks in each direction. If `p` (`positive_diff`) arguments are specified, it uses `d` (`difference`) for negative offset, and `p` for positive.
|
number of blocks in each direction. If `positive_range` arguments are specified,
|
||||||
|
it uses `range` for negative offset, and `positive_range` for positive.
|
||||||
|
|
||||||
`centre` can be defined either as three coordinates, a list of three coords, or a block value.
|
`centre` can be defined either as three coordinates, a list of three coords, or a block value.
|
||||||
`difference` and `positive_diff` can have the same representations, just if its a block, it computes the distance to the center
|
`range` and `positive_range` can have the same representations, just if its a block, it computes the distance to the center
|
||||||
as range instead of taking the values as is.`
|
as range instead of taking the values as is.`
|
||||||
|
|
||||||
### `diamond(cx, cy, cz, radius?, height?), diamond(centre, radius?, height?)`
|
### `diamond(centre_pos, radius?, height?)`
|
||||||
|
|
||||||
Iterates over a diamond like area of blocks. With no radius and height, its 7 blocks centered around the middle
|
Iterates over a diamond like area of blocks. With no radius and height, its 7 blocks centered around the middle
|
||||||
(block + neighbours). With a radius specified, it expands shape on x and z coords, and with a custom height, on y.
|
(block + neighbours). With a radius specified, it expands shape on x and z coords, and with a custom height, on y.
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ import net.minecraft.util.math.ChunkPos;
|
|||||||
import net.minecraft.util.math.Direction;
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.EulerAngle;
|
import net.minecraft.util.math.EulerAngle;
|
||||||
import net.minecraft.util.math.BlockBox;
|
import net.minecraft.util.math.BlockBox;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.Vec3i;
|
import net.minecraft.util.math.Vec3i;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
@@ -2227,8 +2228,8 @@ public class CarpetExpression
|
|||||||
|
|
||||||
BlockArgument pos1Locator = BlockArgument.findIn(cc, lv, 0);
|
BlockArgument pos1Locator = BlockArgument.findIn(cc, lv, 0);
|
||||||
BlockArgument pos2Locator = BlockArgument.findIn(cc, lv, pos1Locator.offset);
|
BlockArgument pos2Locator = BlockArgument.findIn(cc, lv, pos1Locator.offset);
|
||||||
BlockPos pos2 = pos2Locator.block.getPos();
|
|
||||||
BlockPos pos1 = pos1Locator.block.getPos();
|
BlockPos pos1 = pos1Locator.block.getPos();
|
||||||
|
BlockPos pos2 = pos2Locator.block.getPos();
|
||||||
|
|
||||||
int x1 = pos1.getX();
|
int x1 = pos1.getX();
|
||||||
int y1 = pos1.getY();
|
int y1 = pos1.getY();
|
||||||
@@ -2313,41 +2314,54 @@ public class CarpetExpression
|
|||||||
this.expr.addLazyFunction("rect", -1, (c, t, lv)->
|
this.expr.addLazyFunction("rect", -1, (c, t, lv)->
|
||||||
{
|
{
|
||||||
CarpetContext cc = (CarpetContext) c;
|
CarpetContext cc = (CarpetContext) c;
|
||||||
|
int cx, cy, cz;
|
||||||
int cx;
|
int sminx, sminy, sminz;
|
||||||
int cy;
|
int smaxx, smaxy, smaxz;
|
||||||
int cz;
|
|
||||||
int sminx;
|
|
||||||
int sminy;
|
|
||||||
int sminz;
|
|
||||||
int smaxx;
|
|
||||||
int smaxy;
|
|
||||||
int smaxz;
|
|
||||||
|
|
||||||
BlockArgument cposLocator = BlockArgument.findIn(cc, lv, 0);
|
BlockArgument cposLocator = BlockArgument.findIn(cc, lv, 0);
|
||||||
BlockPos cpos = cposLocator.block.getPos();
|
BlockPos cpos = cposLocator.block.getPos();
|
||||||
|
|
||||||
cx = cpos.getX();
|
cx = cpos.getX();
|
||||||
cy = cpos.getY();
|
cy = cpos.getY();
|
||||||
cz = cpos.getZ();
|
cz = cpos.getZ();
|
||||||
|
if (lv.size() > cposLocator.offset)
|
||||||
if(lv.size()>cposLocator.offset){
|
{
|
||||||
BlockArgument diff_Locator = BlockArgument.findIn(cc, lv, cposLocator.offset);
|
Vector3Argument diffLocator = Vector3Argument.findIn(cc, lv, cposLocator.offset);
|
||||||
BlockPos difference = diff_Locator.block.getPos();
|
if (diffLocator.fromBlock)
|
||||||
sminx = difference.getX();
|
{
|
||||||
sminy = difference.getY();
|
sminx = MathHelper.floor(abs(diffLocator.vec.x - cx));
|
||||||
sminz = difference.getZ();
|
sminy = MathHelper.floor(abs(diffLocator.vec.y - cx));
|
||||||
if(lv.size()>diff_Locator.offset){
|
sminz = MathHelper.floor(abs(diffLocator.vec.z - cx));
|
||||||
BlockPos pos_diff=BlockArgument.findIn(cc,lv,diff_Locator.offset).block.getPos();
|
}
|
||||||
smaxx = pos_diff.getX();
|
else
|
||||||
smaxy = pos_diff.getY();
|
{
|
||||||
smaxz = pos_diff.getZ();
|
sminx = MathHelper.floor(abs(diffLocator.vec.x));
|
||||||
}else{
|
sminy = MathHelper.floor(abs(diffLocator.vec.y));
|
||||||
|
sminz = MathHelper.floor(abs(diffLocator.vec.z));
|
||||||
|
}
|
||||||
|
if (lv.size() > diffLocator.offset)
|
||||||
|
{
|
||||||
|
Vector3Argument posDiff = Vector3Argument.findIn(cc, lv, diffLocator.offset);
|
||||||
|
if (posDiff.fromBlock)
|
||||||
|
{
|
||||||
|
smaxx = MathHelper.floor(abs(posDiff.vec.x - cx));
|
||||||
|
smaxy = MathHelper.floor(abs(posDiff.vec.y - cx));
|
||||||
|
smaxz = MathHelper.floor(abs(posDiff.vec.z - cx));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
smaxx = MathHelper.floor(abs(posDiff.vec.x));
|
||||||
|
smaxy = MathHelper.floor(abs(posDiff.vec.y));
|
||||||
|
smaxz = MathHelper.floor(abs(posDiff.vec.z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
smaxx = sminx;
|
smaxx = sminx;
|
||||||
smaxy = sminy;
|
smaxy = sminy;
|
||||||
smaxz = sminz;
|
smaxz = sminz;
|
||||||
}
|
}
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
sminx = 1;
|
sminx = 1;
|
||||||
sminy = 1;
|
sminy = 1;
|
||||||
sminz = 1;
|
sminz = 1;
|
||||||
@@ -2439,7 +2453,7 @@ public class CarpetExpression
|
|||||||
cy = cpos.getY();
|
cy = cpos.getY();
|
||||||
cz = cpos.getZ();
|
cz = cpos.getZ();
|
||||||
|
|
||||||
if (lv.size()==1+cposLocator.offset)
|
if (lv.size()==cposLocator.offset)
|
||||||
{
|
{
|
||||||
Value retval = ListValue.of(
|
Value retval = ListValue.of(
|
||||||
BlockValue.fromCoords(cc, cx, cy-1, cz),
|
BlockValue.fromCoords(cc, cx, cy-1, cz),
|
||||||
@@ -2452,22 +2466,22 @@ public class CarpetExpression
|
|||||||
);
|
);
|
||||||
return (_c, _t ) -> retval;
|
return (_c, _t ) -> retval;
|
||||||
}
|
}
|
||||||
else if (lv.size()==2+cposLocator.offset)
|
else if (lv.size()==1+cposLocator.offset)
|
||||||
{
|
{
|
||||||
width = (int) ((NumericValue) lv.get(cposLocator.offset).evalValue(c)).getLong();
|
width = (int) ((NumericValue) lv.get(cposLocator.offset).evalValue(c)).getLong();
|
||||||
height = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
else if(lv.size()==3+cposLocator.offset)
|
else if(lv.size()==2+cposLocator.offset)
|
||||||
{
|
{
|
||||||
width = (int) ((NumericValue) lv.get(cposLocator.offset).evalValue(c)).getLong();
|
width = (int) ((NumericValue) lv.get(cposLocator.offset).evalValue(c)).getLong();
|
||||||
height = (int) ((NumericValue) lv.get(cposLocator.offset+1).evalValue(c)).getLong();
|
height = (int) ((NumericValue) lv.get(cposLocator.offset+1).evalValue(c)).getLong();
|
||||||
} else{
|
} else{
|
||||||
throw new InternalExpressionException("Incorrect number of arguments for diamond");
|
throw new InternalExpressionException("Incorrect number of arguments for 'diamond'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ClassCastException exc)
|
catch (ClassCastException exc)
|
||||||
{
|
{
|
||||||
throw new InternalExpressionException("Attempted to pass a non-number to diamond");
|
throw new InternalExpressionException("Attempted to pass a non-number to 'diamond'");
|
||||||
}
|
}
|
||||||
if (height == 0)
|
if (height == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user