This repository has been archived on 2023-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
Twine/src/main/java/com/thebrokenrail/twine/mixin/MixinMobEntity.java

70 lines
3.4 KiB
Java

package com.thebrokenrail.twine.mixin;
import com.thebrokenrail.twine.component.StageDataComponent;
import com.thebrokenrail.twine.entity.ExplodeArtificialBlockGoal;
import com.thebrokenrail.twine.entity.FleeEndRodGoal;
import com.thebrokenrail.twine.entity.FollowPassiveEntityGoal;
import com.thebrokenrail.twine.entity.StandOnGlowingObsidian;
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;
import net.minecraft.util.math.ChunkPos;
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@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));
goalSelector.add(3, new FleeEndRodGoal((MobEntityWithAi) (Object) this));
if ((Object) this instanceof CreeperEntity) {
goalSelector.add(3, new ExplodeArtificialBlockGoal((MobEntityWithAi) (Object) this));
}
}
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());
ChunkPos chunkPos = new ChunkPos(((IronGolemEntity) (Object) this).getBlockPos());
int stage = component.findEffectiveStageOfChunk((ServerWorld) (((IronGolemEntity) (Object) this).getEntityWorld()), chunkPos);
return stage >= 3 && !((IronGolemEntity) (Object) this).isPlayerCreated();
}));
}
}
}
@Inject(at = @At("HEAD"), method = "isInDaylight", cancellable = true)
public void isInDaylight(CallbackInfoReturnable<Boolean> info) {
StageDataComponent component = StageDataComponent.getFromWorld((ServerWorld) ((ZombieEntity) (Object) this).getEntityWorld());
ChunkPos chunkPos = new ChunkPos(((ZombieEntity) (Object) this).getBlockPos());
int stage = component.findEffectiveStageOfChunk((ServerWorld) ((ZombieEntity) (Object) this).getEntityWorld(), chunkPos);
if (stage >= 5) {
info.setReturnValue(false);
}
}
}