Advertisement
Guest User

Untitled

a guest
Apr 15th, 2022
7
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.nbt.CompoundNBT;
  7. import net.minecraft.network.datasync.DataParameter;
  8. import net.minecraft.network.datasync.DataSerializers;
  9. import net.minecraft.network.datasync.EntityDataManager;
  10. import net.minecraft.util.DamageSource;
  11. import net.minecraft.util.Direction;
  12. import net.minecraft.util.math.*;
  13. import net.minecraft.util.math.vector.Vector2f;
  14. import net.minecraft.util.math.vector.Vector3d;
  15. import net.minecraft.world.World;
  16.  
  17. import javax.annotation.Nullable;
  18.  
  19. public class MagicArrowEntity extends DamagingProjectileEntity {
  20. private static final DataParameter<Integer> ID_SIZE = EntityDataManager.defineId(MagicArrowEntity.class, DataSerializers.INT);
  21.  
  22. public MagicArrowEntity(EntityType<? extends MagicArrowEntity> type, World world){
  23. super(type, world);
  24. this.setNoGravity(true);
  25. }
  26.  
  27. public MagicArrowEntity(LivingEntity caster, World world, int scale){
  28. this(world, caster.getX(), caster.getEyeY() - 0.10000000149011612D, caster.getZ(), scale);
  29. }
  30.  
  31. public MagicArrowEntity(EntityType<? extends MagicArrowEntity> entityType, World world, LivingEntity caster){
  32. this(entityType, world);
  33. }
  34.  
  35. public MagicArrowEntity(World world, double x, double y, double z, int scale) {
  36. super((EntityType)ModEntities.MAGIC_ARROW_ENTITY.get(),world);
  37. this.setPos(x,y,z);
  38. System.out.println("dims: "+ this.getType().getDimensions());
  39. System.out.println("Bb0 : "+this.getBoundingBox());
  40. this.setNoGravity(true);
  41. this.setSize(scale);
  42.  
  43. // this.setBoundingBox(this.getBoundingBox().inflate(scale));
  44. }
  45.  
  46. public void shoot(@Nullable Entity caster, Vector3d look, float velocity, float inaccuracy){
  47. this.shoot(look.get(Direction.Axis.X), look.get(Direction.Axis.Y), look.get(Direction.Axis.Z), velocity, inaccuracy);
  48. }
  49.  
  50.  
  51.  
  52. @Override
  53. public void shoot(double x, double y, double z, float velocity, float inaccuracy) {
  54. System.out.println("dims1: "+ this.getType().getDimensions());
  55. System.out.println("BB1 : "+this.getBoundingBox());
  56.  
  57. //System.out.println("dims : "+this.getType().getDimensions());
  58. Vector3d Vector3d = (new Vector3d(x,y,z).normalize().scale((double) velocity));
  59. this.setDeltaMovement(Vector3d);
  60. float f = MathHelper.sqrt(getHorizontalDistanceSqr(Vector3d));
  61.  
  62. this.yRot = (float)(MathHelper.atan2(Vector3d.x,Vector3d.z)*57.2957763671875D);
  63. this.xRot = (float)(MathHelper.atan2(Vector3d.y, (double)f)*57.2957763671875D);
  64. this.xRotO = xRot;
  65. this.yRotO = yRot;
  66. }
  67.  
  68. @Override
  69. public void onSyncedDataUpdated(DataParameter<?> parameter) {
  70. System.out.println("DataUpdated");
  71. if(ID_SIZE.equals(parameter)){
  72. this.refreshDimensions();
  73. }
  74. super.onSyncedDataUpdated(parameter);
  75. }
  76.  
  77. @Override
  78. protected void defineSynchedData() {
  79. System.out.println("defineData");
  80. super.defineSynchedData();
  81. this.entityData.define(ID_SIZE, 1);
  82. }
  83.  
  84. @Override
  85. public EntitySize getDimensions(Pose pose) {
  86. System.out.println("get dims");
  87. return super.getDimensions(pose).scale(0.255f*(float)this.getSize());
  88. }
  89.  
  90. private void setSize(int size ){
  91. this.entityData.set(ID_SIZE, size);
  92. this.reapplyPosition();
  93. this.refreshDimensions();
  94. }
  95.  
  96. private int getSize() {
  97. return this.entityData.get(ID_SIZE);
  98. }
  99.  
  100. @Override
  101. public void addAdditionalSaveData(CompoundNBT nbt) {
  102. super.addAdditionalSaveData(nbt);
  103. nbt.putInt("Size", this.getSize()-1);
  104. }
  105.  
  106. @Override
  107. public void readAdditionalSaveData(CompoundNBT nbt) {
  108. int i = nbt.getInt("Size");
  109. if(i <0){i=0;}
  110. this.setSize(i+1);
  111. super.readAdditionalSaveData(nbt);
  112. }
  113.  
  114. private EntitySize scale(float s){
  115. EntitySize size = this.getType().getDimensions().scale(s);
  116. System.out.println("dims scale : "+size);
  117. return size;
  118. }
  119. @Override
  120. protected void onHit(RayTraceResult rayTraceResult) {
  121. System.out.println("magic arrow hit");
  122. System.out.println(rayTraceResult.getLocation().x +", " + rayTraceResult.getLocation().y +"," +rayTraceResult.getLocation().z);
  123. RayTraceResult.Type rayTraceResult$Type = rayTraceResult.getType();
  124. if(rayTraceResult$Type == RayTraceResult.Type.ENTITY){
  125. System.out.println("magic arrow hit entity");
  126. this.onHitEntity((EntityRayTraceResult) rayTraceResult);
  127. System.out.println("magic arrow affected entity entity");
  128. }else if(rayTraceResult$Type == RayTraceResult.Type.BLOCK){
  129. System.out.println("magic arrow hit block");
  130. BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult)rayTraceResult;
  131. this.blockHit(blockRayTraceResult.getBlockPos(), blockRayTraceResult.getDirection());
  132. System.out.println("magic arrow affected block");
  133. }
  134. if(!this.level.isClientSide()){
  135. this.remove();
  136. }
  137. }
  138.  
  139.  
  140.  
  141.  
  142. @Override
  143. protected void onHitEntity(EntityRayTraceResult entityRayTraceResult) {
  144. Entity entity = entityRayTraceResult.getEntity();
  145. if(entity instanceof LivingEntity){
  146. this.entityHit((LivingEntity)entity);
  147. }
  148. }
  149.  
  150. private void entityHit(LivingEntity entity) {
  151. entity.kill();
  152. }
  153.  
  154. private void blockHit(BlockPos blockPos, Direction direction) {
  155. this.applyEffect(blockPos, direction, (Entity)null);
  156.  
  157. }
  158.  
  159. private void applyEffect(BlockPos blockPos, Direction direction, Entity entity) {
  160. if(entity != null){
  161.  
  162. }
  163. }
  164. }
  165.  
Advertisement
RAW Paste Data Copied
Advertisement