Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

GetEntitiesWithinAABBExludingEntity is not returning entities within boundingbox


Recommended Posts

    I am trying to get the entities within the target entity of the same type to compare variables to affect gameplay

I know for a fact there are other entities within it bounding box yet not printing the message n the ide console.

this is my code

 package src.IVWeather.entity;

import java.util.List;

import src.IVWeather.biome.BiomeTemperature;
import src.IVWeather.block.BlockFlyingBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.effect.EntityWeatherEffect;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeDecorator;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import src.IVWeather.*;

public class EntityWeatherAirmass extends WeatherEntity{

public Vaccume vaccum;
public float temperature;
public float maxGramsOfWaterHoldable;
public float currentGramsOfWaterInAir;
BiomeTemperature BiomeTemp;
public float evaporationrate;
public float dewpoint;
int time;
double droplesize;
boolean rainProcess;
double yboundingBoxERatePerTick;
public boolean eventFlag;
List precipitationCunkList;
public BiomeTemperature bt;
protected double GreaterTemp;
protected TempCategory tc;

public EntityWeatherAirmass(World thisworld) {
	super(thisworld);
}

public TempCategory getTempCategory() {
	return tc;
}

public EntityWeatherAirmass(World arg0, float par1, double x, double z, double ddY, float setx, float setz) {
	super(arg0);
	this.setSize(setx, setz);
	this.temperature = par1;
	this.currentGramsOfWaterInAir =  evaporationrate;
	this.maxGramsOfWaterHoldable = .1580888888888888f * (temperature * 50);
	this.humidity = (this.currentGramsOfWaterInAir * 100) / this.maxGramsOfWaterHoldable;
   int time = 0;
   droplesize = 0;
   					
   				this.posX = x;
   				this.posZ = z;
   				this.posY = ddY;
   				
   				this.CyclePeriod = IVWeather.startCycle;
}

public float gethumidity() {
return humidity;
}

public boolean canBeCollidedWith() {
return true;

}

boolean flerg;
private List collidingBoundingWeather;
public float AverageHighLow;
public float CycleExtremeityMaxT;
public int CyclePeriod;
private boolean Active;
private boolean Declining;
public boolean cycloneFlag;

public void onUpdate() {

System.out.println("UPDATING AIRMASS;");

AxisAlignedBB boundingBox = this.boundingBox;
BiomeGenBase Biom = worldObj.getBiomeGenForCoords((int)Math.floor(this.posX), (int)Math.floor(this.posZ));
if (IVWeather.Seasonalchanges)
    {
	System.out.println("SesonalChanges Accepted");

      this.AverageHighLow = (Biom.temperature + 0.4F);
      
      if (this.AverageHighLow > 2.0F) {
        this.AverageHighLow = 2.0F;
        System.out.println("Too high Average High-Low Temp, Reseting to 2.0");
      }
      
      this.CycleExtremeityMaxT = (Biom.temperature + 0.6F);
      
      if (this.CycleExtremeityMaxT > 2.1F) {
        this.CycleExtremeityMaxT = 2.1F;
        System.out.println("Maximum Temps too High, Reseting to 2.1");
      }
        float par1;
        
        if (IVWeather.Fluc)
        {
        	System.out.println("Fluc Accepted");
          par1 = (this.CycleExtremeityMaxT - Biom.temperature) / IVWeather.WeatherPatternMaxD;
        }
        else
        {
          par1 = this.AverageHighLow;
          if (this.CyclePeriod == 1) {
            par1 = this.AverageHighLow;
          } else {
            par1 = -this.AverageHighLow;
          }
        }
        if ((this.CyclePeriod == 1) && (this.Active == true)) {
          Biom.temperature += par1;
          System.out.println("Cycle Active; Warm Cycle");
        }
        if ((this.CyclePeriod == 2) && (!this.Declining) && (this.Active == true)) {
          Biom.temperature += par1;
          System.out.println("Cycle Active; Cold Cycle");
        }
        if ((Biom.temperature == this.CycleExtremeityMaxT) || (Biom.temperature == -this.CycleExtremeityMaxT))
        {
          this.Declining = true;
          
          System.out.println("Now Declining");
        }
        else
        {
          this.Declining = false;
        }
        
        if ((this.Declining == true) && (this.Active == true)) {
          this.CycleExtremeityMaxT -= par1;
        }
      }else{
    	  System.out.println("SeasonalChanges Declined");
      }

double prevPosY = this.posY;
double cbiomeTemp = Biom.temperature;
List BlockList = this.collidingBoundingWeather;
List iiiiiii = this.collidingBoundingWeather;

if(BlockList != null) {

	BlockList.clear();

}
if(iiiiiii != null) {
	iiiiiii.clear();

}
double d0 = .25;
			  List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(d0, d0, d0));
if(list !=null) {
	System.out.println("list is not null");
}
  for (int j2 = 0; j2 < list.size(); j2++)
  {
    Entity entity = ((Entity)list.get(j2));
    
    if(entity instanceof EntityWeatherAirmass){
    	System.out.println("Adding entity to list");
    	iiiiiii.add(entity);
    }
double prevY = this.posY;
double prevMY= this.boundingBox.maxY;

	if(iiiiiii != null) {
		System.out.println("List located Other Airmasses");

for(int u =0; u < iiiiiii.size(); u++) {

	EntityWeatherAirmass e = (EntityWeatherAirmass) iiiiiii.get(u);

	this.GreaterTemp = this.temperature - e.temperature;

	if(!cycloneFlag) {

	 if(e.temperature < this.temperature){

		tc = TempCategory.WARM;
		System.out.println("now WARM");
	 }else if(e.temperature > this.temperature){

		tc = TempCategory.COLD;
		System.out.println("now COLD");
	 }else if(this.temperature > e.temperature && this.humidity < e.humidity) {

		tc = TempCategory.HOT;
		System.out.println("now HOT");
	 }
	}



	boolean eAirMassTSupport = false;
	boolean thisAirMassTSupport = false;

	double distance = 0;
	 double distance2 = 0;
	 distance = Math.abs(this.temperature - cbiomeTemp);
	 distance2 = Math.abs(e.temperature - cbiomeTemp);

	 if(distance > distance2) {
		 thisAirMassTSupport = true;
		 System.out.println("recievving t-support");
	 }

	 if(tc == TempCategory.WARM) {
		if(thisAirMassTSupport){
			this.boundingBox.expand(0, this.temperature - cbiomeTemp + 4, 0);
				System.out.println("Expanding");
		}
		else
		{
		 this.motionY = ((this.temperature - e.temperature) / 4);
	}
	}

	if(tc == TempCategory.COLD) {
		if(this.getCollidingBlockWithWE(this, this.boundingBox).size() < 150 && this.boundingBox.minX <= 55) {
		this.motionY = ((this.temperature - e.temperature) / 4);
		}
	}
	if(tc == TempCategory.HOT)  {
		this.motionY = ((this.temperature - e.temperature) / 3);
		if(e.humidity - this.humidity > this.humidity + (this.humidity / 6)) {
			flerg = true;
		}
	}

	if(flerg == true) {
		this.humidity = this.humidity + (float) .001;
	}
	if(list.size() == 0) {
		if(this.temperature > cbiomeTemp) {
			tc = TempCategory.WARM;
		}else{
			tc = TempCategory.COLD;
		}
		this.boundingBox.expand(15, 0, 15);
		if(this.boundingBox.maxY < 3000) {
			this.boundingBox.expand(0, 15, 0);
			if(tc == TempCategory.WARM && this.boundingBox.maxY > (Biom.temperature - (this.boundingBox.maxY / 700))) {

			}
		}
	}
		this.evaporationrate = (float) (Biom.temperature);

	this.currentGramsOfWaterInAir = maxGramsOfWaterHoldable / evaporationrate; 
	this.maxGramsOfWaterHoldable = .1580888888888888f * (temperature * 50);
	this.humidity = (this.currentGramsOfWaterInAir * 100) / this.maxGramsOfWaterHoldable;
   dewpoint = bt.getDewPoint(humidity, this.temperature);
   
   yboundingBoxERatePerTick = prevMY - prevY;
   
   if(this.temperature <= dewpoint) {
	   this.rainProcess = true;
	   if(droplesize <= 0) {
	   droplesize = .0000000001;
	  }
	 droplesize =  droplesize  * time;
   
	  int gravity = 18000;
  
   if(droplesize > (gravity + (this.yboundingBoxERatePerTick ) * 2.) {
	   double maxx = this.boundingBox.maxX;
	   double minx = this.boundingBox.minX;
	   double maxz = this.boundingBox.maxZ;
	   double minz = this.boundingBox.minZ;
	   
	   for(int o = (int) minx; o < maxx; o++) {
		   for(int p = (int) minz; p < maxz; p++) {
		  
			  Chunk C = worldObj.getChunkFromBlockCoords(o, p);

			  this.precipitationCunkList.clear();
			  
			  this.precipitationCunkList.add(C);
			  if(this.precipitationCunkList != null) {
				  System.out.println("Precipitation");
			  }else{
				  System.out.println("No Rain List");
			  }
		   }
	   }
	   
   }
   }
   
   double velocity = (this.motionX + this.motionY + this.motionZ )/3;
   		
   if(this.humidity < e.humidity) {
	   this.humidity = this.humidity + ((e.humidity - this.humidity)/50);
   }else if(this.humidity < bt.getBiomeTemp(Biom)) {
	   this.humidity = this.humidity + ((e.humidity - bt.getBiomeTemp(Biom))/50);
   }
   

	  }
}else{
			System.err.println("No Airmasses found");


				this.motionY = Biom.temperature - this.temperature;

		}
  	}
  }



protected void entityInit() {



}

public List collidingAirmasses(EntityWeatherAirmass ewa) {
List list = this.collidingBoundingWeather;
list.clear();
  int i = MathHelper.floor_double(ewa.posX + this.boundingBox.minX);
  int j = MathHelper.floor_double(ewa.posX + this.boundingBox.maxX + 1.0D);
  int k = MathHelper.floor_double(ewa.posY + this.boundingBox.minY);
  int l = MathHelper.floor_double(ewa.posY + this.boundingBox.maxY + 1.0D);
  int i1 = MathHelper.floor_double(ewa.posZ + this.boundingBox.minZ);
  int j1 = MathHelper.floor_double(ewa.posX + this.boundingBox.maxZ + 1.0D);
  double d0 = 0.25D;
  System.out.println(i);
  System.out.println(j);
  System.out.println(k);
  System.out.println(l);
  System.out.println(i1);
  System.out.println(j1);
  for(int q = i; q < j; q++) {
	  for(int w = k; k < l; k++) {
		  for(int f = i1; f < j1; f++) {

			  Block block = worldObj.getBlock(q, w, f);
			  
			  List list2 = worldObj.getEntitiesWithinAABBExcludingEntity(this, this.boundingBox.expand(d0, d0, d0));
  
  for (int j2 = 0; j2 < list2.size(); j2++)
  {
    Entity entity = ((Entity)list2.get(j2));
    
    if(entity instanceof EntityWeatherAirmass){
    
    	list.add(entity);
    }
  }
}
   }
  }
  return list;
}

@Override
protected void readEntityFromNBT(NBTTagCompound arg0) {

}

@Override
protected void writeEntityToNBT(NBTTagCompound arg0) {
// TODO Auto-generated method stub

}

public enum TempCategory {

WARM, COLD, HOT, COOL;

}

}

 

thank you for reading.

Link to post
Share on other sites

Though I can't tell immediately with the code you provided, but it could be that the chunk you are checking isn't loaded. worldObj.getEntitiesWithinAABB checks whether or not the chunk is loaded before it determines which entities are within the specified area. Double check that the chunk is loaded by using 'worlObj.chunkExists(chunkCoordX, chunkCoordY)'.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.