Merge branch 'master' into 1.16
This commit is contained in:
commit
2333f57f4a
3 files changed
+42
-15
No files matched your search
@@ -1646,19 +1646,26 @@ __on_chunk_generated(x, z) -> (
|
|||||||
|
|
||||||
### `place_item(item, pos, facing?, sneak?)`
|
### `place_item(item, pos, facing?, sneak?)`
|
||||||
|
|
||||||
Places a given item in the world like it was placed by a player. Item names are default minecraft item name,
|
Uses a given item in the world like it was used by a player. Item names are default minecraft item name,
|
||||||
less the minecraft prefix. Default facing is 'up', but there are other options: 'down', 'north', 'east', 'south',
|
less the minecraft prefix. Default facing is 'up', but there are other options: 'down', 'north', 'east', 'south',
|
||||||
'west', but also there are other secondary directions important for placement of blocks like stairs, doors, etc.
|
'west', but also there are other secondary directions important for placement of blocks like stairs, doors, etc.
|
||||||
Try experiment with options like 'north-up' which is placed facing north with cursor pointing to the upper part of the
|
Try experiment with options like 'north-up' which is placed facing north with cursor pointing to the upper part of the
|
||||||
block, or 'up-north', which means a block placed facing up (player looking down) and placed smidge away of the block
|
block, or 'up-north', which means a block placed facing up (player looking down) and placed smidge away of the block
|
||||||
center towards north. Optional sneak is a boolean indicating if a player would be sneaking while placing the
|
center towards north. Optional sneak is a boolean indicating if a player would be sneaking while placing the
|
||||||
block - this option only affects placement of chests and scaffolding at the moment. Returns true if placement was
|
block - this option only affects placement of chests and scaffolding at the moment.
|
||||||
|
|
||||||
|
Works with items that have the right-click effect on the block placed, `'like bone_meal`` on grass or axes on logs,
|
||||||
|
but doesn't open chests / containers, so have no effect on interactive blocks, like TNT, comparators, etc.
|
||||||
|
|
||||||
|
Returns true if placement/use was
|
||||||
successful, false otherwise.
|
successful, false otherwise.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
place_item('stone',x,y,z) // places a stone block on x,y,z block
|
place_item('stone',x,y,z) // places a stone block on x,y,z block
|
||||||
place_item('piston,x,y,z,'down') // places a piston facing down
|
place_item('piston,x,y,z,'down') // places a piston facing down
|
||||||
place_item('carrot',x,y,z) // attempts to plant a carrot plant. Returns true if could place carrots at that position.
|
place_item('carrot',x,y,z) // attempts to plant a carrot plant. Returns true if could place carrots at that position.
|
||||||
|
place_item('bone_meal',x,y,z) // attempts to bonemeal the ground.
|
||||||
|
place_item('wooden_axe',x,y,z) // attempts to strip the log.
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
### `set_poi(pos, type, occupancy?)`
|
### `set_poi(pos, type, occupancy?)`
|
||||||
|
|||||||
@@ -102,19 +102,26 @@ __on_chunk_generated(x, z) -> (
|
|||||||
|
|
||||||
### `place_item(item, pos, facing?, sneak?)`
|
### `place_item(item, pos, facing?, sneak?)`
|
||||||
|
|
||||||
Places a given item in the world like it was placed by a player. Item names are default minecraft item name,
|
Uses a given item in the world like it was used by a player. Item names are default minecraft item name,
|
||||||
less the minecraft prefix. Default facing is 'up', but there are other options: 'down', 'north', 'east', 'south',
|
less the minecraft prefix. Default facing is 'up', but there are other options: 'down', 'north', 'east', 'south',
|
||||||
'west', but also there are other secondary directions important for placement of blocks like stairs, doors, etc.
|
'west', but also there are other secondary directions important for placement of blocks like stairs, doors, etc.
|
||||||
Try experiment with options like 'north-up' which is placed facing north with cursor pointing to the upper part of the
|
Try experiment with options like 'north-up' which is placed facing north with cursor pointing to the upper part of the
|
||||||
block, or 'up-north', which means a block placed facing up (player looking down) and placed smidge away of the block
|
block, or 'up-north', which means a block placed facing up (player looking down) and placed smidge away of the block
|
||||||
center towards north. Optional sneak is a boolean indicating if a player would be sneaking while placing the
|
center towards north. Optional sneak is a boolean indicating if a player would be sneaking while placing the
|
||||||
block - this option only affects placement of chests and scaffolding at the moment. Returns true if placement was
|
block - this option only affects placement of chests and scaffolding at the moment.
|
||||||
|
|
||||||
|
Works with items that have the right-click effect on the block placed, `'like bone_meal`` on grass or axes on logs,
|
||||||
|
but doesn't open chests / containers, so have no effect on interactive blocks, like TNT, comparators, etc.
|
||||||
|
|
||||||
|
Returns true if placement/use was
|
||||||
successful, false otherwise.
|
successful, false otherwise.
|
||||||
|
|
||||||
<pre>
|
<pre>
|
||||||
place_item('stone',x,y,z) // places a stone block on x,y,z block
|
place_item('stone',x,y,z) // places a stone block on x,y,z block
|
||||||
place_item('piston,x,y,z,'down') // places a piston facing down
|
place_item('piston,x,y,z,'down') // places a piston facing down
|
||||||
place_item('carrot',x,y,z) // attempts to plant a carrot plant. Returns true if could place carrots at that position.
|
place_item('carrot',x,y,z) // attempts to plant a carrot plant. Returns true if could place carrots at that position.
|
||||||
|
place_item('bone_meal',x,y,z) // attempts to bonemeal the ground.
|
||||||
|
place_item('wooden_axe',x,y,z) // attempts to strip the log.
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
### `set_poi(pos, type, occupancy?)`
|
### `set_poi(pos, type, occupancy?)`
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ import net.minecraft.state.property.Property;
|
|||||||
import net.minecraft.structure.StructurePiece;
|
import net.minecraft.structure.StructurePiece;
|
||||||
import net.minecraft.structure.StructureStart;
|
import net.minecraft.structure.StructureStart;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Clearable;
|
import net.minecraft.util.Clearable;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import net.minecraft.util.InvalidIdentifierException;
|
import net.minecraft.util.InvalidIdentifierException;
|
||||||
@@ -1009,6 +1010,7 @@ public class CarpetExpression
|
|||||||
return success ? LazyValue.TRUE : LazyValue.FALSE;
|
return success ? LazyValue.TRUE : LazyValue.FALSE;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TODO rename to use_item
|
||||||
this.expr.addLazyFunction("place_item", -1, (c, t, lv) ->
|
this.expr.addLazyFunction("place_item", -1, (c, t, lv) ->
|
||||||
{
|
{
|
||||||
if (lv.size()<2)
|
if (lv.size()<2)
|
||||||
@@ -1024,18 +1026,28 @@ public class CarpetExpression
|
|||||||
boolean sneakPlace = false;
|
boolean sneakPlace = false;
|
||||||
if (lv.size() > locator.offset+1)
|
if (lv.size() > locator.offset+1)
|
||||||
sneakPlace = lv.get(locator.offset+1).evalValue(c).getBoolean();
|
sneakPlace = lv.get(locator.offset+1).evalValue(c).getBoolean();
|
||||||
if (stackArg.getItem() instanceof BlockItem)
|
|
||||||
|
BlockValue.PlacementContext ctx;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
ctx = BlockValue.PlacementContext.from(cc.s.getWorld(), where, facing, sneakPlace, stackArg.createStack(1, false));
|
||||||
|
}
|
||||||
|
catch (CommandSyntaxException e)
|
||||||
|
{
|
||||||
|
throw new InternalExpressionException(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(stackArg.getItem() instanceof BlockItem))
|
||||||
|
{
|
||||||
|
ActionResult useResult = ctx.getStack().useOnBlock(ctx);
|
||||||
|
if (useResult == ActionResult.CONSUME || useResult == ActionResult.SUCCESS)
|
||||||
|
{
|
||||||
|
return LazyValue.TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // not sure we need special case for block items, since useOnBlock can do that as well
|
||||||
BlockItem blockItem = (BlockItem) stackArg.getItem();
|
BlockItem blockItem = (BlockItem) stackArg.getItem();
|
||||||
BlockValue.PlacementContext ctx;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ctx = BlockValue.PlacementContext.from(cc.s.getWorld(), where, facing, sneakPlace, stackArg.createStack(1, false));
|
|
||||||
}
|
|
||||||
catch (CommandSyntaxException e)
|
|
||||||
{
|
|
||||||
throw new InternalExpressionException(e.getMessage());
|
|
||||||
}
|
|
||||||
if (!ctx.canPlace())
|
if (!ctx.canPlace())
|
||||||
return (_c, _t) -> Value.FALSE;
|
return (_c, _t) -> Value.FALSE;
|
||||||
BlockState placementState = blockItem.getBlock().getPlacementState(ctx);
|
BlockState placementState = blockItem.getBlock().getPlacementState(ctx);
|
||||||
@@ -1165,7 +1177,8 @@ public class CarpetExpression
|
|||||||
String reqString = requested.getString();
|
String reqString = requested.getString();
|
||||||
String structureName = FeatureGenerator.featureToStructure.get(reqString);
|
String structureName = FeatureGenerator.featureToStructure.get(reqString);
|
||||||
if (structureName == null) throw new InternalExpressionException("Unknown structure: " + reqString);
|
if (structureName == null) throw new InternalExpressionException("Unknown structure: " + reqString);
|
||||||
structure = Feature.STRUCTURES.get(structureName);
|
structure = Feature.STRUCTURES.get(structureName.toLowerCase(Locale.ROOT));
|
||||||
|
if (structure == null) throw new InternalExpressionException("Unsupported structure: " + structureName);
|
||||||
}
|
}
|
||||||
if (lv.size() > locator.offset+1)
|
if (lv.size() > locator.offset+1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user