GaryScripts

LapisProcedure

Dec 4th, 2021
826
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.mcreator.expandedpicks.procedures;
  2.  
  3. import net.minecraftforge.fml.common.Mod;
  4. import net.minecraftforge.eventbus.api.SubscribeEvent;
  5. import net.minecraftforge.event.world.BlockEvent;
  6.  
  7. import net.minecraft.world.World;
  8. import net.minecraft.world.IWorld;
  9. import net.minecraft.util.math.BlockPos;
  10. import net.minecraft.item.Items;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.entity.item.ItemEntity;
  13. import net.minecraft.entity.LivingEntity;
  14. import net.minecraft.entity.Entity;
  15. import net.minecraft.block.Blocks;
  16.  
  17. import net.mcreator.expandedpicks.item.LapisPickaxeItem;
  18. import net.mcreator.expandedpicks.ExpandedPicksMod;
  19.  
  20. import java.util.Map;
  21. import java.util.HashMap;
  22.  
  23. public class LapisPickaxeBlockDestroyedWithToolProcedure {
  24.     @Mod.EventBusSubscriber
  25.     private static class GlobalTrigger {
  26.         @SubscribeEvent
  27.         public static void onBlockBreak(BlockEvent.BreakEvent event) {
  28.             Entity entity = event.getPlayer();
  29.             IWorld world = event.getWorld();
  30.             Map<String, Object> dependencies = new HashMap<>();
  31.             dependencies.put("xpAmount", event.getExpToDrop());
  32.             dependencies.put("x", event.getPos().getX());
  33.             dependencies.put("y", event.getPos().getY());
  34.             dependencies.put("z", event.getPos().getZ());
  35.             dependencies.put("px", entity.getPosX());
  36.             dependencies.put("py", entity.getPosY());
  37.             dependencies.put("pz", entity.getPosZ());
  38.             dependencies.put("world", world);
  39.             dependencies.put("entity", entity);
  40.             dependencies.put("blockstate", event.getState());
  41.             dependencies.put("event", event);
  42.             executeProcedure(dependencies);
  43.         }
  44.     }
  45.     public static void executeProcedure(Map<String, Object> dependencies) {
  46.         if (dependencies.get("entity") == null) {
  47.             if (!dependencies.containsKey("entity"))
  48.                 ExpandedPicksMod.LOGGER.warn("Failed to load dependency entity for procedure LapisPickaxeBlockDestroyedWithTool!");
  49.             return;
  50.         }
  51.         if (dependencies.get("x") == null) {
  52.             if (!dependencies.containsKey("x"))
  53.                 ExpandedPicksMod.LOGGER.warn("Failed to load dependency x for procedure LapisPickaxeBlockDestroyedWithTool!");
  54.             return;
  55.         }
  56.         if (dependencies.get("y") == null) {
  57.             if (!dependencies.containsKey("y"))
  58.                 ExpandedPicksMod.LOGGER.warn("Failed to load dependency y for procedure LapisPickaxeBlockDestroyedWithTool!");
  59.             return;
  60.         }
  61.         if (dependencies.get("z") == null) {
  62.             if (!dependencies.containsKey("z"))
  63.                 ExpandedPicksMod.LOGGER.warn("Failed to load dependency z for procedure LapisPickaxeBlockDestroyedWithTool!");
  64.             return;
  65.         }
  66.         if (dependencies.get("world") == null) {
  67.             if (!dependencies.containsKey("world"))
  68.                 ExpandedPicksMod.LOGGER.warn("Failed to load dependency world for procedure LapisPickaxeBlockDestroyedWithTool!");
  69.             return;
  70.         }
  71.         Entity entity = (Entity) dependencies.get("entity");
  72.         double x = dependencies.get("x") instanceof Integer ? (int) dependencies.get("x") : (double) dependencies.get("x");
  73.         double y = dependencies.get("y") instanceof Integer ? (int) dependencies.get("y") : (double) dependencies.get("y");
  74.         double z = dependencies.get("z") instanceof Integer ? (int) dependencies.get("z") : (double) dependencies.get("z");
  75.         IWorld world = (IWorld) dependencies.get("world");
  76.         if ((((world.getBlockState(new BlockPos((int) x, (int) y, (int) z))).getBlock() == Blocks.STONE)
  77.                 && (((entity instanceof LivingEntity) ? ((LivingEntity) entity).getHeldItemMainhand() : ItemStack.EMPTY)
  78.                         .getItem() == LapisPickaxeItem.block))) {
  79.             if ((Math.random() <= 0.25)) {
  80.                 for (int index0 = 0; index0 < (int) (2); index0++) {
  81.                     if (world instanceof World && !world.isRemote()) {
  82.                         ItemEntity entityToSpawn = new ItemEntity((World) world, x, y, z, new ItemStack(Items.LAPIS_LAZULI));
  83.                         entityToSpawn.setPickupDelay((int) 10);
  84.                         entityToSpawn.setNoDespawn();
  85.                         world.addEntity(entityToSpawn);
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.     }
  91. }
  92.  
RAW Paste Data