keaft

Untitled

Apr 11th, 2024 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. #Name: boss_summoning.zs
  2. #reloadable
  3. #Author: Keaft
  4.  
  5. import crafttweaker.data.IData;
  6. import crafttweaker.block.IBlock;
  7. import crafttweaker.block.IBlockState;
  8. import crafttweaker.command.ICommandManager;
  9. import crafttweaker.entity.AttributeInstance;
  10. import crafttweaker.entity.IEntity;
  11. import crafttweaker.entity.IEntityDefinition;
  12. import crafttweaker.entity.IEntityEquipmentSlot;
  13. import crafttweaker.entity.IEntityLivingBase;
  14. import crafttweaker.event.EntityJoinWorldEvent;
  15. import crafttweaker.event.IEventCancelable;
  16. import crafttweaker.event.PlayerInteractBlockEvent;
  17. import crafttweaker.event.PlayerInteractEvent;
  18. import crafttweaker.events.IEventManager;
  19. import crafttweaker.formatting.IFormattedText;
  20. import crafttweaker.item.IItemStack;
  21. import crafttweaker.world.IBlockPos;
  22. import crafttweaker.world.IWorld;
  23. import crafttweaker.player.IPlayer;
  24.  
  25. zenClass BasicBoss {
  26. // statics can't change
  27. static name as string = "tacoZombie";
  28.  
  29. // variables can be changed, DO declare variables for everything that I want to be able to change, likely establish defaults, but definitely vars for changing.
  30. var bossEvent as PlayerInteractBlockEvent;
  31. var bossClass as IEntityLivingBase;
  32. var maxHealth as int = 50;
  33. var armor as int = 0;
  34. var mainHandSlotItem as IItemStack = null;
  35. var offHandSlotItem as IItemStack = null;
  36. var headSlotItem as IItemStack = <minecraft:diamond_helmet>;
  37. var chestSlotItem as IItemStack = null;
  38. var legsSlotItem as IItemStack = null;
  39. var feetSlotItem as IItemStack = null;
  40. var localSummonMessage as string = "You feel the ground shake beneath you.";
  41.  
  42. // methods (functions), bits of functionality.
  43.  
  44. zenConstructor(eventParam as PlayerInteractBlockEvent){ // called whenever the class is initialized. Every call does the following instructions. Makes sure that I don't have to call every instruction every time.
  45. bossEvent = eventParam;
  46. // bossEvent.player.sendMessage("hi");
  47. var bossClass as IEntityLivingBase = <entity:minecraft:zombie>.createEntity(bossEvent.entityLivingBase.world);
  48. // bossEvent.player.sendMessage(this.bossClass.displayName as string);
  49. bossClass.setPosition(crafttweaker.util.Position3f.create(bossEvent.x, bossEvent.y + 1, bossEvent.z).asBlockPos());
  50. bossClass.setCustomName(name);
  51. bossClass.setItemToSlot(crafttweaker.entity.IEntityEquipmentSlot.mainHand(),mainHandSlotItem);
  52. bossClass.setItemToSlot(crafttweaker.entity.IEntityEquipmentSlot.offhand(),offHandSlotItem);
  53. bossClass.setItemToSlot(crafttweaker.entity.IEntityEquipmentSlot.head(),headSlotItem);
  54. bossClass.setItemToSlot(crafttweaker.entity.IEntityEquipmentSlot.chest(),chestSlotItem);
  55. bossClass.setItemToSlot(crafttweaker.entity.IEntityEquipmentSlot.legs(),legsSlotItem);
  56. bossClass.setItemToSlot(crafttweaker.entity.IEntityEquipmentSlot.feet(),feetSlotItem);
  57. bossClass.getAttribute("generic.maxHealth").baseValue = maxHealth; // Setting a baseValue needs a double even though the int works?
  58. bossClass.getAttribute("generic.armor").baseValue = armor;
  59. bossClass.health = maxHealth; // Health is a float???
  60. bossEvent.entityLivingBase.world.spawnEntity(bossClass);
  61. server.commandManager.executeCommand(server,"execute @a[x=" + bossEvent.x as int + ",y=" + bossEvent.y as int + ",z=" + bossEvent.z as int + ",r=15] ~ ~ ~ tellraw @a[x=~1,y=~1,z=~1,rm=0,r=15] [\"" + localSummonMessage + "\"]");
  62.  
  63. // setBossPosition(bossEvent.x, bossEvent.y + 1, bossEvent.z);
  64. }
  65.  
  66. // function setBossPosition(posX as int, posY as int, posZ as int){
  67.  
  68. // }
  69.  
  70. // function spawnBoss(){
  71. // bossEvent.player.sendMessage("saved the event properly.");
  72. // bossEvent.player.sendMessage(bossClass.displayName);
  73.  
  74. // this.bossClass.setPosition(crafttweaker.util.Position3f.create(eventParam.x, eventParam.y + 1, eventParam.z).asBlockPos());
  75. // bossEvent.entityLivingBase.world.spawnEntity(bossClass);
  76. // }
  77. }
  78.  
  79. print("Initializing 'boss_summoning'...");
  80.  
  81. var altarBlocks = [
  82. <minecraft:stone>/* ,
  83. <minecraft:grass> */
  84. ] as IBlock[];
  85.  
  86. var spawnItems = [
  87. <minecraft:diamond>
  88. ] as IItemStack[];
  89. // Associative array to associate IBlock with IEntityLivingBase
  90.  
  91. /* val changingArray = {
  92. <minecraft:dirt> : zombie
  93. } as IEntityLivingBase[IItemStack]; */
  94.  
  95. events.onPlayerInteractBlock(function(event as PlayerInteractBlockEvent){
  96. var currentAltar as IItemStack = null;
  97. var currentItem as IItemStack = null;
  98. var currentHand as string = null;
  99. // If it is on the client or the OFF_HAND, do not continue. 1.12.2 forge doesn't seem to be able to differentiate which hand is being fired here while crafttweaker does, but limiting it to 1 makes sure it doesn't fire multiple times.
  100. if(event.world.remote || event.hand == "OFF_HAND") {
  101. return;
  102. }
  103. // Find if the block right clicked is an altar block, and then record which block it is to later determine boss summon.
  104. for i, block in altarBlocks {
  105. if (block has event.block) {
  106. currentAltar = block;
  107. break;
  108. }
  109. }
  110. // If block is found proceed, otherwise ignore.
  111. if (!isNull(currentAltar)) {
  112. // Record each hand's current items
  113. var mhItem = event.player.mainHandHeldItem;
  114. var ohItem = event.player.offHandHeldItem;
  115. // If the current held items are null, stop here.
  116. if (isNull(mhItem) && isNull(ohItem)){
  117. return;
  118. }
  119. // Check if the held item is in the spawnItems list and write which item it is to later determine properties about the boss, as well as write which hand the item was found in prioritizing the main hand.
  120. for i, item in spawnItems {
  121. if (!isNull(mhItem) && item has mhItem){
  122. currentItem = item;
  123. currentHand = "main";
  124. break;
  125. }
  126. if (!isNull(ohItem) && item has ohItem){
  127. currentItem = item;
  128. currentHand = "offhand";
  129. break;
  130. }
  131. }
  132. // If the currentItem isn't written and still null, then inform the player and stop here.
  133. if (isNull(currentItem)){
  134. event.player.sendMessage("The altar rejects your offering.");
  135. event.cancel();
  136. return;
  137. }
  138. // Erase the item from the correct hand if 1, and Subtract the item if greater than 1.
  139. if (currentHand == "main"){
  140. event.player.setItemToSlot(IEntityEquipmentSlot.mainHand(), mhItem.amount == 1 ? null : mhItem.withAmount(mhItem.amount - 1));
  141. event.player.sendMessage("The " + mhItem.displayName + " wrenches from your hand.");
  142. } else {
  143. event.player.setItemToSlot(IEntityEquipmentSlot.offhand(), ohItem.amount == 1 ? null : ohItem.withAmount(ohItem.amount - 1));
  144. event.player.sendMessage("The " + ohItem.displayName + " wrenches from your hand.");
  145. }
  146. // Perform boss summon here.
  147. var myBasicBoss = BasicBoss(event); // this is a function call to the constructor
  148. // myBasicBoss.spawnBoss();
  149. }
  150. });
  151.  
  152. print("Initialized 'boss_summoning'");
  153.  
Advertisement
Add Comment
Please, Sign In to add comment