supersaiyansubtlety

player-interact.zs

Feb 17th, 2020
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. import crafttweaker.event.PlayerInteractEvent;
  2. import crafttweaker.event.PlayerInteractBlockEvent;
  3. import crafttweaker.event.PlayerInteractEntityEvent;
  4. import crafttweaker.event.PlayerUseHoeEvent;
  5. import crafttweaker.entity.IEntityLiving;
  6. import crafttweaker.entity.IEntityEquipmentSlot as slots;
  7. import crafttweaker.server.IServer;
  8. import crafttweaker.block.IBlock;
  9. import crafttweaker.block.IBlockState;
  10. import crafttweaker.entity.IEntity;
  11. import crafttweaker.world.IFacing;
  12. import crafttweaker.command.ICommandSender;
  13. import mods.ctutils.utils.Math;
  14. import crafttweaker.entity.IEntityLivingBase;
  15. import crafttweaker.world.IBlockPos;
  16. import mods.contenttweaker.BlockState;
  17. import crafttweaker.world.IVector3d;
  18. import mods.contenttweaker.Commands;
  19. import scripts.player_interact_statics as stats;
  20.  
  21. events.onPlayerInteract(function(event as PlayerInteractEvent)
  22. {
  23. if (event.player.world.isRemote() || isNull(event.player.currentItem)) { return; }
  24. print("PlayerInteractEvent fired");
  25. if (event.player.currentItem.definition.id == <minecraft:fire_charge>.definition.id)// &&
  26. {
  27. if (event.block.definition.id == <block:minecraft:air>.getBlock().definition.id || ((event.x == (event.player as IEntity).position.x) &&
  28. (event.y == Math.floor(event.player.y)) &&
  29. (event.z == (event.player as IEntity).position.z)))
  30. {
  31. val direction as IVector3d = event.player.lookingDirection.normalized.scale(0.061);
  32. var offset as IVector3d = crafttweaker.world.IVector3d.create(direction.x, 0, direction.z);
  33. offset = offset.normalized;
  34. val spawnX = event.player.x + offset.x;
  35. val spawnY = event.player.y + 1.1;
  36. val spawnZ = event.player.z + offset.z;
  37.  
  38. if(event.player.currentItem.amount > 1)
  39. {
  40. event.player.setItemToSlot(slots.mainHand(), event.player.currentItem.withAmount(event.player.currentItem.amount - 1));
  41. }
  42. else
  43. {
  44. event.player.setItemToSlot(slots.mainHand(), null);
  45. }
  46.  
  47. Commands.call("playsound item.firecharge.use player @s ~ ~ ~ 0.2", event.player, event.player.world, false, true);
  48.  
  49. Commands.call("summon small_fireball "~(spawnX as string)~" "~(spawnY as string)~" "~(spawnZ as string)~
  50. " {direction:["~direction.x~","~direction.y~","~direction.z~"],power:["~direction.x~","~direction.y~","~direction.z~"]}", event.player, event.player.world, false, true);
  51.  
  52. }
  53. }
  54. });
  55.  
  56. events.onPlayerInteractEntity(function(event as PlayerInteractEntityEvent)
  57. {
  58. if ((!isNull(event.player.currentItem)) && (event.player.currentItem.definition.id == <minecraft:flint_and_steel>.definition.id) && (event.target instanceof IEntityLiving))
  59. {
  60. print("flint and steel PlayerInteractEntityEvent fired");
  61. event.target.setFire(6);
  62. if (event.player.world.isRemote()) { return; }
  63.  
  64. Commands.call("playsound item.flintandsteel.use player @s ~ ~ ~ 0.2", event.player, event.player.world, false, true);
  65.  
  66. stats.damageTool(event);
  67. }
  68. });
  69.  
  70. events.onPlayerUseHoe(function(event as PlayerUseHoeEvent)
  71. {
  72. if (event.world.isRemote() || isNull(event.block.definition)) { return; }
  73. print("PlayerUseHoeEvent fired");
  74. if (stats.hoeMatchState has event.block.definition)
  75. {
  76. var newState = stats.hoeMatchState[event.block.definition];
  77.  
  78. for name in event.blockState.getPropertyNames()
  79. {
  80. newState = newState.withProperty(name, event.blockState.getPropertyValue(name));
  81. }
  82.  
  83. Commands.call("playsound item.hoe.till player @s ~ ~ ~ 0.15", event.player, event.player.world, false, true);
  84.  
  85. stats.damageTool(event);
  86.  
  87. event.world.setBlockState(newState, event.position);
  88. }
  89. else if (<minecraft:farmland>.asBlock().definition.id == event.block.definition.id)
  90. {
  91. Commands.call("playsound item.hoe.till player @s ~ ~ ~ 0.15", event.player, event.player.world, false, true);
  92.  
  93. stats.damageTool(event);
  94.  
  95. event.world.setBlockState(<blockstate:minecraft:dirt>, event.position);
  96. }
  97. });
Advertisement
Add Comment
Please, Sign In to add comment