Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Test mob class made for testing the logic of the DwellerEntity mob.
- *
- */
- public class BoxEntity extends PathfinderMob implements IAnimatable, VibrationListener.VibrationListenerConfig {
- private AnimationFactory animationFactory = new AnimationFactory(this);
- private final DynamicGameEventListener<VibrationListener> dynamicGameEventListener;
- public static final EntityDataAccessor<Boolean> SYNC_DATA = SynchedEntityData.defineId(BoxEntity.class, EntityDataSerializers.BOOLEAN);
- private Rotation rot;
- private boolean angry = false;
- public static AttributeSupplier setAttributes() {
- return Monster.createMobAttributes()
- .add(Attributes.MAX_HEALTH, 30.0D)
- .add(Attributes.MOVEMENT_SPEED, 0.3f)
- .add(Attributes.FOLLOW_RANGE, 12.0D)
- .add(Attributes.ATTACK_DAMAGE, 5.0f)
- .add(Attributes.ATTACK_KNOCKBACK, 0.3f)
- .build();
- }
- public BoxEntity(EntityType<? extends PathfinderMob> pEntityType, Level pLevel) {
- super(pEntityType, pLevel);
- this.dynamicGameEventListener = new DynamicGameEventListener<>(new VibrationListener(new EntityPositionSource(this, this.getEyeHeight()), 10, this, (VibrationListener.ReceivingEvent)null, 0.0F, 0));
- this.setPathfindingMalus(BlockPathTypes.WATER, -1.0F);
- this.setPathfindingMalus(BlockPathTypes.DAMAGE_FIRE, -1.0F);
- this.xpReward = 3;
- }
- protected void registerGoals() {
- this.goalSelector.addGoal(4, new LookAtPlayerGoal(this, Player.class, 20));
- this.goalSelector.addGoal(1, new MeleeAttackGoal(this, 1.0f, false));
- this.goalSelector.addGoal(4, new RandomLookAroundGoal(this));
- this.goalSelector.addGoal(3, new WaterAvoidingRandomStrollGoal(this, 1.0f, 0.0f));
- this.goalSelector.addGoal(0, new LeapAtTargetGoal(this, 0.3f));
- this.targetSelector.addGoal(0, new HurtByTargetGoal(this));
- }
- public void tick() {
- Level level = this.level;
- if (level instanceof ServerLevel serverlevel) {
- this.dynamicGameEventListener.getListener().tick(serverlevel);
- }
- if (this.getTarget() == null) {
- angry = false;
- }
- else angry = true;
- this.setClimbing(this.horizontalCollision);
- super.tick();
- }
- private <E extends IAnimatable> PlayState attackPredicate(AnimationEvent event) {
- if (this.swinging && event.getController().getAnimationState().equals(AnimationState.Stopped)) {
- event.getController().markNeedsReload();
- event.getController().setAnimation(new AnimationBuilder()
- .addAnimation("animation.box.attack", false));
- this.swinging = false;
- }
- return PlayState.CONTINUE;
- }
- private <E extends IAnimatable> PlayState predicate(AnimationEvent<E> event) {
- if (event.isMoving()) {
- event.getController().setAnimation(new AnimationBuilder()
- .addAnimation("animation.box.walk", true));
- return PlayState.CONTINUE;
- }
- event.getController().setAnimation(new AnimationBuilder()
- .addAnimation("animation.box.idle", true));
- return PlayState.CONTINUE;
- }
- @Override
- public boolean isPushable() {
- return true;
- }
- @Override
- public void registerControllers(AnimationData data) {
- data.addAnimationController(new AnimationController(this, "controller",
- 0, this::predicate));
- data.addAnimationController(new AnimationController(this, "attackController",
- 0, this::attackPredicate));
- }
- public TagKey<GameEvent> getListenableEvents() {
- return GameEventTags.WARDEN_CAN_LISTEN;
- }
- @Override
- public AnimationFactory getFactory() {
- return this.animationFactory;
- }
- protected void playStepSound(BlockPos blockPos, BlockState blockIn) {
- this.playSound(SoundEvents.GRASS_STEP, 0.3f, 1.0f);
- }
- protected SoundEvent getAmbientSound() {
- return SoundEvents.GRASS_STEP;
- }
- protected SoundEvent getHurtSound(DamageSource dmgSrc) {
- return SoundEvents.GRASS_HIT;
- }
- protected SoundEvent getDeathSound() {
- return SoundEvents.GRASS_BREAK;
- }
- protected float getVolume() {
- return 1.0f;
- }
- @Contract("null->false")
- public boolean canTargetEntity(@javax.annotation.Nullable Entity entity) {
- if (entity instanceof LivingEntity livingentity) {
- if (this.level == entity.level && EntitySelector.NO_CREATIVE_OR_SPECTATOR.test(entity) && !this.isAlliedTo(entity) && livingentity.getType() != EntityType.ARMOR_STAND && livingentity.getType() != EntityType.WARDEN && !livingentity.isInvulnerable() && !livingentity.isDeadOrDying() && this.level.getWorldBorder().isWithinBounds(livingentity.getBoundingBox())) {
- if (!(entity instanceof BoxEntity)) return true;
- }
- }
- return false;
- }
- @Override
- public boolean shouldListen(ServerLevel pLevel, GameEventListener pListener, BlockPos pPos, GameEvent pEvent, GameEvent.Context pContext) {
- if (!this.isNoAi() && !this.isDeadOrDying() && !this.getBrain().hasMemoryValue(MemoryModuleType.VIBRATION_COOLDOWN) && pLevel.getWorldBorder().isWithinBounds(pPos) && !this.isRemoved() && this.level == pLevel) {
- Entity entity = pContext.sourceEntity();
- if (entity instanceof LivingEntity) {
- LivingEntity livingentity = (LivingEntity)entity;
- if (!this.canTargetEntity(livingentity)) {
- return false;
- }
- }
- return true;
- } else {
- return false;
- }
- }
- @Override
- public void updateDynamicGameEventListener(BiConsumer<DynamicGameEventListener<?>, ServerLevel> serverLevel) {
- Level level = this.level;
- if (level instanceof ServerLevel serverlevel) {
- serverLevel.accept(this.dynamicGameEventListener, serverlevel);
- }
- }
- @Override
- public void onSignalReceive(ServerLevel level, GameEventListener listener, BlockPos pos, GameEvent event, @Nullable Entity entity, @Nullable Entity entity2, float distance) {
- System.out.println("[DEBUG] event: " + event.toString());
- System.out.println("[DEBUG] entity: " + entity.toString());
- System.out.println("[DEBUG] distance: " + distance);
- if (entity instanceof LivingEntity && entity.isAlive() && !(entity instanceof BoxEntity)) {
- this.setTarget((LivingEntity) entity);
- }
- }
- // Climbing stuff
- @Override
- protected PathNavigation createNavigation(Level pLevel) {
- return new WallClimberNavigation(this, pLevel);
- }
- public boolean isAngry() {
- return this.angry;
- }
- public boolean isClimbing() {
- // System.out.println((this.entityData.get(DATA_FLAGS_ID) & 1) != 0);
- // System.out.println(this.climbing);
- System.out.println(this.entityData.get(SYNC_DATA));
- return this.entityData.get(SYNC_DATA);
- }
- public boolean onClimbable() {
- return this.isClimbing();
- }
- @Override
- protected void defineSynchedData() {
- super.defineSynchedData();
- this.entityData.define(SYNC_DATA, false);
- }
- public void setClimbing(boolean pClimbing) {
- boolean data = this.entityData.get(SYNC_DATA);
- this.entityData.set(SYNC_DATA, pClimbing);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment