Skip to content

Commit

Permalink
Enderman & passive mob changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pot-Tx committed Jun 23, 2024
1 parent b6c2244 commit fb8f9fe
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ This is a Minecraft Better Than Wolves addon that aims to slightly strengthen mo

### Endermen

- Endermen sometimes try to teleport their attack target when they cannot reach them.
- Players' gloom level rapidly increase when starring at an enderman.
- Players' gloom level rapidly increase when being too close to an enderman.

Expand All @@ -124,6 +125,8 @@ This is a Minecraft Better Than Wolves addon that aims to slightly strengthen mo
- Villagers and pigs try to flee from explosions.
- Pigs counterattack at high health.
- Some cows counterattack to protect weaker ones in the herd.
- Players' view is locked on first person when head crabbed by a squid.
- Animals have enhanced fleeing AI.
- Animals panic when pushed by a player.
- Players' reputation decrease if they attack villagers in a village.
- Villagers refuse to trade with players who have low reputation.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MobsEnhancementAddon extends BTWAddon {
private static MobsEnhancementAddon instance;

private MobsEnhancementAddon() {
super("Mobs Enhancement", "0.3.0", "MEA");
super("Mobs Enhancement", "0.3.1", "MEA");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void updateTask() {
}

this.attackTimer = Math.max(this.attackTimer - 1, 0);
double reach = theAnimal.width + targetEntity.width;
double reach = theAnimal.width + targetEntity.width + 0.5D;

if ( targetEntity == this.theAnimal.riddenByEntity ) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public CowEntityMixin(World par1World) {
super(par1World);
}

@Override
public int getMeleeAttackStrength(Entity target) {
return 4;
}

@Inject(
method = "<init>",
at = @At(value = "TAIL")
Expand All @@ -35,9 +40,9 @@ private void addExtraDataAndTasks(CallbackInfo ci) {
this.tasks.removeAllTasksOfClass(EntityAIWatchClosest.class);

if (this.getIsAggressive() == (byte)1) {
tasks.addTask(1, new AnimalCombatBehavior(this, 0.28F, 0.33F, ZombieEntity.class, 4));
tasks.addTask(1, new AnimalCombatBehavior(this, 0.38F, 0.33F, ZombieEntity.class, 4));
} else {
tasks.addTask(1, new AnimalCombatBehavior(this, 0.28F, 0.33F, ZombieEntity.class, 15));
tasks.addTask(1, new AnimalCombatBehavior(this, 0.38F, 0.33F, ZombieEntity.class, 15));
}
}

Expand Down Expand Up @@ -81,7 +86,7 @@ public boolean attackEntityFrom(DamageSource par1DamageSource, int par2) {

boolean isSpeciesSame = tempAnimal instanceof CowEntity;

if (!tempAnimal.isLivingDead && isSpeciesSame && !tempAnimal.hasAttackTarget())
if (!tempAnimal.isLivingDead && isSpeciesSame && !tempAnimal.hasAttackTarget() && tempAnimal.canEntityBeSeen(this))
{
tempAnimal.setAttackTarget((EntityLiving)attacker);
}
Expand Down
105 changes: 105 additions & 0 deletions src/main/java/net/pottx/mobsenhancement/mixin/EndermanEntityMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package net.pottx.mobsenhancement.mixin;

import btw.entity.mob.EndermanEntity;
import net.minecraft.src.*;
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(EndermanEntity.class)
public class EndermanEntityMixin extends EntityEnderman {
@Shadow protected int teleportDelay;

public EndermanEntityMixin(World par1World) {
super(par1World);
}

@Inject(
method = "onLivingUpdate",
at = @At(value = "INVOKE", target = "Lbtw/entity/mob/EndermanEntity;entityMobOnLivingUpdate()V")
)
private void updateEnemyTeleport(CallbackInfo ci)
{
if (!this.worldObj.isRemote && this.isEntityAlive() && this.entityToAttack != null) {
if (entityToAttack.getDistanceSqToEntity(this) > 6.0D && entityToAttack.getDistanceSqToEntity(this) < 64D) {
if (teleportDelay++ >= 120 && this.teleportEnemy()) {
this.teleportDelay = 0;
}
} else if (entityToAttack.getDistanceSqToEntity(this) < 256D) {
this.teleportDelay = 0;
}
}
}

protected boolean teleportEnemy() {
if (this.entityToAttack != null) {
Entity target = this.entityToAttack;
Vec3 vec = this.worldObj.getWorldVec3Pool().getVecFromPool(this.posX - target.posX, this.boundingBox.minY + (double)(this.height / 2.0F) - target.posY + (double)target.getEyeHeight(), this.posZ - target.posZ);
vec = vec.normalize();
double x0 = target.posX;
double y0 = target.posY;
double z0 = target.posZ;
target.posX = x0 + (this.rand.nextDouble() - 0.5D) * 8.0D + vec.xCoord * 0.8D;
target.posY = y0 + (double)(this.rand.nextInt(16) - 8) + vec.yCoord * 0.8D;
target.posZ = z0 + (this.rand.nextDouble() - 0.5D) * 8.0D + vec.zCoord * 0.8D;
int xb = MathHelper.floor_double(target.posX);
int yb = MathHelper.floor_double(target.posY);
int zb = MathHelper.floor_double(target.posZ);
int blockId;

if (this.worldObj.blockExists(xb, yb, zb)) {
boolean canTeleport = false;

while (!canTeleport && yb > 0) {
blockId = this.worldObj.getBlockId(xb, yb, zb);
if (blockId != 0 && Block.blocksList[blockId].blockMaterial.blocksMovement()) {
canTeleport = true;
for (int i = 1; i <= MathHelper.ceiling_float_int(target.height); i++) {
blockId = this.worldObj.getBlockId(xb, yb + i, zb);
if (blockId != 0 && Block.blocksList[blockId].blockMaterial.blocksMovement()) {
canTeleport = false;
target.posY -= MathHelper.ceiling_float_int(target.height) + 1;
yb -= MathHelper.ceiling_float_int(target.height) + 1;
break;
}
}
++target.posY;
}
else {
--target.posY;
--yb;
}
}

if (canTeleport) {
if (target instanceof EntityPlayer) {
((EntityPlayer) target).setPositionAndUpdate(target.posX, target.posY, target.posZ);
} else {
target.setPosition(target.posX, target.posY, target.posZ);
}

short var30 = 128;
for (blockId = 0; blockId < var30; ++blockId) {
double var19 = (double)blockId / ((double)var30 - 1.0D);
float var21 = (this.rand.nextFloat() - 0.5F) * 0.2F;
float var22 = (this.rand.nextFloat() - 0.5F) * 0.2F;
float var23 = (this.rand.nextFloat() - 0.5F) * 0.2F;
double var24 = x0 + (target.posX - x0) * var19 + (this.rand.nextDouble() - 0.5D) * (double)target.width * 2.0D;
double var26 = y0 + (target.posY - y0) * var19 + this.rand.nextDouble() * (double)target.height;
double var28 = z0 + (target.posZ - z0) * var19 + (this.rand.nextDouble() - 0.5D) * (double)target.width * 2.0D;
this.worldObj.spawnParticle("portal", var24, var26, var28, (double)var21, (double)var22, (double)var23);
}
this.worldObj.playSoundEffect(x0, y0, z0, "mob.endermen.portal", 1.0F, 1.0F);
target.playSound("mob.endermen.portal", 1.0F, 1.0F);

return true;
} else {
target.setPosition(x0, y0, z0);
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package net.pottx.mobsenhancement.mixin;

import net.minecraft.src.*;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(EntityAnimal.class)
public abstract class EntityAnimalMixin extends EntityAgeable {
@Shadow public abstract void setRevengeTarget(EntityLiving targetEntity);

@Unique
private int pushedCounter = 0;

public EntityAnimalMixin(World par1World) {
super(par1World);
}

@Inject(
method = "onLivingUpdate",
at = @At(value = "TAIL")
)
private void updatePushed(CallbackInfo ci) {
EntityPlayer player = (EntityPlayer) this.worldObj.findNearestEntityWithinAABB(EntityPlayer.class, this.boundingBox.expand(1.5D, 1D, 1.5D), this);
if (player != null && this.boundingBox.expand(0.35D, 0.35D, 0.35D).intersectsWith(player.boundingBox)) {
if (this.pushedCounter < 10) {
++this.pushedCounter;
} else {
this.setRevengeTarget(player);
}
} else if (this.pushedCounter > 0) {
this.pushedCounter = 0;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public PigEntityMixin(World par1World) {
super(par1World);
}

@Override
public int getMeleeAttackStrength(Entity target) {
return 3;
}


@Inject(
method = "<init>",
at = @At(value = "TAIL")
Expand Down Expand Up @@ -52,7 +58,7 @@ private void setAttackTargetWhenAttacked(DamageSource par1DamageSource, int par2

boolean isSpeciesSame = tempAnimal instanceof PigEntity;

if (!tempAnimal.isLivingDead && isSpeciesSame && !tempAnimal.hasAttackTarget())
if (!tempAnimal.isLivingDead && isSpeciesSame && !tempAnimal.hasAttackTarget() && tempAnimal.canEntityBeSeen(this))
{
tempAnimal.setAttackTarget((EntityLiving)attacker);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "mobsenhancement",
"version": "0.3.0",
"version": "0.3.1",

"name": "Mobs Enhancement Addon",
"description": "Slightly strengthens monsters.",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/mobsenhancement.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
"CreeperEntityAccess",
"CreeperEntityMixin",
"CreeperSwellBehaviorMixin",
"EndermanEntityMixin",
"EntityAccess",
"EntityAILookIdleMixin",
"EntityAITargetMixin",
"EntityAITradePlayerMixin",
"EntityAnimalMixin",
"EntityArrowMixin",
"EntityCreeperAccess",
"EntityCreeperMixin",
Expand Down

0 comments on commit fb8f9fe

Please sign in to comment.