BrennoMaturino1

Untitled

May 4th, 2021
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. package mob.transporter;
  2.  
  3. import net.minecraft.client.MinecraftClient;
  4. import net.minecraft.entity.Entity;
  5. import net.minecraft.entity.player.PlayerEntity;
  6. import net.minecraft.item.Item;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.nbt.CompoundTag;
  9. import net.minecraft.util.Hand;
  10. import net.minecraft.util.TypedActionResult;
  11. import net.minecraft.util.hit.BlockHitResult;
  12. import net.minecraft.util.hit.EntityHitResult;
  13. import net.minecraft.util.hit.HitResult;
  14. import net.minecraft.util.math.BlockPos;
  15. import net.minecraft.util.math.Vec3d;
  16. import net.minecraft.world.World;
  17. import net.minecraft.util.hit.HitResult.Type;
  18.  
  19. public class FabricItem extends Item {
  20.  
  21. public FabricItem(Settings settings) {
  22. super(settings);
  23. }
  24.  
  25. @Override
  26. public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand)
  27. {
  28. ItemStack mainHand = playerEntity.inventory.getMainHandStack();
  29. CompoundTag tag = mainHand.getTag();
  30. EntityHitResult entityHit;
  31. Entity entity;
  32. MinecraftClient client = MinecraftClient.getInstance();
  33. HitResult hit = client.crosshairTarget;
  34. BlockPos blockPos;
  35. CompoundTag entityCTag = null;
  36.  
  37. if (mainHand.getTag() == null)
  38. {
  39. CompoundTag newTag = mainHand.getOrCreateTag();
  40. newTag.putBoolean("hasEntity", false);
  41. newTag.put("entityTag", entityCTag);
  42. }
  43.  
  44. if (hit.getType() == Type.ENTITY)
  45. {
  46. entityHit = (EntityHitResult) hit;
  47. entity = entityHit.getEntity();
  48. if (tag.getBoolean("hasEntity") == false)
  49. {
  50.  
  51. entityCTag = new CompoundTag();
  52. entity.saveSelfToTag(entityCTag);
  53. entityCTag.remove("Pos");
  54. entity.remove();
  55.  
  56. }
  57. else if (hit.getType() == Type.BLOCK)
  58. {
  59. BlockHitResult blockHit = (BlockHitResult) hit;
  60. blockPos = blockHit.getBlockPos();
  61. //BlockState blockState = client.world.getBlockState(blockPos);
  62. //Block block = blockState.getBlock();
  63. // i dont need these
  64.  
  65. if (tag.getBoolean("hasEntity") == true)
  66. {
  67. if (entityCTag != null)
  68. {
  69. Vec3d SummonVec = new Vec3d(blockPos.getX(), blockPos.getY(), blockPos.getZ());
  70. Transporter.summon(tag.getCompound("entityTag"), world, SummonVec);
  71. tag.putBoolean("hasEntity", true);
  72. }
  73. }
  74. }
  75. }
  76. return TypedActionResult.success(playerEntity.getStackInHand(hand));
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment