Advertisement
Guest User

Untitled

a guest
Jul 27th, 2022
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.00 KB | None | 0 0
  1. package com.Leftmostchain21.scanner_ai.events;
  2.  
  3.  
  4. import com.Leftmostchain21.scanner_ai.scanner_ai;
  5. import net.minecraft.world.entity.Entity;
  6. import net.minecraft.world.item.ItemStack;
  7. import net.minecraft.world.phys.AABB;
  8. import net.minecraft.world.phys.Vec3;
  9. import net.minecraftforge.event.TickEvent;
  10. import net.minecraftforge.eventbus.api.SubscribeEvent;
  11. import net.minecraftforge.fml.common.Mod;
  12.  
  13. import java.util.List;
  14.  
  15. @Mod.EventBusSubscriber(modid = scanner_ai.MODID)
  16. public class ModEvents {
  17.  
  18.     @SubscribeEvent
  19.     public static <RayTraceResult> void getPositionOfPlayerToChat(TickEvent.PlayerTickEvent event) {
  20.         // Print time
  21.         System.out.println("============================================" + System.currentTimeMillis() + "========================================");
  22.         // Set the bounding box of the player
  23.         AABB playerBox = new AABB(event.player.getX() - 35, event.player.getY() - 25, event.player.getZ() - 35, event.player.getX() + 35, event.player.getY() + 25, event.player.getZ() + 35);
  24.         List<Entity> total_entities = event.player.level.getEntities(null, playerBox);
  25.         // Get player's health and send it to the chat
  26.         System.out.println("Player health is: " + event.player.getHealth());
  27.         // Get the player's location, and print it to the chat
  28.         System.out.println("Player is at: " + event.player.position());
  29.         // Get the player's looking direction, and print it to the chat. E.G. (0.73, -0.54)
  30.         System.out.println("Player is facing: " + event.player.getXRot() + ", " + event.player.getYRot());
  31.         // State the dimension they are in
  32.         System.out.println("Player is in dimension: " + event.player.level.dimension().location());
  33.         // State if the player is on fire
  34.         System.out.println("Player is on fire: " + event.player.isOnFire());
  35.         // State if the player is in water
  36.         System.out.println("Player is in water: " + event.player.isInWater());
  37.         // State if the player is in lava
  38.         System.out.println("Player is in lava: " + event.player.isInLava());
  39.         // State if the player is in the air
  40.         System.out.println("Player is in the air: " + event.player.isDescending());
  41.         // State if the player is crouched
  42.         System.out.println("Player is crouched: " + event.player.isCrouching());
  43.         // State if the player is sprinting
  44.         System.out.println("Player is sprinting: " + event.player.isSprinting());
  45.         // State if the player is flying
  46.         System.out.println("Player is flying: " + event.player.isFallFlying());
  47.         // State if the player is dead or dying
  48.         System.out.println("Player is dead or dying: " + event.player.isDeadOrDying());
  49.         // State if the player is freezing
  50.         System.out.println("Player is freezing: " + event.player.isFreezing());
  51.         try {
  52.             // State if the player is wearing any golden armor
  53.             Iterable<ItemStack> armor = event.player.getArmorSlots();
  54.             if (armor.toString().contains("GOLD")) {
  55.                 System.out.println("Player is wearing golden armor");
  56.             }
  57.         } catch (Exception e) {
  58.             System.out.println("Player is not wearing any golden armor");
  59.         }
  60.         try {
  61.             System.out.println("Selected armor: " + event.player.getArmorSlots());
  62.         } catch (Exception e) {
  63.             System.out.println("No armor");
  64.         }
  65.         // Loop through their inventory and print each item to the chat
  66.         for (int i = 0; i < 36; i++) {
  67.             try {
  68.                 ItemStack current_item = event.player.getSlot(i).get();
  69.                 if (!(current_item.getItem().toString().equals("air"))) {
  70.                     System.out.println("Item in slot " + i + ": " + current_item.getItem());
  71.                 }
  72.             } catch (Exception e) {
  73.                 System.out.println("No item in slot " + i);
  74.             }
  75.         }
  76.         // Now output all the entities in the world to the chat
  77.         System.out.println("Entities in the world: " + total_entities.size());
  78.  
  79.         // Get all the entities in the world
  80.         // First remove the player from the list of entities
  81.         total_entities.remove(event.player);
  82.         for (Entity entity : total_entities) {
  83.             // Get the Entity's location, and print it to the chat
  84.             System.out.println("Entity is at: " + entity.position());
  85.             // Get the Entity's looking direction, and print it to the chat. E.G. (0.73, -0.54)
  86.             System.out.println("Entity is facing: " + entity.getXRot() + ", " + entity.getYRot());
  87.             // State the dimension they are in
  88.             System.out.println("Entity is in dimension: " + entity.level.dimension().location());
  89.             // State if the Entity is on fire
  90.             System.out.println("Entity is on fire: " + entity.isOnFire());
  91.             // State if the Entity is in water
  92.             System.out.println("Entity is in water: " + entity.isInWater());
  93.             // State if the Entity is in lava
  94.             System.out.println("Entity is in lava: " + entity.isInLava());
  95.             // State if the Entity is in the air
  96.             System.out.println("Entity is in the air: " + entity.isDescending());
  97.             // State if the Entity is crouched
  98.             System.out.println("Entity is crouched: " + entity.isCrouching());
  99.             // State if the Entity is sprinting
  100.             System.out.println("Entity is sprinting: " + entity.isSprinting());
  101.             // State if the Entity is freezing
  102.             System.out.println("Entity is freezing: " + entity.isFreezing());
  103.             // Now print the distance between the player and the entity
  104.             System.out.println("Distance between player and entity: " + event.player.distanceTo(entity));
  105.             try {
  106.                 // Print the entity's selected slot to the chat
  107.                 System.out.println("Selected primary hand: " + entity.getHandSlots().iterator().next().getItem());
  108.                 // Print the entity's selected offhand slot to the chat
  109.                 System.out.println("Selected offhand hand: " + entity.getHandSlots());
  110.             } catch (Exception e) {
  111.                 System.out.println("No offhand hand");
  112.             }
  113.             // Print the entity's selected armor slot to the chat
  114.             try {
  115.                 System.out.println("Selected armor: " + entity.getArmorSlots());
  116.             } catch (Exception e) {
  117.                 System.out.println("No armor");
  118.             }
  119.             // Loop through their inventory and print each item to the chat
  120.             for (int i = 0; i < 36; i++) {
  121.                 try {
  122.                     ItemStack current_item = entity.getSlot(i).get();
  123.                     if (!(current_item.getItem().toString().equals("air"))) {
  124.                         System.out.println("Item in slot " + i + ": " + current_item.getItem());
  125.                     }
  126.                 } catch (Exception e) {
  127.                     System.out.println("No item in slot " + i);
  128.                 }
  129.             }
  130.         }
  131.         // Now print the blocks in the world to the chat
  132.         // The way this will work is by casting raycasts from the player to the world and printing the block that is hit
  133.         // First, create the raycasts
  134.         // Ray length
  135.         int ray_length = 50;
  136.         // Create the raycasts from the player's position to the world
  137.         // So loop 10 * 10 times
  138.         for (int i = -5; i < 5; i++) {
  139.             for (int j = -5; j < 5; j++) {
  140.                 // Find where the raycast will hit
  141.                 Vec3 applier = new Vec3(i, 0, j);
  142.                 Vec3 player_rotation = event.player.getViewVector(0).add(applier);
  143.                 Vec3 rayPath = player_rotation.scale(ray_length);
  144.  
  145.                 //RAY START AND END POINTS
  146.                 Vec3 from = event.player.getEyePosition(0);
  147.                 Vec3 to = from.add(rayPath);
  148.  
  149.                 //CREATE THE RAY AND GET THE BLOCKS IT HITS
  150.  
  151.  
  152.  
  153.             }
  154.         }
  155.     }
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement