Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DeadBodyEntity extends LivingEntity implements GeoEntity {
- protected static final RawAnimation DEATH = RawAnimation.begin().thenPlayAndHold("death");
- private final AnimatableInstanceCache geoCache = GeckoLibUtil.createInstanceCache(this);
- private static final TrackedData<String> BUTCHERY_TYPE = DataTracker.registerData(DeadBodyEntity.class, TrackedDataHandlerRegistry.STRING);
- private static final TrackedData<Integer> AGE = DataTracker.registerData(DeadBodyEntity.class, TrackedDataHandlerRegistry.INTEGER);
- private final DefaultedList<ItemStack> armorItems = DefaultedList.ofSize(4, ItemStack.EMPTY);
- public DeadBodyEntity(EntityType<? extends LivingEntity> entityType, World world) {
- super(entityType, world);
- }
- @Override
- public Box getVisibilityBoundingBox() {
- return super.getVisibilityBoundingBox();
- }
- @Override
- public ActionResult interact(PlayerEntity player, Hand hand) {
- if(player.getMainHandStack().isEmpty() && player.getOffHandStack().isEmpty()) {
- DnGEntityComponent component = DnGComponents.DNG_ENTITY_KEY.get(player);
- if(!component.isCarrying()) {
- component.setCarrying(this.getButcheryType());
- }
- }
- if(player.getStackInHand(hand).isIn(DnGTags.CLEAVERS)) {
- this.remove(RemovalReason.DISCARDED);
- // player.giveItemStack(new ItemStack(ModItems.BONE_MARROW));
- }
- return super.interact(player, hand);
- }
- @Override
- public boolean damage(DamageSource source, float amount) {
- Entity attacker = source.getAttacker();
- if (attacker != null && !source.isIn(DamageTypeTags.NO_KNOCKBACK)) {
- double d = attacker.getX() - this.getX();
- double e = attacker.getZ() - this.getZ();
- while (d * d + e * e < 1.0E-4) {
- d = (Math.random() - Math.random()) * 0.01;
- e = (Math.random() - Math.random()) * 0.01;
- }
- this.takeKnockback(0.1f, d, e);
- }
- return false;
- }
- @Override
- public void tick() {
- super.tick();
- this.addAge(1);
- // This is so it despawns after 10 minutes TODO Change despawn System
- if(this.getAge() >= 12000) {
- this.remove(RemovalReason.DISCARDED);
- }
- }
- @Override
- public Arm getMainArm() {
- return null;
- }
- @Override
- protected void initDataTracker(DataTracker.Builder builder) {
- super.initDataTracker(builder);
- builder.add(BUTCHERY_TYPE,"");
- builder.add(AGE,0);
- }
- @Override
- public void readCustomDataFromNbt(NbtCompound nbt) {
- if(nbt.contains("ButcheryType")) {
- this.setButcheryType(nbt.getString("ButcheryType"));
- }
- if(nbt.contains("Age")) {
- this.setAge(nbt.getInt("Age"));
- }
- }
- @Override
- public void writeCustomDataToNbt(NbtCompound nbt) {
- if (!this.getButcheryType().isEmpty()) {
- nbt.putString("ButcheryType", this.getButcheryType());
- }
- nbt.putInt("Age", this.getAge());
- }
- public void setButcheryType(String name) {
- this.getDataTracker().set(BUTCHERY_TYPE, name);
- }
- public String getButcheryType() {
- return this.getDataTracker().get(BUTCHERY_TYPE);
- }
- public void setAge(int age) {
- this.getDataTracker().set(AGE,age);
- }
- public void addAge(int age) {
- this.dataTracker.set(AGE,this.getAge() + age);
- }
- public int getAge() {
- return this.dataTracker.get(AGE);
- }
- @Override
- public void registerControllers(AnimatableManager.ControllerRegistrar controllers) {
- controllers.add(deathPredicate(this));
- }
- public <T extends GeoAnimatable> AnimationController<T> deathPredicate(T animatable) {
- return new AnimationController<T>(animatable,
- "death",
- 0,
- state -> state.setAndContinue(DEATH));
- }
- @Override
- public AnimatableInstanceCache getAnimatableInstanceCache() {
- return this.geoCache;
- }
- @Override
- public Iterable<ItemStack> getArmorItems() {
- return this.armorItems;
- }
- @Override
- public ItemStack getEquippedStack(EquipmentSlot slot) {
- return ItemStack.EMPTY;
- }
- @Override
- public void equipStack(EquipmentSlot slot, ItemStack stack) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement