diff --git a/MODSRC/vazkii/botania/common/block/BlockRFGenerator.java b/MODSRC/vazkii/botania/common/block/BlockRFGenerator.java new file mode 100644 index 000000000..a4ad84687 --- /dev/null +++ b/MODSRC/vazkii/botania/common/block/BlockRFGenerator.java @@ -0,0 +1,53 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Aug 29, 2014, 9:51:58 PM (GMT)] + */ +package vazkii.botania.common.block; + +import cpw.mods.fml.common.Optional; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import vazkii.botania.api.lexicon.LexiconEntry; +import vazkii.botania.client.core.helper.IconHelper; +import vazkii.botania.common.block.tile.mana.TileDistributor; +import vazkii.botania.common.block.tile.mana.TileRFGenerator; +import vazkii.botania.common.lexicon.LexiconData; +import vazkii.botania.common.lib.LibBlockNames; + +public class BlockRFGenerator extends BlockModContainer { + + protected BlockRFGenerator() { + super(Material.rock); + setHardness(2.0F); + setResistance(10.0F); + setStepSound(soundTypeStone); + setBlockName(LibBlockNames.RF_GENERATOR); + } + + @Override + @Optional.Method(modid = "CoFHAPI") + public void onNeighborChange(IBlockAccess world, int x, int y, int z, int tileX, int tileY, int tileZ) { + TileEntity tile = world.getTileEntity(x, y, z); + if(tile != null && tile instanceof TileRFGenerator) + ((TileRFGenerator) tile).onNeighborTileChange(tileX, tileY, tileZ); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) { + return new TileRFGenerator(); + } + +} diff --git a/MODSRC/vazkii/botania/common/block/ModBlocks.java b/MODSRC/vazkii/botania/common/block/ModBlocks.java index 23c3ac86c..7436a2c05 100644 --- a/MODSRC/vazkii/botania/common/block/ModBlocks.java +++ b/MODSRC/vazkii/botania/common/block/ModBlocks.java @@ -120,6 +120,7 @@ import vazkii.botania.common.block.tile.mana.TileDistributor; import vazkii.botania.common.block.tile.mana.TileManaDetector; import vazkii.botania.common.block.tile.mana.TileManaVoid; import vazkii.botania.common.block.tile.mana.TilePool; +import vazkii.botania.common.block.tile.mana.TileRFGenerator; import vazkii.botania.common.block.tile.mana.TileSpreader; import vazkii.botania.common.block.tile.mana.TileTurntable; import vazkii.botania.common.core.handler.ConfigHandler; @@ -171,6 +172,7 @@ public final class ModBlocks { public static Block customBrick; public static Block enderEye; public static Block starfield; + public static Block rfGenerator; public static Block livingwoodStairs; public static Block livingwoodSlab; @@ -288,7 +290,8 @@ public final class ModBlocks { customBrick = new BlockCustomBrick(); enderEye = new BlockEnderEye(); starfield = new BlockStarfield(); - + rfGenerator = new BlockRFGenerator(); + livingwoodStairs = new BlockLivingwoodStairs(); livingwoodSlab = new BlockLivingwoodSlab(false); livingwoodSlabFull = new BlockLivingwoodSlab(true); @@ -465,6 +468,7 @@ public final class ModBlocks { registerTile(TileSpawnerClaw.class, LibBlockNames.SPAWNER_CLAW); registerTile(TileEnderEye.class, LibBlockNames.ENDER_EYE_BLOCK); registerTile(TileStarfield.class, LibBlockNames.STARFIELD); + registerTile(TileRFGenerator.class, LibBlockNames.RF_GENERATOR); BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_PUREDAISY, SubTilePureDaisy.class); BotaniaAPI.registerSubTile(LibBlockNames.SUBTILE_MANASTAR, SubTileManastar.class); diff --git a/MODSRC/vazkii/botania/common/block/tile/mana/TileRFGenerator.java b/MODSRC/vazkii/botania/common/block/tile/mana/TileRFGenerator.java new file mode 100644 index 000000000..5542d3105 --- /dev/null +++ b/MODSRC/vazkii/botania/common/block/tile/mana/TileRFGenerator.java @@ -0,0 +1,152 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Aug 29, 2014, 10:01:32 PM (GMT)] + */ +package vazkii.botania.common.block.tile.mana; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; +import vazkii.botania.api.mana.IManaReceiver; +import vazkii.botania.common.block.tile.TileMod; +import cofh.api.energy.IEnergyConnection; +import cofh.api.energy.IEnergyHandler; +import cpw.mods.fml.common.Optional; + +@Optional.Interface(iface = "cofh.api.energy.IEnergyConnection", modid = "CoFHAPI") +public class TileRFGenerator extends TileMod implements IManaReceiver, IEnergyConnection { + + private static final int MAX_MANA = 1280; + + private static final String TAG_MANA = "mana"; + + int mana = 0; + + // Thanks to skyboy for help with this cuz I'm a noob with RF + private IEnergyHandler[] handlerCache; + private boolean deadCache; + + @Override + @Optional.Method(modid = "CoFHAPI") + public void validate() { + super.validate(); + deadCache = true; + handlerCache = null; + } + + @Override + @Optional.Method(modid = "CoFHAPI") + public void updateEntity() { + super.updateEntity(); + if(!worldObj.isRemote) { + if(deadCache) + reCache(); + + int transfer = Math.min(mana, 160); + mana -= transfer; + mana += transmitEnergy(transfer); + } + } + + @Optional.Method(modid = "CoFHAPI") + protected final int transmitEnergy(int energy) { + if (handlerCache != null) + for(int i = handlerCache.length; i-- > 0;) { + IEnergyHandler tile = handlerCache[i]; + if (tile == null) + continue; + + ForgeDirection from = ForgeDirection.VALID_DIRECTIONS[i]; + if(tile.receiveEnergy(from, energy, true) > 0) + energy -= tile.receiveEnergy(from, energy * 10, false) / 10; + + if(energy <= 0) + return 0; + } + + return energy; + } + + @Optional.Method(modid = "CoFHAPI") + private void reCache() { + if(deadCache) { + for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) + onNeighborTileChange(xCoord + dir.offsetX, + yCoord + dir.offsetY, zCoord + dir.offsetZ); + deadCache = false; + } + } + + @Optional.Method(modid = "CoFHAPI") + public void onNeighborTileChange(int x, int y, int z) { + TileEntity tile = worldObj.getTileEntity(x, y, z); + + if(x < xCoord) + addCache(tile, 5); + else if(x > xCoord) + addCache(tile, 4); + else if(z < zCoord) + addCache(tile, 3); + else if(z > zCoord) + addCache(tile, 2); + else if(y < yCoord) + addCache(tile, 1); + else if(y > yCoord) + addCache(tile, 0); + } + + @Optional.Method(modid = "CoFHAPI") + private void addCache(TileEntity tile, int side) { + if(handlerCache != null) + handlerCache[side] = null; + + if(tile instanceof IEnergyHandler && ((IEnergyHandler)tile).canConnectEnergy(ForgeDirection.VALID_DIRECTIONS[side])) { + if(handlerCache == null) + handlerCache = new IEnergyHandler[6]; + handlerCache[side] = (IEnergyHandler)tile; + } + } + + @Override + public int getCurrentMana() { + return mana; + } + + @Override + public boolean isFull() { + return mana >= MAX_MANA; + } + + @Override + public void recieveMana(int mana) { + this.mana = Math.min(MAX_MANA, this.mana + mana); + } + + @Override + public boolean canRecieveManaFromBursts() { + return true; + } + + @Override + public void writeCustomNBT(NBTTagCompound cmp) { + cmp.setInteger(TAG_MANA, mana); + } + + @Override + public void readCustomNBT(NBTTagCompound cmp) { + mana = cmp.getInteger(TAG_MANA); + } + + @Override + public boolean canConnectEnergy(ForgeDirection from) { + return true; + } + +} diff --git a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java index e87ce991a..4b93dad51 100644 --- a/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java +++ b/MODSRC/vazkii/botania/common/core/BotaniaCreativeTab.java @@ -236,6 +236,7 @@ public final class BotaniaCreativeTab extends CreativeTabs { addBlock(ModBlocks.distributor); addBlock(ModBlocks.manaVoid); addBlock(ModBlocks.manaDetector); + addBlock(ModBlocks.rfGenerator); addBlock(ModBlocks.spreader); addBlock(ModBlocks.turntable); addItem(ModItems.spark); diff --git a/MODSRC/vazkii/botania/common/lib/LibBlockNames.java b/MODSRC/vazkii/botania/common/lib/LibBlockNames.java index 3d436e8a5..0f4d37c78 100644 --- a/MODSRC/vazkii/botania/common/lib/LibBlockNames.java +++ b/MODSRC/vazkii/botania/common/lib/LibBlockNames.java @@ -56,6 +56,7 @@ public final class LibBlockNames { public static final String CUSTOM_BRICK = "customBrick"; public static final String ENDER_EYE_BLOCK = "enderEyeBlock"; public static final String STARFIELD = "starfield"; + public static final String RF_GENERATOR = "rfGenerator"; public static final String SPECIAL_FLOWER_PREFIX = FLOWER + "."; diff --git a/apis/cofh/api/energy/IEnergyConnection.java b/apis/cofh/api/energy/IEnergyConnection.java new file mode 100644 index 000000000..fd2968537 --- /dev/null +++ b/apis/cofh/api/energy/IEnergyConnection.java @@ -0,0 +1,21 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not + * accept it; otherwise just use IEnergyHandler. + * + * Note that {@link IEnergyHandler} is an extension of this. + * + * @author King Lemming + * + */ +public interface IEnergyConnection { + + /** + * Returns TRUE if the TileEntity can connect on a given side. + */ + boolean canConnectEnergy(ForgeDirection from); + +} \ No newline at end of file diff --git a/apis/cofh/api/energy/IEnergyHandler.java b/apis/cofh/api/energy/IEnergyHandler.java new file mode 100644 index 000000000..db17f44ba --- /dev/null +++ b/apis/cofh/api/energy/IEnergyHandler.java @@ -0,0 +1,51 @@ +package cofh.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects. + * + * A reference implementation is provided {@link TileEnergyHandler}. + * + * @author King Lemming + * + */ +public interface IEnergyHandler extends IEnergyConnection { + + /** + * Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. + * + * @param from + * Orientation the energy is received from. + * @param maxReceive + * Maximum amount of energy to receive. + * @param simulate + * If TRUE, the charge will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) received. + */ + int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate); + + /** + * Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler. + * + * @param from + * Orientation the energy is extracted from. + * @param maxExtract + * Maximum amount of energy to extract. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted. + */ + int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate); + + /** + * Returns the amount of energy currently stored. + */ + int getEnergyStored(ForgeDirection from); + + /** + * Returns the maximum amount of energy that can be stored. + */ + int getMaxEnergyStored(ForgeDirection from); + +} \ No newline at end of file diff --git a/resources/assets/botania/lang/en_US.lang b/resources/assets/botania/lang/en_US.lang index 45d6a1ddb..168a8ab24 100644 --- a/resources/assets/botania/lang/en_US.lang +++ b/resources/assets/botania/lang/en_US.lang @@ -425,6 +425,7 @@ tile.botania:customBrick14.name=Azulejo tile.botania:customBrick15.name=Azulejo tile.botania:enderEyeBlock.name=Ender Overseer tile.botania:starfield.name=Starfield Creator +tile.botania:rfGenerator.name=Mana Fluxfield # FLOWER NAMES tile.botania:flower..name=Botania Flower diff --git a/resources/assets/botania/textures/blocks/rfGenerator.png b/resources/assets/botania/textures/blocks/rfGenerator.png new file mode 100644 index 000000000..fe71710ad Binary files /dev/null and b/resources/assets/botania/textures/blocks/rfGenerator.png differ