mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
Fixed broken logic in collector/pool position caching that caused flowers to bind to the wrong collector or pool thanks to chunkloading,
This commit is contained in:
1 parent
4a7e09ff3a
commit
d063941167
3 files changed
+115
-107
No files matched your search
@@ -91,116 +91,120 @@ public class SubTileFunctional extends SubTileEntity {
|
||||
if(linkedPool == null) {
|
||||
needsNew = true;
|
||||
|
||||
if(cachedPoolCoordinates != null && supertile.getWorldObj().blockExists(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ)) {
|
||||
TileEntity tileAt = supertile.getWorldObj().getTileEntity(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ);
|
||||
if(tileAt != null && tileAt instanceof IManaPool) {
|
||||
linkedPool = tileAt;
|
||||
needsNew = false;
|
||||
if(cachedPoolCoordinates != null) {
|
||||
needsNew = false;
|
||||
if(supertile.getWorldObj().blockExists(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ)) {
|
||||
needsNew = true;
|
||||
TileEntity tileAt = supertile.getWorldObj().getTileEntity(cachedPoolCoordinates.posX, cachedPoolCoordinates.posY, cachedPoolCoordinates.posZ);
|
||||
if(tileAt != null && tileAt instanceof IManaPool) {
|
||||
linkedPool = tileAt;
|
||||
needsNew = false;
|
||||
}
|
||||
cachedPoolCoordinates = null;
|
||||
}
|
||||
cachedPoolCoordinates = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(!needsNew) {
|
||||
TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord);
|
||||
if(!(tileAt instanceof IManaPool)) {
|
||||
linkedPool = null;
|
||||
needsNew = true;
|
||||
} else linkedPool = tileAt;
|
||||
}
|
||||
|
||||
if(needsNew) {
|
||||
IManaNetwork network = BotaniaAPI.internalHandler.getManaNetworkInstance();
|
||||
int size = network.getAllPoolsInWorld(supertile.getWorldObj()).size();
|
||||
if(BotaniaAPI.internalHandler.shouldForceCheck() || size != sizeLastCheck) {
|
||||
ChunkCoordinates coords = new ChunkCoordinates(supertile.xCoord, supertile.yCoord, supertile.zCoord);
|
||||
linkedPool = network.getClosestPool(coords, supertile.getWorldObj(), range);
|
||||
sizeLastCheck = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addMana(int mana) {
|
||||
this.mana = Math.min(getMaxMana(), this.mana + mana);
|
||||
if(!needsNew) {
|
||||
TileEntity tileAt = supertile.getWorldObj().getTileEntity(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord);
|
||||
if(!(tileAt instanceof IManaPool)) {
|
||||
linkedPool = null;
|
||||
needsNew = true;
|
||||
} else linkedPool = tileAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return false;
|
||||
|
||||
knownMana = mana;
|
||||
player.worldObj.playSoundAtEntity(player, "botania:ding", 0.1F, 1F);
|
||||
|
||||
return super.onWanded(player, wand);
|
||||
}
|
||||
|
||||
public int getMaxMana() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromPacketNBT(NBTTagCompound cmp) {
|
||||
mana = cmp.getInteger(TAG_MANA);
|
||||
|
||||
int x = cmp.getInteger(TAG_POOL_X);
|
||||
int y = cmp.getInteger(TAG_POOL_Y);
|
||||
int z = cmp.getInteger(TAG_POOL_Z);
|
||||
|
||||
cachedPoolCoordinates = new ChunkCoordinates(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacketNBT(NBTTagCompound cmp) {
|
||||
cmp.setInteger(TAG_MANA, mana);
|
||||
|
||||
int x = linkedPool == null ? 0 : linkedPool.xCoord;
|
||||
int y = linkedPool == null ? -1 : linkedPool.yCoord;
|
||||
int z = linkedPool == null ? 0 : linkedPool.zCoord;
|
||||
|
||||
cmp.setInteger(TAG_POOL_X, x);
|
||||
cmp.setInteger(TAG_POOL_Y, y);
|
||||
cmp.setInteger(TAG_POOL_Z, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getBinding() {
|
||||
if(linkedPool == null)
|
||||
return null;
|
||||
return new ChunkCoordinates(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSelect(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindTo(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
|
||||
int range = 10;
|
||||
range *= range;
|
||||
|
||||
double dist = (x - supertile.xCoord) * (x - supertile.xCoord) + (y - supertile.yCoord) * (y - supertile.yCoord) + (z - supertile.zCoord) * (z - supertile.zCoord);
|
||||
if(range >= dist) {
|
||||
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
|
||||
if(tile instanceof IManaPool) {
|
||||
linkedPool = tile;
|
||||
return true;
|
||||
}
|
||||
if(needsNew) {
|
||||
IManaNetwork network = BotaniaAPI.internalHandler.getManaNetworkInstance();
|
||||
int size = network.getAllPoolsInWorld(supertile.getWorldObj()).size();
|
||||
if(BotaniaAPI.internalHandler.shouldForceCheck() || size != sizeLastCheck) {
|
||||
ChunkCoordinates coords = new ChunkCoordinates(supertile.xCoord, supertile.yCoord, supertile.zCoord);
|
||||
linkedPool = network.getClosestPool(coords, supertile.getWorldObj(), range);
|
||||
sizeLastCheck = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addMana(int mana) {
|
||||
this.mana = Math.min(getMaxMana(), this.mana + mana);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onWanded(EntityPlayer player, ItemStack wand) {
|
||||
if(player == null)
|
||||
return false;
|
||||
|
||||
knownMana = mana;
|
||||
player.worldObj.playSoundAtEntity(player, "botania:ding", 0.1F, 1F);
|
||||
|
||||
return super.onWanded(player, wand);
|
||||
}
|
||||
|
||||
public int getMaxMana() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return 0xFFFFFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromPacketNBT(NBTTagCompound cmp) {
|
||||
mana = cmp.getInteger(TAG_MANA);
|
||||
|
||||
int x = cmp.getInteger(TAG_POOL_X);
|
||||
int y = cmp.getInteger(TAG_POOL_Y);
|
||||
int z = cmp.getInteger(TAG_POOL_Z);
|
||||
|
||||
cachedPoolCoordinates = new ChunkCoordinates(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToPacketNBT(NBTTagCompound cmp) {
|
||||
cmp.setInteger(TAG_MANA, mana);
|
||||
|
||||
int x = linkedPool == null ? 0 : linkedPool.xCoord;
|
||||
int y = linkedPool == null ? -1 : linkedPool.yCoord;
|
||||
int z = linkedPool == null ? 0 : linkedPool.zCoord;
|
||||
|
||||
cmp.setInteger(TAG_POOL_X, x);
|
||||
cmp.setInteger(TAG_POOL_Y, y);
|
||||
cmp.setInteger(TAG_POOL_Z, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getBinding() {
|
||||
if(linkedPool == null)
|
||||
return null;
|
||||
return new ChunkCoordinates(linkedPool.xCoord, linkedPool.yCoord, linkedPool.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSelect(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindTo(EntityPlayer player, ItemStack wand, int x, int y, int z, int side) {
|
||||
int range = 10;
|
||||
range *= range;
|
||||
|
||||
double dist = (x - supertile.xCoord) * (x - supertile.xCoord) + (y - supertile.yCoord) * (y - supertile.yCoord) + (z - supertile.zCoord) * (z - supertile.zCoord);
|
||||
if(range >= dist) {
|
||||
TileEntity tile = player.worldObj.getTileEntity(x, y, z);
|
||||
if(tile instanceof IManaPool) {
|
||||
linkedPool = tile;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHUD(Minecraft mc, ScaledResolution res) {
|
||||
String name = StatCollector.translateToLocal("tile.botania:flower." + getUnlocalizedName() + ".name");
|
||||
int color = getColor();
|
||||
BotaniaAPI.internalHandler.drawSimpleManaHUD(color, knownMana, getMaxMana(), name, res);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHUD(Minecraft mc, ScaledResolution res) {
|
||||
String name = StatCollector.translateToLocal("tile.botania:flower." + getUnlocalizedName() + ".name");
|
||||
int color = getColor();
|
||||
BotaniaAPI.internalHandler.drawSimpleManaHUD(color, knownMana, getMaxMana(), name, res);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user