-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more special mob interactions, fix cooldown animations, add phant…
…om to flight tag
- Loading branch information
Showing
17 changed files
with
375 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/draylar/identity/mixin/FollowTargetGoalMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package draylar.identity.mixin; | ||
|
||
import draylar.identity.Identity; | ||
import draylar.identity.registry.Components; | ||
import net.minecraft.entity.EntityGroup; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.goal.FollowTargetGoal; | ||
import net.minecraft.entity.ai.goal.TrackTargetGoal; | ||
import net.minecraft.entity.boss.WitherEntity; | ||
import net.minecraft.entity.mob.HostileEntity; | ||
import net.minecraft.entity.mob.MobEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
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; | ||
|
||
@Mixin(FollowTargetGoal.class) | ||
public abstract class FollowTargetGoalMixin extends TrackTargetGoal { | ||
|
||
@Shadow protected LivingEntity targetEntity; | ||
|
||
public FollowTargetGoalMixin(MobEntity mob, boolean checkVisibility) { | ||
super(mob, checkVisibility); | ||
} | ||
|
||
@Inject( | ||
method = "start", | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private void ignoreMorphedPlayers(CallbackInfo ci) { | ||
if (Identity.CONFIG.hostilesIgnoreHostileIdentityPlayer && this.mob instanceof HostileEntity && this.targetEntity instanceof PlayerEntity) { | ||
PlayerEntity targetPlayer = (PlayerEntity) this.targetEntity; | ||
LivingEntity identity = Components.CURRENT_IDENTITY.get(targetPlayer).getIdentity(); | ||
|
||
// withers should ignore undead | ||
if(this.mob instanceof WitherEntity && identity.getGroup().equals(EntityGroup.UNDEAD)) { | ||
super.stop(); | ||
ci.cancel(); | ||
} | ||
|
||
// hostile mobs (besides wither) should not target players morphed as hostile mobs | ||
else if (!(this.mob instanceof WitherEntity) && identity instanceof HostileEntity) { | ||
super.stop(); | ||
ci.cancel(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public boolean shouldContinue() { | ||
// check cancelling for hostiles | ||
if(Identity.CONFIG.hostilesIgnoreHostileIdentityPlayer && Identity.CONFIG.hostilesForgetNewHostileIdentityPlayer && this.mob instanceof HostileEntity && this.targetEntity instanceof PlayerEntity) { | ||
PlayerEntity targetPlayer = (PlayerEntity) this.targetEntity; | ||
LivingEntity identity = Components.CURRENT_IDENTITY.get(targetPlayer).getIdentity(); | ||
|
||
// withers should ignore undead | ||
if(this.mob instanceof WitherEntity && identity.getGroup().equals(EntityGroup.UNDEAD)) { | ||
return false; | ||
} | ||
|
||
// hostile mobs (besides wither) should not target players morphed as hostile mobs | ||
else if (!(this.mob instanceof WitherEntity) && identity instanceof HostileEntity) { | ||
return false; | ||
} | ||
} | ||
|
||
return super.shouldContinue(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package draylar.identity.mixin; | ||
|
||
import draylar.identity.Identity; | ||
import draylar.identity.registry.Components; | ||
import draylar.identity.registry.EntityTags; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.goal.FollowTargetGoal; | ||
import net.minecraft.entity.passive.AnimalEntity; | ||
import net.minecraft.entity.passive.FishEntity; | ||
import net.minecraft.entity.passive.FoxEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(FoxEntity.class) | ||
public abstract class FoxEntityMixin extends AnimalEntity { | ||
|
||
private FoxEntityMixin(EntityType<? extends AnimalEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Inject( | ||
method = "initGoals", | ||
at = @At("RETURN") | ||
) | ||
private void addPlayerTarget(CallbackInfo ci) { | ||
this.targetSelector.add(7, new FollowTargetGoal<>(this, PlayerEntity.class, 10, false, false, player -> { | ||
// ensure foxes can attack players with an identity similar to their normal prey | ||
if(!Identity.CONFIG.foxesAttackIdentityPrey) { | ||
return false; | ||
} | ||
|
||
// foxes can target players if their identity is in the fox_prey tag, or if they are an entity that extends FishEntity | ||
// todo: add baby turtle targeting | ||
LivingEntity identity = Components.CURRENT_IDENTITY.get(player).getIdentity(); | ||
return identity != null && EntityTags.FOX_PREY.contains(identity.getType()) || identity instanceof FishEntity; | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/draylar/identity/mixin/VillagerEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package draylar.identity.mixin; | ||
|
||
import draylar.identity.registry.Components; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.passive.VillagerEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
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.CallbackInfoReturnable; | ||
|
||
@Mixin(VillagerEntity.class) | ||
public abstract class VillagerEntityMixin { | ||
|
||
@Shadow protected abstract void sayNo(); | ||
|
||
@Inject( | ||
method = "interactMob", | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private void onInteract(PlayerEntity player, Hand hand, CallbackInfoReturnable<ActionResult> cir) { | ||
LivingEntity identity = Components.CURRENT_IDENTITY.get(player).getIdentity(); | ||
|
||
if(identity != null && identity.isUndead()) { | ||
this.sayNo(); | ||
cir.setReturnValue(ActionResult.SUCCESS); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/draylar/identity/mixin/VillagerHostilesSensorMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package draylar.identity.mixin; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import draylar.identity.Identity; | ||
import draylar.identity.registry.Components; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.ai.brain.sensor.VillagerHostilesSensor; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
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.CallbackInfoReturnable; | ||
|
||
@Mixin(VillagerHostilesSensor.class) | ||
public class VillagerHostilesSensorMixin { | ||
|
||
@Shadow @Final private static ImmutableMap<EntityType<?>, Float> SQUARED_DISTANCES_FOR_DANGER; | ||
|
||
@Inject( | ||
method = "isHostile", | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private void checkHostileIdentity(LivingEntity entity, CallbackInfoReturnable<Boolean> cir) { | ||
if(entity instanceof PlayerEntity) { | ||
// check if we should be performing this from config | ||
if(Identity.CONFIG.villagersRunFromIdentities) { | ||
LivingEntity identity = Components.CURRENT_IDENTITY.get(entity).getIdentity(); | ||
|
||
// check if identity is valid & if it is a type villagers run from | ||
if (identity != null && SQUARED_DISTANCES_FOR_DANGER.containsKey(identity.getType())) { | ||
cir.setReturnValue(true); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Inject( | ||
method = "isCloseEnoughForDanger", | ||
at = @At("HEAD"), | ||
cancellable = true | ||
) | ||
private void checkPlayerDanger(LivingEntity villager, LivingEntity potentialPlayer, CallbackInfoReturnable<Boolean> cir) { | ||
// should only be called if the above mixin passes, so we can assume the config option is true | ||
if(potentialPlayer instanceof PlayerEntity) { | ||
LivingEntity identity = Components.CURRENT_IDENTITY.get(potentialPlayer).getIdentity(); | ||
|
||
// check if identity is valid & if it is a type villagers run from | ||
if (identity != null && SQUARED_DISTANCES_FOR_DANGER.containsKey(identity.getType())) { | ||
float f = SQUARED_DISTANCES_FOR_DANGER.get(identity.getType()); | ||
cir.setReturnValue(potentialPlayer.squaredDistanceTo(villager) <= (double) (f * f)); | ||
} else { | ||
cir.setReturnValue(false); | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/draylar/identity/mixin/WitherEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package draylar.identity.mixin; | ||
|
||
import draylar.identity.registry.Components; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.boss.WitherEntity; | ||
import net.minecraft.entity.mob.HostileEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.world.World; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
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.LocalCapture; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Mixin(WitherEntity.class) | ||
public abstract class WitherEntityMixin extends HostileEntity { | ||
|
||
private WitherEntityMixin(EntityType<? extends HostileEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Inject( | ||
method = "mobTick", | ||
at = @At(value = "INVOKE", target = "Ljava/util/List;isEmpty()Z"), | ||
locals = LocalCapture.CAPTURE_FAILHARD | ||
) | ||
private void removeInvalidPlayerTargets(CallbackInfo ci, int j, List<LivingEntity> list, int l) { | ||
List<LivingEntity> toRemove = new ArrayList(); | ||
|
||
list.forEach(entity -> { | ||
if(entity instanceof PlayerEntity) { | ||
LivingEntity identity = Components.CURRENT_IDENTITY.get(entity).getIdentity(); | ||
|
||
// potentially ignore undead identity players | ||
if(identity != null && identity.isUndead()) { | ||
if(this.getTarget() != null) { | ||
// if this wither's target is not equal to the current entity | ||
if(!this.getTarget().getUuid().equals(entity.getUuid())) { | ||
toRemove.add(entity); | ||
} | ||
} else { | ||
toRemove.add(entity); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
list.removeAll(toRemove); | ||
} | ||
} |
Oops, something went wrong.