-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Villagers should now be able to open doors added by other mods
- Loading branch information
ganymedes01
committed
Sep 22, 2015
1 parent
1eacd95
commit 89d3121
Showing
3 changed files
with
143 additions
and
0 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
89 changes: 89 additions & 0 deletions
89
src/main/java/ganymedes01/etfuturum/entities/ai/EntityAICustomDoorInteract.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,89 @@ | ||
package ganymedes01.etfuturum.entities.ai; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockDoor; | ||
import net.minecraft.entity.EntityLiving; | ||
import net.minecraft.entity.ai.EntityAIBase; | ||
import net.minecraft.pathfinding.PathEntity; | ||
import net.minecraft.pathfinding.PathNavigate; | ||
import net.minecraft.pathfinding.PathPoint; | ||
import net.minecraft.util.MathHelper; | ||
|
||
/* | ||
* Copy paste from vanilla and adapted to work with other doors | ||
*/ | ||
public abstract class EntityAICustomDoorInteract extends EntityAIBase { | ||
|
||
protected EntityLiving theEntity; | ||
protected int entityPosX; | ||
protected int entityPosY; | ||
protected int entityPosZ; | ||
protected BlockDoor field_151504_e; | ||
boolean hasStoppedDoorInteraction; | ||
float entityPositionX; | ||
float entityPositionZ; | ||
|
||
public EntityAICustomDoorInteract(EntityLiving p_i1621_1_) { | ||
theEntity = p_i1621_1_; | ||
} | ||
|
||
@Override | ||
public boolean shouldExecute() { | ||
if (!theEntity.isCollidedHorizontally) | ||
return false; | ||
else { | ||
PathNavigate pathnavigate = theEntity.getNavigator(); | ||
PathEntity pathentity = pathnavigate.getPath(); | ||
|
||
if (pathentity != null && !pathentity.isFinished() && pathnavigate.getCanBreakDoors()) { | ||
for (int i = 0; i < Math.min(pathentity.getCurrentPathIndex() + 2, pathentity.getCurrentPathLength()); ++i) { | ||
PathPoint pathpoint = pathentity.getPathPointFromIndex(i); | ||
entityPosX = pathpoint.xCoord; | ||
entityPosY = pathpoint.yCoord + 1; | ||
entityPosZ = pathpoint.zCoord; | ||
|
||
if (theEntity.getDistanceSq(entityPosX, theEntity.posY, entityPosZ) <= 2.25D) { | ||
field_151504_e = func_151503_a(entityPosX, entityPosY, entityPosZ); | ||
|
||
if (field_151504_e != null) | ||
return true; | ||
} | ||
} | ||
|
||
entityPosX = MathHelper.floor_double(theEntity.posX); | ||
entityPosY = MathHelper.floor_double(theEntity.posY + 1.0D); | ||
entityPosZ = MathHelper.floor_double(theEntity.posZ); | ||
field_151504_e = func_151503_a(entityPosX, entityPosY, entityPosZ); | ||
return field_151504_e != null; | ||
} else | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean continueExecuting() { | ||
return !hasStoppedDoorInteraction; | ||
} | ||
|
||
@Override | ||
public void startExecuting() { | ||
hasStoppedDoorInteraction = false; | ||
entityPositionX = (float) (entityPosX + 0.5F - theEntity.posX); | ||
entityPositionZ = (float) (entityPosZ + 0.5F - theEntity.posZ); | ||
} | ||
|
||
@Override | ||
public void updateTask() { | ||
float f = (float) (entityPosX + 0.5F - theEntity.posX); | ||
float f1 = (float) (entityPosZ + 0.5F - theEntity.posZ); | ||
float f2 = entityPositionX * f + entityPositionZ * f1; | ||
|
||
if (f2 < 0.0F) | ||
hasStoppedDoorInteraction = true; | ||
} | ||
|
||
private BlockDoor func_151503_a(int x, int y, int z) { | ||
Block block = theEntity.worldObj.getBlock(x, y, z); | ||
return block instanceof BlockDoor ? (BlockDoor) block : null; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/ganymedes01/etfuturum/entities/ai/EntityAIOpenCustomDoor.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,41 @@ | ||
package ganymedes01.etfuturum.entities.ai; | ||
|
||
import net.minecraft.entity.EntityLiving; | ||
|
||
/* | ||
* Copy paste from vanilla and adapted to work with other doors | ||
*/ | ||
public class EntityAIOpenCustomDoor extends EntityAICustomDoorInteract { | ||
|
||
boolean field_75361_i; | ||
int field_75360_j; | ||
|
||
public EntityAIOpenCustomDoor(EntityLiving p_i1644_1_, boolean p_i1644_2_) { | ||
super(p_i1644_1_); | ||
theEntity = p_i1644_1_; | ||
field_75361_i = p_i1644_2_; | ||
} | ||
|
||
@Override | ||
public boolean continueExecuting() { | ||
return field_75361_i && field_75360_j > 0 && super.continueExecuting(); | ||
} | ||
|
||
@Override | ||
public void startExecuting() { | ||
field_75360_j = 20; | ||
field_151504_e.func_150014_a(theEntity.worldObj, entityPosX, entityPosY, entityPosZ, true); | ||
} | ||
|
||
@Override | ||
public void resetTask() { | ||
if (field_75361_i) | ||
field_151504_e.func_150014_a(theEntity.worldObj, entityPosX, entityPosY, entityPosZ, false); | ||
} | ||
|
||
@Override | ||
public void updateTask() { | ||
--field_75360_j; | ||
super.updateTask(); | ||
} | ||
} |