Advertisement
GeradesoLukas

Untitled

May 30th, 2024
629
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.50 KB | None | 0 0
  1.  
  2. public class DeadBodyEntity extends LivingEntity implements GeoEntity {
  3.     protected static final RawAnimation DEATH = RawAnimation.begin().thenPlayAndHold("death");
  4.     private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);
  5.     private static final TrackedData<String> BUTCHERY_TYPE = DataTracker.registerData(DeadBodyEntity.class, TrackedDataHandlerRegistry.STRING);
  6.     private static final TrackedData<Integer> AGE = DataTracker.registerData(DeadBodyEntity.class, TrackedDataHandlerRegistry.INTEGER);
  7.     private final DefaultedList<ItemStack> armorItems = DefaultedList.ofSize(4, ItemStack.EMPTY);
  8.  
  9.  
  10.  
  11.     public DeadBodyEntity(EntityType<? extends LivingEntity> entityType, World world) {
  12.         super(entityType, world);
  13.     }
  14.  
  15.  
  16.     @Override
  17.     public Box getVisibilityBoundingBox() {
  18.         return super.getVisibilityBoundingBox();
  19.     }
  20.  
  21.     @Override
  22.     public ActionResult interact(PlayerEntity player, Hand hand) {
  23.         if(player.getMainHandStack().isEmpty() && player.getOffHandStack().isEmpty()) {
  24.             DnGEntityComponent component = DnGComponents.DNG_ENTITY_KEY.get(player);
  25.             if(!component.isCarrying()) {
  26.                 component.setCarrying(this.getButcheryType());
  27.             }
  28.         }
  29.  
  30.         if(player.getStackInHand(hand).isIn(DnGTags.CLEAVERS)) {
  31.             this.remove(RemovalReason.DISCARDED);
  32. //            player.giveItemStack(new ItemStack(ModItems.BONE_MARROW));
  33.         }
  34.         return super.interact(player, hand);
  35.     }
  36.  
  37.     @Override
  38.     public boolean damage(DamageSource source, float amount) {
  39.         Entity attacker = source.getAttacker();
  40.         if (attacker != null && !source.isIn(DamageTypeTags.NO_KNOCKBACK)) {
  41.             double d = attacker.getX() - this.getX();
  42.             double e = attacker.getZ() - this.getZ();
  43.             while (d * d + e * e < 1.0E-4) {
  44.                 d = (Math.random() - Math.random()) * 0.01;
  45.                 e = (Math.random() - Math.random()) * 0.01;
  46.             }
  47.             this.takeKnockback(0.1f, d, e);
  48.         }
  49.         return false;
  50.     }
  51.  
  52.     @Override
  53.     public void tick() {
  54.         super.tick();
  55.         this.addAge(1);
  56.  
  57.         // This is so it despawns after 10 minutes TODO Change despawn System
  58.         if(this.getAge() >= 12000) {
  59.             this.remove(RemovalReason.DISCARDED);
  60.         }
  61.  
  62.  
  63.     }
  64.  
  65.     @Override
  66.     public Arm getMainArm() {
  67.         return null;
  68.     }
  69.  
  70.  
  71.     @Override
  72.     protected void initDataTracker(DataTracker.Builder builder) {
  73.         super.initDataTracker(builder);
  74.         builder.add(BUTCHERY_TYPE,"");
  75.         builder.add(AGE,0);
  76.     }
  77.  
  78.     @Override
  79.     public void readCustomDataFromNbt(NbtCompound nbt) {
  80.         if(nbt.contains("ButcheryType")) {
  81.             this.setButcheryType(nbt.getString("ButcheryType"));
  82.         }
  83.         if(nbt.contains("Age")) {
  84.             this.setAge(nbt.getInt("Age"));
  85.         }
  86.     }
  87.  
  88.  
  89.  
  90.     @Override
  91.     public void writeCustomDataToNbt(NbtCompound nbt) {
  92.         if (!this.getButcheryType().isEmpty()) {
  93.             nbt.putString("ButcheryType", this.getButcheryType());
  94.         }
  95.         nbt.putInt("Age", this.getAge());
  96.     }
  97.  
  98.     public void setButcheryType(String name) {
  99.         this.getDataTracker().set(BUTCHERY_TYPE, name);
  100.     }
  101.  
  102.     public String getButcheryType() {
  103.         return this.getDataTracker().get(BUTCHERY_TYPE);
  104.     }
  105.  
  106.     public void setAge(int age) {
  107.         this.getDataTracker().set(AGE,age);
  108.     }
  109.  
  110.     public void addAge(int age) {
  111.         this.dataTracker.set(AGE,this.getAge() + age);
  112.     }
  113.  
  114.     public int getAge() {
  115.         return this.dataTracker.get(AGE);
  116.     }
  117.  
  118.     @Override
  119.     public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
  120.         controllers.add(deathPredicate(this));
  121.     }
  122.  
  123.     public <T extends GeoAnimatable> AnimationController<T> deathPredicate(T animatable) {
  124.         return new AnimationController<T>(animatable,
  125.                 "death",
  126.                 0,
  127.                 state -> state.setAndContinue(DEATH));
  128.     }
  129.  
  130.  
  131.  
  132.     @Override
  133.     public AnimatableInstanceCache getAnimatableInstanceCache() {
  134.         return this.geoCache;
  135.     }
  136.  
  137.     @Override
  138.     public Iterable<ItemStack> getArmorItems() {
  139.         return this.armorItems;
  140.     }
  141.  
  142.     @Override
  143.     public ItemStack getEquippedStack(EquipmentSlot slot) {
  144.         return ItemStack.EMPTY;
  145.     }
  146.  
  147.     @Override
  148.     public void equipStack(EquipmentSlot slot, ItemStack stack) {
  149.  
  150.     }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement