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

@@ -0,0 +1,37 @@
package magicbees.api.bees;
/**
* Allows a tile entity to provide a Magic Apiary with 'aura' to boost bee production, mutation rate,
* or decrease bee lifespan.
*
* @author MysteriousAges
*/
public interface IMagicApiaryAuraProvider {
/**
* Requests a mutation charge from the aura provider. If true is returned, the
* aura provider should decrement its internal charge by one. If there are no
* charges remaining, it should return false.
*
* @return True if a charge is given; false otherwise.
*/
public boolean getMutationCharge();
/**
* Requests a mutation charge from the aura provider. If true is returned, the
* aura provider should decrement its internal charge by one. If there are no
* charges remaining, it should return false.
*
* @return True if a charge is given; false otherwise.
*/
public boolean getDeathRateCharge();
/**
* Requests a mutation charge from the aura provider. If true is returned, the
* aura provider should decrement its internal charge by one. If there are no
* charges remaining, it should return false.
*
* @return True if a charge is given; false otherwise.
*/
public boolean getProductionCharge();
}
@@ -0,0 +1,42 @@
package magicbees.block;
import magicbees.main.utils.TabMagicBees;
import magicbees.tileentity.TileEntityVisAuraProvider;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class BlockVisAuraProvider extends BlockContainer {
public BlockVisAuraProvider() {
super(Material.glass);
this.setCreativeTab(TabMagicBees.tabMagicBees);
this.setBlockName("visAuraProvider");
this.setHardness(0.5f);
this.setResistance(1.5f);
this.setBlockBounds(0.25f, 0f, 0.25f, 0.75f, 0.5f, 0.75f);
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
public TileEntity createNewTileEntity(World world, int metadata) {
return new TileEntityVisAuraProvider();
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = Blocks.glass.getIcon(0, 0);
}
}
+25 -10
View File
@@ -3,11 +3,12 @@ package magicbees.main;
import java.io.File;
import java.lang.reflect.Field;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import magicbees.block.*;
import magicbees.block.BlockEffectJar;
import magicbees.block.BlockHive;
import magicbees.block.BlockMagicApiary;
import magicbees.block.BlockPlanks;
import magicbees.block.BlockVisAuraProvider;
import magicbees.block.BlockWoodSlab;
import magicbees.block.types.HiveType;
import magicbees.item.ItemCapsule;
import magicbees.item.ItemComb;
@@ -36,6 +37,7 @@ import magicbees.main.utils.compat.ThaumcraftHelper;
import magicbees.storage.BackpackDefinition;
import magicbees.tileentity.TileEntityEffectJar;
import magicbees.tileentity.TileEntityMagicApiary;
import magicbees.tileentity.TileEntityVisAuraProvider;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
@@ -47,6 +49,10 @@ import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import forestry.api.apiculture.BeeManager;
import forestry.api.storage.BackpackManager;
import forestry.api.storage.EnumBackpackType;
@@ -92,7 +98,8 @@ public class Config
public static BlockWoodSlab slabWoodFull;
public static BlockEffectJar effectJar;
public static BlockHive hive;
public static BlockMagicApiary thaumicApiary;
public static BlockMagicApiary magicApiary;
public static BlockVisAuraProvider visAuraProvider;
public static ItemComb combs;
public static ItemWax wax;
@@ -241,6 +248,8 @@ public class Config
setupEffectJar();
setupHives();
setupApiary();
setupThaumcraftBlocks();
}
public void setupItems()
@@ -391,8 +400,8 @@ public class Config
}
private void setupApiary() {
thaumicApiary = new BlockMagicApiary();
GameRegistry.registerBlock(thaumicApiary, "thaumicApiary");
magicApiary = new BlockMagicApiary();
GameRegistry.registerBlock(magicApiary, "magicApiary");
GameRegistry.registerTileEntity(TileEntityMagicApiary.class, TileEntityMagicApiary.tileEntityName);
}
@@ -495,13 +504,19 @@ public class Config
}
}
}
private void setupThaumcraftBlocks() {
if (ThaumcraftHelper.isActive()) {
visAuraProvider = new BlockVisAuraProvider();
GameRegistry.registerBlock(visAuraProvider, "visAuraProvider");
GameRegistry.registerTileEntity(TileEntityVisAuraProvider.class, "visAuraProvider");
}
}
private void setupThaumcraftItems() {
if (ThaumcraftHelper.isActive())
{
// Items
//solidFlux replaced by Thaumcraft's crystalized essentia.
//solidFlux = new ItemCrystalAspect();
}
}
@@ -14,6 +14,8 @@ import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent.MissingMapping;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
@@ -90,5 +92,14 @@ public class MagicBees
{
IMCManager.handle(event);
}
@Mod.EventHandler
public void handleMissingMapping(FMLMissingMappingsEvent event) {
for (MissingMapping mapping : event.get()) {
// TODO: ... maybe not this.
LogHelper.info(String.format("Missing mapping: %s - ignoring.", mapping.name));
mapping.ignore();
}
}
}
@@ -1,6 +1,7 @@
package magicbees.main.utils;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@@ -32,4 +33,61 @@ public class ChunkCoords
this.z = zCoord;
}
/**
* Adds chunk coords together & returns the result within the same dimension.
*/
public ChunkCoords add(ChunkCoords coords) {
return new ChunkCoords(coords.dimension, this.x + coords.x, this.y + coords.y, this.z + coords.z);
}
/**
* Subtracts chunk coords (a.subtract(b) == a - b) & returns the result within the same dimension.
*/
public ChunkCoords subtract(ChunkCoords coords) {
return new ChunkCoords(coords.dimension, this.x - coords.x, this.y - coords.y, this.z - coords.z);
}
/**
* Returns a new ChunkCoords in the specified dimension.
*/
public ChunkCoords inDimension(int dimId) {
return new ChunkCoords(dimId, x, y, z);
}
/**
* Returns a new ChunkCoords in the specified world.
*/
public ChunkCoords inDimension(World world) {
return new ChunkCoords(world.provider.dimensionId, x, y, z);
}
/**
* Writes obj to the given tag compound as a subtag. Writes nothing if obj is null.
*/
public static void writeToNBT(ChunkCoords obj, NBTTagCompound tagRoot) {
if (obj != null) {
NBTTagCompound coordsTag = new NBTTagCompound();
coordsTag.setInteger("dim", obj.dimension);
coordsTag.setInteger("xPos", obj.x);
coordsTag.setInteger("yPos", obj.y);
coordsTag.setInteger("zPos", obj.z);
tagRoot.setTag("chunkCoords", coordsTag);
}
}
/**
* Reads a ChunkCoords from an NBT tag. If no ChunkCoords subtag exists, returns null.
*/
public static ChunkCoords readFromNBT(NBTTagCompound tagRoot) {
if (tagRoot.hasKey("chunkCoords")) {
NBTTagCompound coordsTag = (NBTTagCompound)tagRoot.getTag("chunkCoords");
int dim = coordsTag.getInteger("dim");
int x = coordsTag.getInteger("xPos");
int y = coordsTag.getInteger("yPos");
int z = coordsTag.getInteger("zPos");
return new ChunkCoords(dim, x, y, z);
}
return null;
}
}
@@ -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);
}
}
@@ -12,6 +12,7 @@ item.moonDial.name=Jade Moon Dial
#Tiles
tile.effectJar.name=Bee Collector's Jar
tile.magicApiary.name=Magic Apiary
tile.visAuraProvider.name=Vis Apiary Booster
tile.hive.curious.name=Curious Hive
tile.hive.unusual.name=Unusual Hive
tile.hive.deep.name=Deep Hive