build in script load from resources, added 2 more events, added event test
This commit is contained in:
1 parent
87eb46b773
commit
fc66ec9c93
8 files changed
+487
-341
No files matched your search
@@ -31,6 +31,7 @@ import net.minecraft.block.CommandBlock;
|
||||
import net.minecraft.block.JigsawBlock;
|
||||
import net.minecraft.block.StructureBlock;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.network.packet.GuiSlotUpdateS2CPacket;
|
||||
import net.minecraft.client.network.packet.PlaySoundIdS2CPacket;
|
||||
import net.minecraft.command.arguments.ItemStackArgument;
|
||||
import net.minecraft.command.arguments.ParticleArgumentType;
|
||||
@@ -1051,6 +1052,13 @@ public class CarpetExpression
|
||||
* stack_limit('ender_pearl') => 16
|
||||
* stack_limit('stone') => 64
|
||||
* </pre>
|
||||
* <h3><code>item_category(item)</code></h3>
|
||||
* <p>Returns the string representing the category of a given item, like `building_blocks`, `combat`, or `tools`.</p>
|
||||
* <pre>
|
||||
* item_category('wooden_axe') => tools
|
||||
* item_category('ender_pearl') => misc
|
||||
* item_category('stone') => building_blocks
|
||||
* </pre>
|
||||
* <h3><code>inventory_size(inventory)</code></h3>
|
||||
* <p>Returns the size of the inventory for the entity or block in question. Returns null if the block or entity
|
||||
* don't have an inventory</p>
|
||||
@@ -1120,6 +1128,13 @@ public class CarpetExpression
|
||||
return (_c, _t) -> res;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("item_category", 1, (c, t, lv) ->
|
||||
{
|
||||
ItemStackArgument item = NBTSerializableValue.parseItem(lv.get(0).evalValue(c).getString());
|
||||
Value res = new StringValue(item.getItem().getGroup().getName());
|
||||
return (_c, _t) -> res;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("inventory_size", -1, (c, t, lv) ->
|
||||
{
|
||||
CarpetContext cc = (CarpetContext) c;
|
||||
@@ -1173,6 +1188,7 @@ public class CarpetExpression
|
||||
{
|
||||
// clear slot
|
||||
ItemStack removedStack = inventoryLocator.inventory.removeInvStack(slot);
|
||||
syncPlayerInventory(inventoryLocator, slot);
|
||||
//Value res = ListValue.fromItemStack(removedStack); // that tuple will be read only but cheaper if noone cares
|
||||
return (_c, _t) -> ListValue.fromItemStack(removedStack);
|
||||
}
|
||||
@@ -1182,6 +1198,7 @@ public class CarpetExpression
|
||||
ItemStack newStack = previousStack.copy();
|
||||
newStack.setCount(count);
|
||||
inventoryLocator.inventory.setInvStack(slot, newStack);
|
||||
syncPlayerInventory(inventoryLocator, slot);
|
||||
return (_c, _t) -> ListValue.fromItemStack(previousStack);
|
||||
}
|
||||
CompoundTag nbt = null; // skipping one argument
|
||||
@@ -1204,6 +1221,7 @@ public class CarpetExpression
|
||||
try
|
||||
{
|
||||
inventoryLocator.inventory.setInvStack(slot, newitem.createStack(count, false));
|
||||
syncPlayerInventory(inventoryLocator, slot);
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
@@ -1279,11 +1297,13 @@ public class CarpetExpression
|
||||
{
|
||||
stack.setCount(left);
|
||||
inventoryLocator.inventory.setInvStack(i, stack);
|
||||
syncPlayerInventory(inventoryLocator, i);
|
||||
return (_c, _t) -> Value.TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
inventoryLocator.inventory.removeInvStack(i);
|
||||
syncPlayerInventory(inventoryLocator, i);
|
||||
amount -= stack.getCount();
|
||||
}
|
||||
}
|
||||
@@ -1344,11 +1364,22 @@ public class CarpetExpression
|
||||
item.setToDefaultPickupDelay();
|
||||
cc.s.getWorld().spawnEntity(item);
|
||||
}
|
||||
inventoryLocator.inventory.markDirty();
|
||||
Value res = new NumericValue(item.getStack().getCount());
|
||||
return (_c, _t) -> res;
|
||||
});
|
||||
}
|
||||
private void syncPlayerInventory(NBTSerializableValue.InventoryLocator inventory, int int_1)
|
||||
{
|
||||
if (inventory.owner instanceof ServerPlayerEntity)
|
||||
{
|
||||
ServerPlayerEntity player = (ServerPlayerEntity) inventory.owner;
|
||||
player.networkHandler.sendPacket(new GuiSlotUpdateS2CPacket(
|
||||
-2,
|
||||
int_1,
|
||||
inventory.inventory.getInvStack(int_1)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -3105,6 +3136,8 @@ public class CarpetExpression
|
||||
* __on_player_stops_sneaking(player)
|
||||
* __on_player_starts_sprinting(player)
|
||||
* __on_player_stops_sprinting(player)
|
||||
* __on_player_drops_item(player)
|
||||
* __on_player_drops_stack(player)
|
||||
* </pre>
|
||||
* <h3><code>/script event</code> command</h3>
|
||||
* <p>used to display current events and bounded functions. use <code>add_to</code> ro register new event, or <code>remove_from</code>
|
||||
|
||||
Reference in new issue
Block a user