2020-06-14 03:04:21 +00:00
|
|
|
package com.thebrokenrail.twine.mixin;
|
|
|
|
|
|
|
|
import com.thebrokenrail.twine.component.StageDataComponent;
|
2020-06-15 15:15:20 +00:00
|
|
|
import com.thebrokenrail.twine.entity.ExplodeArtificialBlockGoal;
|
2020-06-15 20:05:35 +00:00
|
|
|
import com.thebrokenrail.twine.entity.FleeEndRodGoal;
|
2020-06-14 03:04:21 +00:00
|
|
|
import com.thebrokenrail.twine.entity.FollowPassiveEntityGoal;
|
|
|
|
import com.thebrokenrail.twine.entity.StandOnGlowingObsidian;
|
2020-06-15 21:31:15 +00:00
|
|
|
import com.thebrokenrail.twine.util.StageUtil;
|
2020-06-14 03:04:21 +00:00
|
|
|
import net.minecraft.entity.EntityType;
|
|
|
|
import net.minecraft.entity.ai.goal.FollowTargetGoal;
|
|
|
|
import net.minecraft.entity.ai.goal.GoalSelector;
|
|
|
|
import net.minecraft.entity.mob.*;
|
|
|
|
import net.minecraft.entity.passive.IronGolemEntity;
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
import net.minecraft.server.world.ServerWorld;
|
2020-06-15 20:29:28 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-06-14 03:04:21 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import org.spongepowered.asm.mixin.Final;
|
|
|
|
import org.spongepowered.asm.mixin.Mixin;
|
|
|
|
import org.spongepowered.asm.mixin.Shadow;
|
|
|
|
import org.spongepowered.asm.mixin.injection.At;
|
|
|
|
import org.spongepowered.asm.mixin.injection.Inject;
|
2020-06-15 20:55:56 +00:00
|
|
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
2020-06-14 03:04:21 +00:00
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
2020-06-15 20:05:35 +00:00
|
|
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
2020-06-14 03:04:21 +00:00
|
|
|
|
2020-06-15 20:55:56 +00:00
|
|
|
import java.util.Random;
|
|
|
|
|
2020-06-14 03:04:21 +00:00
|
|
|
@SuppressWarnings("ConstantConditions")
|
|
|
|
@Mixin(MobEntity.class)
|
|
|
|
public class MixinMobEntity {
|
|
|
|
@Shadow
|
|
|
|
@Final
|
|
|
|
protected GoalSelector targetSelector;
|
|
|
|
|
|
|
|
@Shadow
|
|
|
|
@Final
|
|
|
|
protected GoalSelector goalSelector;
|
|
|
|
|
|
|
|
@Inject(at = @At("RETURN"), method = "<init>")
|
|
|
|
public void initGoals(EntityType<? extends MobEntity> entityType, World world, CallbackInfo info) {
|
|
|
|
if (world != null && !world.isClient()) {
|
|
|
|
if (this instanceof Monster) {
|
|
|
|
if ((Object) this instanceof MobEntityWithAi) {
|
|
|
|
goalSelector.add(1, new StandOnGlowingObsidian((MobEntityWithAi) (Object) this));
|
2020-06-15 20:05:35 +00:00
|
|
|
goalSelector.add(3, new FleeEndRodGoal((MobEntityWithAi) (Object) this));
|
2020-06-15 15:15:20 +00:00
|
|
|
if ((Object) this instanceof CreeperEntity) {
|
|
|
|
goalSelector.add(3, new ExplodeArtificialBlockGoal((MobEntityWithAi) (Object) this));
|
|
|
|
}
|
2020-06-14 03:04:21 +00:00
|
|
|
}
|
|
|
|
targetSelector.add(2, new FollowPassiveEntityGoal((MobEntity) (Object) this));
|
|
|
|
} else if ((Object) this instanceof IronGolemEntity) {
|
|
|
|
targetSelector.add(3, new FollowTargetGoal<>((IronGolemEntity) (Object) this, PlayerEntity.class, 10, true, false, entity -> {
|
|
|
|
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) ((IronGolemEntity) (Object) this).getEntityWorld());
|
2020-06-15 20:29:28 +00:00
|
|
|
BlockPos blockPos = ((IronGolemEntity) (Object) this).getBlockPos();
|
|
|
|
int stage = component.findEffectiveStageOfChunk((ServerWorld) (((IronGolemEntity) (Object) this).getEntityWorld()), blockPos);
|
2020-06-14 03:04:21 +00:00
|
|
|
|
2020-06-15 21:31:15 +00:00
|
|
|
return stage >= StageUtil.IRON_GOLEMS_TARGET_PLAYERS && !((IronGolemEntity) (Object) this).isPlayerCreated();
|
2020-06-14 03:04:21 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 20:05:35 +00:00
|
|
|
|
|
|
|
@Inject(at = @At("HEAD"), method = "isInDaylight", cancellable = true)
|
|
|
|
public void isInDaylight(CallbackInfoReturnable<Boolean> info) {
|
2020-06-15 20:29:28 +00:00
|
|
|
if (!((MobEntity) (Object) this).getEntityWorld().isClient()) {
|
|
|
|
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) ((MobEntity) (Object) this).getEntityWorld());
|
|
|
|
BlockPos blockPos = ((MobEntity) (Object) this).getBlockPos();
|
|
|
|
int stage = component.findEffectiveStageOfChunk((ServerWorld) ((MobEntity) (Object) this).getEntityWorld(), blockPos);
|
2020-06-15 21:31:15 +00:00
|
|
|
if (stage >= StageUtil.MOBS_NO_LONGER_BURN_IN_SUNLIGHT) {
|
2020-06-15 20:29:28 +00:00
|
|
|
info.setReturnValue(false);
|
|
|
|
}
|
2020-06-15 20:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-15 20:55:56 +00:00
|
|
|
|
|
|
|
@Redirect(at = @At(value = "INVOKE", target = "Ljava/util/Random;nextFloat()F", ordinal = 0), method = "initEquipment", allow = 1)
|
|
|
|
public float initEquipment(Random random) {
|
|
|
|
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) ((MobEntity) (Object) this).getEntityWorld());
|
|
|
|
BlockPos blockPos = ((MobEntity) (Object) this).getBlockPos();
|
|
|
|
int stage = component.findEffectiveStageOfChunk((ServerWorld) ((MobEntity) (Object) this).getEntityWorld(), blockPos);
|
2020-06-15 21:31:15 +00:00
|
|
|
if (stage >= StageUtil.MOBS_GUARANTEED_ARMOR) {
|
2020-06-15 20:55:56 +00:00
|
|
|
return -1f;
|
|
|
|
} else {
|
|
|
|
return random.nextFloat();
|
|
|
|
}
|
|
|
|
}
|
2020-06-14 03:04:21 +00:00
|
|
|
}
|