Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.examplemod.entity;
- import com.example.examplemod.custom.CustomBreakBlockGoal;
- import com.example.examplemod.custom.CustomSitGoal;
- import net.minecraft.block.Blocks;
- import net.minecraft.entity.*;
- import net.minecraft.entity.ai.attributes.AttributeModifierMap;
- import net.minecraft.entity.ai.attributes.Attributes;
- import net.minecraft.entity.ai.goal.*;
- import net.minecraft.entity.passive.TameableEntity;
- import net.minecraft.entity.player.PlayerEntity;
- import net.minecraft.network.datasync.DataParameter;
- import net.minecraft.network.datasync.DataSerializers;
- import net.minecraft.network.datasync.EntityDataManager;
- import net.minecraft.util.ActionResultType;
- import net.minecraft.util.Hand;
- import net.minecraft.util.SoundCategory;
- import net.minecraft.util.SoundEvents;
- import net.minecraft.util.math.BlockPos;
- import net.minecraft.util.math.vector.Vector3d;
- import net.minecraft.world.IWorld;
- import net.minecraft.world.World;
- import net.minecraft.world.server.ServerWorld;
- import software.bernie.geckolib3.core.IAnimatable;
- import software.bernie.geckolib3.core.PlayState;
- import software.bernie.geckolib3.core.builder.AnimationBuilder;
- import software.bernie.geckolib3.core.controller.AnimationController;
- import software.bernie.geckolib3.core.event.predicate.AnimationEvent;
- import software.bernie.geckolib3.core.manager.AnimationData;
- import software.bernie.geckolib3.core.manager.AnimationFactory;
- import javax.annotation.Nullable;
- public class TestEntity extends TameableEntity implements IAnimatable {
- private AnimationFactory factory = new AnimationFactory(this);
- public boolean flag = false;
- public TestEntity(EntityType<? extends TameableEntity> type, World worldIn)
- {
- super(type, worldIn);
- this.enablePersistence();
- this.setHealth(this.getMaxHealth());
- this.getNavigator().setCanSwim(true);
- this.recalculateSize();
- this.ignoreFrustumCheck = true;
- }
- public static AttributeModifierMap.MutableAttribute getAttributes() {
- return MobEntity.func_233666_p_()
- .createMutableAttribute(Attributes.MAX_HEALTH, 100.0D)
- .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.4D);
- }
- @Override
- public ActionResultType func_230254_b_(PlayerEntity player, Hand hand) {
- ActionResultType result = super.func_230254_b_(player, hand);
- if(player.world.isRemote){
- if(hand == Hand.MAIN_HAND){
- flag = !flag;
- result = ActionResultType.SUCCESS;
- }
- }
- return result;
- }
- @Override
- protected void registerGoals() {
- this.goalSelector.addGoal(1, new SwimGoal(this));
- this.goalSelector.addGoal(2, new CustomSitGoal(this));
- this.goalSelector.addGoal(3, new AttackHive(this, 0.6D, 3));
- this.goalSelector.addGoal(4, new WaterAvoidingRandomWalkingGoal(this, 0.4D));
- this.goalSelector.addGoal(5, new LookRandomlyGoal(this));
- this.goalSelector.addGoal(6, new PanicGoal(this, 0.6D));
- }
- private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
- if(flag){
- event.getController().setAnimation(new AnimationBuilder().addAnimation("seating", true));
- } else {
- if (!(event.getLimbSwingAmount() > -0.15F && event.getLimbSwingAmount() < 0.15F)){
- event.getController().setAnimation(new AnimationBuilder().addAnimation("walk", true));
- }
- else {
- event.getController().setAnimation(new AnimationBuilder().addAnimation("idle", true));
- }
- }
- return PlayState.CONTINUE;
- }
- @Override
- public void registerControllers(AnimationData data)
- {
- data.addAnimationController(new AnimationController(this, "controller", 0, this::predicate));
- }
- @Override
- public AnimationFactory getFactory()
- {
- return this.factory;
- }
- @Nullable
- @Override
- public AgeableEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) {
- return null;
- }
- class AttackHive extends CustomBreakBlockGoal {
- AttackHive(CreatureEntity creatureIn, double speed, int yMax) {
- super(Blocks.BEEHIVE, creatureIn, speed, yMax);
- }
- public void playBreakingSound(IWorld worldIn, BlockPos pos) {
- worldIn.playSound((PlayerEntity)null, pos, SoundEvents.ENTITY_ZOMBIE_DESTROY_EGG, SoundCategory.HOSTILE, 0.5F, 0.9F + TestEntity.this.rand.nextFloat() * 0.2F);
- }
- public void playBrokenSound(World worldIn, BlockPos pos) {
- worldIn.playSound((PlayerEntity)null, pos, SoundEvents.ENTITY_TURTLE_EGG_BREAK, SoundCategory.BLOCKS, 0.7F, 0.9F + worldIn.rand.nextFloat() * 0.2F);
- }
- public double getTargetDistanceSq() {
- return 1.6D;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement