Advertisement
Guest User

Untitled

a guest
Apr 15th, 2022
9
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package net.redman.sorcererking.common.entities;
  2.  
  3. import net.minecraft.entity.*;
  4. import net.minecraft.entity.projectile.DamagingProjectileEntity;
  5. import net.minecraft.entity.projectile.ProjectileItemEntity;
  6. import net.minecraft.network.datasync.DataParameter;
  7. import net.minecraft.network.datasync.DataSerializers;
  8. import net.minecraft.network.datasync.EntityDataManager;
  9. import net.minecraft.util.DamageSource;
  10. import net.minecraft.util.Direction;
  11. import net.minecraft.util.math.*;
  12. import net.minecraft.util.math.vector.Vector2f;
  13. import net.minecraft.util.math.vector.Vector3d;
  14. import net.minecraft.world.World;
  15.  
  16. import javax.annotation.Nullable;
  17.  
  18. public class MagicArrowEntity extends DamagingProjectileEntity {
  19. private static final DataParameter<Integer> ID_SIZE = EntityDataManager.defineId(MagicArrowEntity.class, DataSerializers.INT);
  20.  
  21. public MagicArrowEntity(EntityType<? extends MagicArrowEntity> type, World world){
  22. super(type, world);
  23. this.setNoGravity(true);
  24. }
  25.  
  26. public MagicArrowEntity(LivingEntity caster, World world, int scale){
  27. this(world, caster.getX(), caster.getEyeY() - 0.10000000149011612D, caster.getZ(), scale);
  28. }
  29.  
  30. public MagicArrowEntity(EntityType<? extends MagicArrowEntity> entityType, World world, LivingEntity caster){
  31. this(entityType, world);
  32. }
  33.  
  34. public MagicArrowEntity(World world, double x, double y, double z, int scale) {
  35. super((EntityType)ModEntities.MAGIC_ARROW_ENTITY.get(),world);
  36. this.setPos(x,y,z);
  37. System.out.println("dims: "+ this.getType().getDimensions());
  38. System.out.println("Bb0 : "+this.getBoundingBox());
  39. this.setNoGravity(true);
  40. this.setSize(scale);
  41.  
  42. // this.setBoundingBox(this.getBoundingBox().inflate(scale));
  43. }
  44.  
  45. public void shoot(@Nullable Entity caster, Vector3d look, float velocity, float inaccuracy){
  46. this.shoot(look.get(Direction.Axis.X), look.get(Direction.Axis.Y), look.get(Direction.Axis.Z), velocity, inaccuracy);
  47. }
  48.  
  49.  
  50.  
  51. @Override
  52. public void shoot(double x, double y, double z, float velocity, float inaccuracy) {
  53. System.out.println("dims1: "+ this.getType().getDimensions());
  54. System.out.println("BB1 : "+this.getBoundingBox());
  55.  
  56. //System.out.println("dims : "+this.getType().getDimensions());
  57. Vector3d Vector3d = (new Vector3d(x,y,z).normalize().scale((double) velocity));
  58. this.setDeltaMovement(Vector3d);
  59. float f = MathHelper.sqrt(getHorizontalDistanceSqr(Vector3d));
  60.  
  61. this.yRot = (float)(MathHelper.atan2(Vector3d.x,Vector3d.z)*57.2957763671875D);
  62. this.xRot = (float)(MathHelper.atan2(Vector3d.y, (double)f)*57.2957763671875D);
  63. this.xRotO = xRot;
  64. this.yRotO = yRot;
  65. }
  66.  
  67. @Override
  68. public void onSyncedDataUpdated(DataParameter<?> parameter) {
  69. if(ID_SIZE.equals(parameter)){
  70. this.refreshDimensions();
  71. }
  72. super.onSyncedDataUpdated(parameter);
  73. }
  74.  
  75. @Override
  76. protected void defineSynchedData() {
  77. super.defineSynchedData();
  78. this.entityData.define(ID_SIZE, 1);
  79. }
  80.  
  81. @Override
  82. public EntitySize getDimensions(Pose pose) {
  83. return super.getDimensions(pose).scale(0.255f*(float)this.getSize());
  84. }
  85.  
  86. private void setSize(int size ){
  87. this.entityData.set(ID_SIZE, size);
  88. this.reapplyPosition();
  89. this.refreshDimensions();
  90. }
  91.  
  92. private int getSize() {
  93. return this.entityData.get(ID_SIZE);
  94. }
  95.  
  96. private EntitySize scale(float s){
  97. EntitySize size = this.getType().getDimensions().scale(s);
  98. System.out.println("dims scale : "+size);
  99. return size;
  100. }
Advertisement
RAW Paste Data Copied
Advertisement