mirror of
https://github.com/chylex/Hardcore-Ender-Expansion.git
synced 2025-04-10 20:15:42 +02:00
More work on Homeland
This commit is contained in:
parent
2f6cb99b81
commit
5d19de59bf
src/main/java/chylex/hee
entity
mechanics/misc
world/structure/island/biome/interaction
@ -3,6 +3,8 @@ import java.util.UUID;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.monster.EntityMob;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@ -20,6 +22,8 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
private long groupId = -1;
|
||||
private OvertakeGroupRole overtakeGroupRole;
|
||||
|
||||
private byte stareTimer;
|
||||
|
||||
public EntityMobHomelandEnderman(World world){
|
||||
super(world);
|
||||
setSize(0.6F,2.9F);
|
||||
@ -31,6 +35,7 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
super.entityInit();
|
||||
dataWatcher.addObject(16,Byte.valueOf((byte)0));
|
||||
dataWatcher.addObjectByDataType(17,5);
|
||||
dataWatcher.addObject(18,Byte.valueOf((byte)0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,20 +70,33 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
public void onLivingUpdate(){
|
||||
super.onLivingUpdate();
|
||||
|
||||
// TODO AI
|
||||
if (worldObj.isRemote){
|
||||
refreshRoles();
|
||||
}
|
||||
else{
|
||||
// TODO AI
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Entity findPlayerToAttack(){
|
||||
if (groupId != -1 && !HomelandEndermen.isOvertakeHappening(this)){
|
||||
//teleportRandomly(); // TODO
|
||||
return null;
|
||||
}
|
||||
else{
|
||||
|
||||
if (!shouldActHostile() && teleportRandomly())return null;
|
||||
|
||||
EntityPlayer closestPlayer = worldObj.getClosestPlayerToEntity(this,64D);
|
||||
|
||||
if (closestPlayer != null){
|
||||
if (isPlayerStaringIntoEyes(closestPlayer)){
|
||||
if (stareTimer == 0)worldObj.playSoundEffect(closestPlayer.posX,closestPlayer.posY,closestPlayer.posZ,"mob.endermen.stare",1F,1F);
|
||||
else if (stareTimer++ == 5){
|
||||
stareTimer = 0;
|
||||
setScreaming(true);
|
||||
return closestPlayer;
|
||||
}
|
||||
}
|
||||
else stareTimer = 0;
|
||||
}
|
||||
|
||||
return super.findPlayerToAttack();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,6 +120,7 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
}
|
||||
|
||||
if (homelandRole == null || (groupId != -1 && overtakeGroupRole == null))setDead();
|
||||
else if (!worldObj.isRemote)refreshRoles();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -113,10 +132,31 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
return !HomelandEndermen.isOvertakeHappening(this);
|
||||
}
|
||||
|
||||
// GETTERS AND SETTERS
|
||||
private boolean shouldActHostile(){
|
||||
if (homelandRole == HomelandRole.ISLAND_LEADERS || (groupId != -1 && rand.nextInt(5) != 0) || HomelandEndermen.isOvertakeHappening(this)){
|
||||
return false;
|
||||
}
|
||||
else return rand.nextInt(4) != 0;
|
||||
}
|
||||
|
||||
// GETTERS, SETTERS AND DATA WATCHER
|
||||
|
||||
private void refreshRoles(){
|
||||
if (!worldObj.isRemote){
|
||||
int data = (homelandRole.ordinal() & 0b1111) << 4;
|
||||
if (overtakeGroupRole != null)data |= ((overtakeGroupRole.ordinal()+1) & 0b1111);
|
||||
dataWatcher.updateObject(18,Byte.valueOf((byte)data));
|
||||
}
|
||||
else{
|
||||
byte data = dataWatcher.getWatchableObjectByte(18);
|
||||
homelandRole = HomelandRole.values[(data >> 4) & 0b1111];
|
||||
if ((data & 0b1111) > 0)overtakeGroupRole = OvertakeGroupRole.values[data & 0b1111];
|
||||
}
|
||||
}
|
||||
|
||||
public void setHomelandRole(HomelandRole role){
|
||||
this.homelandRole = role;
|
||||
refreshRoles();
|
||||
updateAttributes();
|
||||
}
|
||||
|
||||
@ -130,7 +170,9 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
}
|
||||
|
||||
public void setGroupMember(long groupId, OvertakeGroupRole role){
|
||||
|
||||
this.groupId = groupId;
|
||||
this.overtakeGroupRole = role;
|
||||
refreshRoles();
|
||||
}
|
||||
|
||||
public OvertakeGroupRole getGroupRole(){
|
||||
@ -166,11 +208,11 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
|
||||
// ENDERMAN METHODS
|
||||
|
||||
protected boolean teleportRandomly(){
|
||||
private boolean teleportRandomly(){
|
||||
return teleportTo(posX+(rand.nextDouble()-0.5D)*64D,posY+(rand.nextInt(64)-32),posZ+(rand.nextDouble()-0.5D)*64D);
|
||||
}
|
||||
|
||||
protected boolean teleportToEntity(Entity entity){
|
||||
private boolean teleportToEntity(Entity entity){
|
||||
Vec3 vec = Vec3.createVectorHelper(posX-entity.posX,boundingBox.minY+(height/2F)-entity.posY+entity.getEyeHeight(),posZ-entity.posZ).normalize();
|
||||
double newX = posX+(rand.nextDouble()-0.5D)*8D-vec.xCoord*16D;
|
||||
double newY = posY+(rand.nextInt(16)-8)-vec.yCoord*16D;
|
||||
@ -178,7 +220,7 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
return this.teleportTo(newX,newY,newZ);
|
||||
}
|
||||
|
||||
protected boolean teleportTo(double x, double y, double z){
|
||||
private boolean teleportTo(double x, double y, double z){
|
||||
if (!canTeleport())return false;
|
||||
|
||||
double oldX = posX, oldY = posY, oldZ = posZ;
|
||||
@ -228,6 +270,18 @@ public class EntityMobHomelandEnderman extends EntityMob implements IEndermanRen
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPlayerStaringIntoEyes(EntityPlayer player){
|
||||
ItemStack is = player.inventory.armorInventory[3];
|
||||
|
||||
if (is != null && is.getItem() == Item.getItemFromBlock(Blocks.pumpkin))return false;
|
||||
else{
|
||||
Vec3 playerLook = player.getLook(1F).normalize();
|
||||
Vec3 eyeVecDiff = Vec3.createVectorHelper(posX-player.posX,boundingBox.minY+(height/2F)-(player.posY+player.getEyeHeight()),posZ-player.posZ);
|
||||
double eyeVecLen = eyeVecDiff.lengthVector();
|
||||
return playerLook.dotProduct(eyeVecDiff.normalize()) > 1D-0.025D/eyeVecLen && player.canEntityBeSeen(this);
|
||||
}
|
||||
}
|
||||
|
||||
// OVERRIDDEN METHODS
|
||||
|
||||
@Override
|
||||
|
@ -29,6 +29,10 @@ public class EntityTechnicalBiomeInteraction extends Entity{
|
||||
if (!worldObj.isRemote)interaction.update();
|
||||
}
|
||||
|
||||
public AbstractBiomeInteraction getInteraction(){
|
||||
return interaction;
|
||||
}
|
||||
|
||||
public Class<? extends AbstractBiomeInteraction> getInteractionType(){
|
||||
return interaction != null ? interaction.getClass() : null;
|
||||
}
|
||||
|
@ -26,15 +26,21 @@ public final class HomelandEndermen{
|
||||
}
|
||||
|
||||
public static boolean isOvertakeHappening(EntityMobHomelandEnderman source){
|
||||
return getOvertakeGroup(source) != -1;
|
||||
}
|
||||
|
||||
public static long getOvertakeGroup(EntityMobHomelandEnderman source){
|
||||
List<EntityTechnicalBiomeInteraction> list = source.worldObj.getEntitiesWithinAABB(EntityTechnicalBiomeInteraction.class,source.boundingBox.expand(260D,128D,260D));
|
||||
|
||||
if (!list.isEmpty()){
|
||||
for(EntityTechnicalBiomeInteraction entity:list){
|
||||
if (entity.getInteractionType() == BiomeInteractionEnchantedIsland.InteractionOvertake.class && entity.ticksExisted > 2)return true;
|
||||
if (entity.getInteractionType() == BiomeInteractionEnchantedIsland.InteractionOvertake.class && entity.ticksExisted > 2){
|
||||
return ((BiomeInteractionEnchantedIsland.InteractionOvertake)entity.getInteraction()).groupId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static List<EntityMobHomelandEnderman> getByHomelandRole(EntityMobHomelandEnderman source, HomelandRole role){
|
||||
|
@ -6,6 +6,8 @@ import chylex.hee.world.structure.island.biome.data.AbstractBiomeInteraction;
|
||||
|
||||
public class BiomeInteractionEnchantedIsland{
|
||||
public static class InteractionOvertake extends AbstractBiomeInteraction{
|
||||
public long groupId;
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
List<EntityMobHomelandEnderman> endermen = world.getEntitiesWithinAABB(EntityMobHomelandEnderman.class,getIslandBoundingBox());
|
||||
|
Loading…
Reference in New Issue
Block a user