Add VisAuraProvider. Placeholder texture, placeholder name, placeholder EVERYTHING.

Add crude search mechanism for Aura Providers to Magic Apiary.
This commit is contained in:
MysteriousAges committed 2015-03-21 18:20:45 -07:00
1 parent cc987d6ac8
commit 46cb2cb95a
8 files changed
+397 -12

No files matched your search

@@ -1,9 +1,12 @@
package magicbees.tileentity;
import magicbees.api.bees.IMagicApiaryAuraProvider;
import magicbees.bees.BeeManager;
import magicbees.main.CommonProxy;
import magicbees.main.MagicBees;
import magicbees.main.utils.ChunkCoords;
import magicbees.main.utils.ItemStackUtils;
import magicbees.main.utils.LogHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
@@ -43,17 +46,28 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
private static final int SLOT_PRODUCTS_START = 5;
private static final int SLOT_PRODUCTS_COUNT = 7;
private final IBeekeepingLogic logic;
private static final int AURAPROVIDER_SEARCH_RADIUS = 6;
private IBeekeepingLogic logic;
private boolean hasAuraProvider = false;
private IMagicApiaryAuraProvider auraProvider;
private ChunkCoords auraProviderPosition;
private BiomeGenBase biome;
private int displayHealthMax = 0;
private int displayHealth = 0;
private boolean init = false;
private static final int FLAG_MUTATIONCHARGE = 1 << 0;
private static final int FLAG_DEATHCHARGE = 1 << 1;
private static final int FLAG_PRODUCTION = 1 << 2;
private int flags;
private IErrorState errorState = ErrorStateRegistry.getErrorState("ok");
private ItemStack[] items;
public TileEntityMagicApiary(){
flags = 0;
items = new ItemStack[12];
logic = BeeManager.beeRoot.createBeekeepingLogic(this);
}
@@ -482,13 +496,16 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
items.appendTag(item);
}
}
compound.setTag("Items", items);
compound.setInteger("BiomeId", biome.biomeID);
if (logic != null) {
logic.writeToNBT(compound);
}
compound.setTag("Items", items);
ChunkCoords.writeToNBT(this.auraProviderPosition, compound);
compound.setInteger("flags", this.flags);
}
@Override
@@ -509,6 +526,9 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
int biomeId = compound.getInteger("BiomeId");
biome = BiomeGenBase.getBiome(biomeId);
logic.readFromNBT(compound);
this.auraProviderPosition = ChunkCoords.readFromNBT(compound);
this.flags = compound.getInteger("flags");
}
public float getExactTemperature() {
@@ -556,6 +576,13 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
}
public void updateServerSide() {
if (!this.hasAuraProvider) {
findAuraProvider();
}
else {
updateAuraProvider();
}
logic.update();
IBee queen = logic.getQueen();
@@ -602,4 +629,86 @@ public class TileEntityMagicApiary extends TileEntity implements ISidedInventory
public boolean isMutationBoosted() {
return false;
}
private void updateAuraProvider() {
}
private static final int MAX_BLOCKS_SEARCH_PER_CHECK = (AURAPROVIDER_SEARCH_RADIUS * 2 + 1) * 2;
private void findAuraProvider() {
if (worldObj.getTotalWorldTime() % 10 != 0) {
return;
}
if (this.auraProviderPosition == null) {
this.auraProviderPosition = new ChunkCoords(0,
xCoord - AURAPROVIDER_SEARCH_RADIUS,
(yCoord - AURAPROVIDER_SEARCH_RADIUS >= 0) ? yCoord - AURAPROVIDER_SEARCH_RADIUS : 0,
zCoord - AURAPROVIDER_SEARCH_RADIUS);
LogHelper.info("Apiary starting search");
}
else {
// Will end up here after loading from save with a valid auraProvider.
if (locationHasAuraProvider(auraProviderPosition.x, auraProviderPosition.y, auraProviderPosition.z)) {
this.auraProvider = (IMagicApiaryAuraProvider)(worldObj.getTileEntity(auraProviderPosition.x,
auraProviderPosition.y,
auraProviderPosition.x));
this.hasAuraProvider = true;
return;
}
}
int blocksCounted = 0;
int x = auraProviderPosition.x;
int y = auraProviderPosition.y;
int z = auraProviderPosition.z;
while ((y < yCoord + AURAPROVIDER_SEARCH_RADIUS) && blocksCounted < MAX_BLOCKS_SEARCH_PER_CHECK) {
while ((z < zCoord + AURAPROVIDER_SEARCH_RADIUS) && blocksCounted < MAX_BLOCKS_SEARCH_PER_CHECK) {
while ((x < xCoord + AURAPROVIDER_SEARCH_RADIUS) && blocksCounted < MAX_BLOCKS_SEARCH_PER_CHECK) {
if (locationHasAuraProvider(x, y, z)) {
LogHelper.info("Apiary found aura provider!");
this.auraProvider = (IMagicApiaryAuraProvider)(worldObj.getTileEntity(x, y, z));
this.hasAuraProvider = true;
saveAuraProviderPosition(x, y, z);
return;
}
++blocksCounted;
++x;
}
if (blocksCounted < MAX_BLOCKS_SEARCH_PER_CHECK) {
++z;
x = xCoord - AURAPROVIDER_SEARCH_RADIUS;
}
}
if (blocksCounted < MAX_BLOCKS_SEARCH_PER_CHECK) {
++y;
z = zCoord - AURAPROVIDER_SEARCH_RADIUS;
}
}
LogHelper.info("Apiary suspending search");
if (auraProvider == null) {
saveAuraProviderPosition(x, y, z);
if (auraProviderPosition.y >= yCoord + AURAPROVIDER_SEARCH_RADIUS) {
LogHelper.info("Apiary finished scanning blocks; did not find aura provider.");
this.auraProviderPosition = null;
return;
}
}
}
private void saveAuraProviderPosition(int x, int y, int z) {
auraProviderPosition = new ChunkCoords(auraProviderPosition.dimension, x, y, z);
}
private boolean locationHasAuraProvider(int x, int y, int z) {
TileEntity entity = worldObj.getTileEntity(x, y, z);
if (entity != null && entity instanceof IMagicApiaryAuraProvider) {
return true;
}
return false;
}
}
@@ -0,0 +1,112 @@
package magicbees.tileentity;
import magicbees.api.bees.IMagicApiaryAuraProvider;
import magicbees.main.CommonProxy;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.visnet.VisNetHandler;
public class TileEntityVisAuraProvider extends TileEntity implements IMagicApiaryAuraProvider {
public static final String tileEntityName = CommonProxy.DOMAIN + ".visAuraProvider";
private static final int MAX_CHARGES = 10;
int currentMutationCharges;
int currentDeathCharges;
int currentProductionCharges;
private static final int VIS_PER_CHARGE = 10;
private static Aspect ASPECT_MUTATION = Aspect.WATER;
private static Aspect ASPECT_DEATH = Aspect.ENTROPY;
private static Aspect ASPECT_PRODUCTION = Aspect.AIR;
int currentMutationVis;
int currentDeathVis;
int currentProductionVis;
public TileEntityVisAuraProvider() {
super();
}
@Override
public void updateEntity() {
long modTickRate = worldObj.getTotalWorldTime();
if (currentProductionCharges < MAX_CHARGES && modTickRate % 3 == 0) {
currentProductionVis += getVisFromNet(ASPECT_PRODUCTION);
if (currentProductionVis >= VIS_PER_CHARGE) {
currentProductionVis -= VIS_PER_CHARGE;
++currentProductionCharges;
}
}
if (currentDeathCharges < MAX_CHARGES && modTickRate % 5 == 0) {
currentDeathVis += getVisFromNet(ASPECT_DEATH);
if (currentDeathVis >= VIS_PER_CHARGE) {
currentDeathVis -= VIS_PER_CHARGE;
++currentDeathCharges;
}
}
if (currentMutationCharges < MAX_CHARGES && modTickRate % 11 == 0) {
currentMutationCharges += getVisFromNet(ASPECT_MUTATION);
if (currentMutationCharges >= VIS_PER_CHARGE) {
currentMutationCharges -= VIS_PER_CHARGE;
++currentMutationCharges;
}
}
}
private int getVisFromNet(Aspect aspect) {
return VisNetHandler.drainVis(worldObj, xCoord, yCoord, zCoord, aspect, 1);
}
@Override
public boolean getMutationCharge() {
if (this.currentMutationCharges > 0) {
--this.currentMutationCharges;
return true;
}
return false;
}
@Override
public boolean getDeathRateCharge() {
if (this.currentDeathCharges > 0) {
--this.currentDeathCharges;
return true;
}
return false;
}
@Override
public boolean getProductionCharge() {
if (this.currentProductionCharges > 0) {
--this.currentProductionCharges;
return true;
}
return false;
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
this.currentMutationCharges = tag.getInteger("mutationCharges");
this.currentMutationVis = tag.getInteger("mutationVis");
this.currentDeathCharges = tag.getInteger("deathCharges");
this.currentDeathVis = tag.getInteger("deathVis");
this.currentProductionCharges = tag.getInteger("productionCharges");
this.currentProductionVis = tag.getInteger("productionVis");
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setInteger("mutationCharges", currentMutationCharges);
tag.setInteger("mutationVis", currentMutationVis);
tag.setInteger("deathCharges", currentDeathCharges);
tag.setInteger("deathVis", currentDeathVis);
tag.setInteger("productionCharges", currentProductionCharges);
tag.setInteger("productionVis", currentProductionVis);
}
}