diff --git a/manifest.json b/manifest.json index b7eddc3..d471132 100644 --- a/manifest.json +++ b/manifest.json @@ -211,7 +211,7 @@ }, { "projectID": 239197, - "fileID": 3587830, + "fileID": 4353149, "required": true }, { diff --git a/overrides/scripts/CustomWrench.zs b/overrides/scripts/CustomWrench.zs new file mode 100644 index 0000000..829dffe --- /dev/null +++ b/overrides/scripts/CustomWrench.zs @@ -0,0 +1,67 @@ +import crafttweaker.block.IBlock; +import crafttweaker.player.IPlayer; +import crafttweaker.block.IBlockPattern; +import crafttweaker.event.PlayerInteractBlockEvent; + +.add(, + , + , + ); + +.addAll(); + +static wrenchables as IBlockPattern = as IBlock | + as IBlock | + as IBlock | + as IBlock | + as IBlock | + as IBlock | + as IBlock; + +function isNotWrenchable(block as IBlock) as bool { + return isNull(block) || // no block + !(wrenchables has block); // not wrenchable +} + +function isNotWrenching(player as IPlayer) as bool { + return isNull(player) || // no player + !player.isSneaking || // not sneaking + isNull(player.currentItem) || // no item is held + !( has player.currentItem); // not a wrench +} + +function playerIsNotWrenchingWrenchable(evt as PlayerInteractBlockEvent) as bool { + // gracefully handle unusual circumstances + if (isNull(evt) || isNull(evt.world) || evt.canceled || evt.useItem == "DENY") + return true; + + return isNotWrenching(evt.player) || isNotWrenchable(evt.block); +} + +function dropItem(evt as PlayerInteractBlockEvent) as bool { + if (evt.world.remote) + return true; + + val stack = evt.world.getPickedBlock(evt.position, evt.player.getRayTrace(4, 0), evt.player); + + if (isNull(stack) || !evt.world.setBlockState(, evt.position)) + return false; + + // dummy entity to drop the item with + val dummy = .createEntity(evt.world); + dummy.posX = evt.x as double + 0.5; + dummy.posY = evt.y as double + 0.5; + dummy.posZ = evt.z as double + 0.5; + + dummy.dropItem(stack); +} + +events.onPlayerInteractBlock(function(evt as PlayerInteractBlockEvent) as void { + if (playerIsNotWrenchingWrenchable(evt)) + return; + + if (dropItem(evt)) { + evt.cancellationResult = "SUCCESS"; + evt.cancel(); + } +});