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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • So I had no clue what topic to put this under because its not really modding with forge but modding forge itself. So I have terrain generation mods that are only server side and Bungeecord that has Geyser packet translator so people on bedrock edition can play as well, but when a bedrock player connects it gets a unknown packet error. I tested the proxy on a Spigot server verifying it was forge. With no mods installed I still get the error. I got a wireshark log of it all and I found the packet where it aborts the connection due to the invalid packet but I have no clue how to stop it. When I still had the mods installed I disabled the forge handshake protocol but it did not fix the issue. If you know what part of forge is doing this or a way to fix it all together that would be awesome. I know modifying forge can end really baddy (definitely the handshake protocol) but I think that is my only fix here. Im open to any suggestions tho. I have run out of ideas to fix it so any help would be nice. Also it seems the packet id causing the connection error is 0xFE but im not sure cause the client also sends back a packet with that ID. I have a whole bunch of info collected so if you need any more information on the issue, I willing to give it, just not the ips on the wireshark log.
    • Okay, I got it working correctly now, but I'm not sure how to make it work with multiple blocks.   My Block Code:   package expanded.blocks; import javax.annotation.Nullable; import expanded.VanillaBuildingBlocks; import net.minecraft.block.BlockState; import net.minecraft.block.RotatedPillarBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.ToolType; public class CustomLog extends RotatedPillarBlock {            public CustomLog(Properties properties) {         super(properties);     }      @Override     @Nullable     public BlockState getToolModifiedState(BlockState state, World world, BlockPos pos, PlayerEntity player, ItemStack stack, ToolType toolType) {         return toolType == ToolType.AXE ? VanillaBuildingBlocks.acacia_log.defaultBlockState() : null;     } }
    • ? Registering the block and overriding a function inside the class are two completely different things
    • Ya but I'm not sure how I would actually add/implement it into the class correctly, and then registering the block correctly in my register class.
    • This tutorial from 1.12.2 is as easy as anyone could possibly explain it, it hasn't changed much til now except some slight changes here and there for you to figure out, it's pretty straightforward (https://www.planetminecraft.com/blog/forge-tutorial-capability-system/). Obviously instead of mana you'd just replace it with whatever else you're doing. All a capability is in essence is the ability to serialize/deserialize standard data types to an entity. When the player dies the game creates a new instance of a PlayerEntity object so your data won't automatically "transfer" over to that new object unless as you say, you copy the data over in an event hook. After you have this set up, if you want to access the data you store in player capabilities you create a class with a static get function that retrieves it.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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