diff options
Diffstat (limited to 'src/Java/miscutil/core')
15 files changed, 1079 insertions, 18 deletions
diff --git a/src/Java/miscutil/core/handler/GuiHandler.java b/src/Java/miscutil/core/handler/GuiHandler.java index 7b65eee9f7..e01822b975 100644 --- a/src/Java/miscutil/core/handler/GuiHandler.java +++ b/src/Java/miscutil/core/handler/GuiHandler.java @@ -2,15 +2,15 @@ package miscutil.core.handler; import miscutil.MiscUtils; import miscutil.core.container.Container_Charger; -import miscutil.core.container.Container_NHG; import miscutil.core.gui.beta.Gui_ID_Registry; import miscutil.core.gui.beta.MU_GuiId; import miscutil.core.gui.machine.GUI_Charger; -import miscutil.core.gui.machine.GUI_NHG; import miscutil.core.interfaces.IGuiManager; import miscutil.core.tileentities.machines.TileEntityCharger; -import miscutil.core.tileentities.machines.TileEntityNHG; import miscutil.core.util.Utils; +import miscutil.core.xmod.forestry.bees.alveary.TileAlvearyFrameHousing; +import miscutil.core.xmod.forestry.bees.alveary.gui.CONTAINER_FrameHousing; +import miscutil.core.xmod.forestry.bees.alveary.gui.GUI_FrameHousing; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; @@ -39,7 +39,7 @@ public class GuiHandler implements IGuiHandler { if (te != null){ if (ID == GUI1){ - return new Container_NHG((TileEntityNHG)te, player); + return new CONTAINER_FrameHousing((TileAlvearyFrameHousing)te, player); } else if (ID == GUI2){ return new Container_Charger((TileEntityCharger)te, player); @@ -58,7 +58,7 @@ public class GuiHandler implements IGuiHandler { if (te != null){ if (ID == GUI1){ Utils.LOG_WARNING("Opening Gui with Id: "+ID+" NHG"); - return new GUI_NHG((TileEntityNHG) te, player); + return new GUI_FrameHousing((TileAlvearyFrameHousing) te, player); } else if (ID == GUI2){ Utils.LOG_WARNING("Opening Gui with Id: "+ID+" Charger"); diff --git a/src/Java/miscutil/core/multiblock/test/TileAlveary.java b/src/Java/miscutil/core/multiblock/test/TileAlveary.java index 7a39809508..87573c4378 100644 --- a/src/Java/miscutil/core/multiblock/test/TileAlveary.java +++ b/src/Java/miscutil/core/multiblock/test/TileAlveary.java @@ -4,17 +4,17 @@ import miscutil.core.multiblock.abstracts.AbstractMultiblockLogic; import miscutil.core.multiblock.abstracts.AbstractMultiblockTE; import miscutil.core.multiblock.base.interfaces.IBaseMultiblockController; import net.minecraft.util.ChunkCoordinates; -import forestry.api.apiculture.IAlvearyComponent; import forestry.api.apiculture.IBeeHousing; +import forestry.api.multiblock.IAlvearyComponent; +import forestry.core.access.IRestrictedAccess; import forestry.core.gui.IHintSource; import forestry.core.network.IStreamableGui; import forestry.core.tiles.IClimatised; -import forestry.core.tiles.IRestrictedAccessTile; import forestry.core.tiles.ITitled; public abstract class TileAlveary extends AbstractMultiblockTE<AbstractMultiblockLogic> - implements IBeeHousing, IAlvearyComponent, IRestrictedAccessTile, IStreamableGui, ITitled, IClimatised, IHintSource + implements IBeeHousing, IAlvearyComponent, IRestrictedAccess, IStreamableGui, ITitled, IClimatised, IHintSource { public static enum Type diff --git a/src/Java/miscutil/core/slots/SlotFrame.java b/src/Java/miscutil/core/slots/SlotFrame.java new file mode 100644 index 0000000000..8deca37d1e --- /dev/null +++ b/src/Java/miscutil/core/slots/SlotFrame.java @@ -0,0 +1,25 @@ +package miscutil.core.slots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import forestry.api.apiculture.IHiveFrame; + +public class SlotFrame extends Slot{ + + public SlotFrame(IInventory inventory, int x, int y, int z) { + super(inventory, x, y, z); + + } + + @Override + public boolean isItemValid(ItemStack itemstack) { + return itemstack.getItem() instanceof IHiveFrame; + } + + @Override + public int getSlotStackLimit() { + return 1; + } + +} diff --git a/src/Java/miscutil/core/util/debug/RenderingTE_ForDebug.java b/src/Java/miscutil/core/util/debug/RenderingTE_ForDebug.java deleted file mode 100644 index 92792c814d..0000000000 --- a/src/Java/miscutil/core/util/debug/RenderingTE_ForDebug.java +++ /dev/null @@ -1,9 +0,0 @@ -package miscutil.core.util.debug; - -import net.minecraft.tileentity.TileEntity; - -public class RenderingTE_ForDebug extends TileEntity { - - - -} diff --git a/src/Java/miscutil/core/xmod/forestry/HANDLER_FR.java b/src/Java/miscutil/core/xmod/forestry/HANDLER_FR.java index f7837826a7..8a6a265962 100644 --- a/src/Java/miscutil/core/xmod/forestry/HANDLER_FR.java +++ b/src/Java/miscutil/core/xmod/forestry/HANDLER_FR.java @@ -1,21 +1,26 @@ package miscutil.core.xmod.forestry; import miscutil.core.lib.LoadedMods; +import miscutil.core.xmod.forestry.bees.alveary.TileAlvearyFrameHousing; import miscutil.core.xmod.forestry.bees.items.FR_ItemRegistry; import miscutil.core.xmod.forestry.bees.recipe.FR_Gregtech_Recipes; +import cpw.mods.fml.common.registry.GameRegistry; public class HANDLER_FR { public static void preInit(){ if (LoadedMods.Forestry){ FR_ItemRegistry.Register(); + + GameRegistry.registerTileEntity(TileAlvearyFrameHousing.class, "FrameHousing"); //FR_BlockRegistryApiculture.RegistryApiculture(); } } public static void Init(){ if (LoadedMods.Forestry){ - //FR_TileHandler.init(); + //FR_TileHandler.init(); + //new FR_GuiIDRegistry(); } } diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_AlvearyFrameBlock.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_AlvearyFrameBlock.java new file mode 100644 index 0000000000..d8fb9827de --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_AlvearyFrameBlock.java @@ -0,0 +1,45 @@ +package miscutil.core.xmod.forestry.bees.alveary; + +import net.minecraft.util.ChunkCoordinates; + +import com.mojang.authlib.GameProfile; + +import forestry.api.multiblock.IAlvearyComponent; +import forestry.api.multiblock.IMultiblockComponent; +import forestry.api.multiblock.IMultiblockController; +import forestry.api.multiblock.IMultiblockLogicAlveary; + +public class FR_AlvearyFrameBlock implements IAlvearyComponent, IMultiblockComponent{ + + @Override + public ChunkCoordinates getCoordinates() { + // TODO Auto-generated method stub + return null; + } + + @Override + public GameProfile getOwner() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void onMachineAssembled(IMultiblockController arg0, + ChunkCoordinates arg1, ChunkCoordinates arg2) { + // TODO Auto-generated method stub + + } + + @Override + public void onMachineBroken() { + // TODO Auto-generated method stub + + } + + @Override + public IMultiblockLogicAlveary getMultiblockLogic() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_BlockAlveary.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_BlockAlveary.java new file mode 100644 index 0000000000..ff08464405 --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_BlockAlveary.java @@ -0,0 +1,274 @@ +package miscutil.core.xmod.forestry.bees.alveary; + +import java.util.ArrayList; +import java.util.List; + +import miscutil.MiscUtils; +import miscutil.core.creative.AddToCreativeTab; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +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 cpw.mods.fml.common.registry.LanguageRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.apiculture.MaterialBeehive; +import forestry.apiculture.multiblock.TileAlvearyPlain; +import forestry.core.blocks.BlockStructure; +import forestry.core.render.TextureManager; + +public class FR_BlockAlveary extends BlockStructure +{ + + public static enum Type + { + PLAIN, + ERROR, + FRAME, + MUTATOR, + + //Placeholder Values + HEATER, HYGRO, STABILIZER, SIEVE; + + public static final Type[] VALUES = values(); + + private Type() {} + } + + public FR_BlockAlveary() + { + super(new MaterialBeehive(false)); + setHardness(1.0F); + setCreativeTab(AddToCreativeTab.tabBlock); + setHarvestLevel("axe", 0); + + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) + { + if (world.isRemote) return true; + + TileEntity te = world.getTileEntity(x, y, z); + if (te != null && te instanceof TileAlvearyFrameHousing) + { + player.openGui(MiscUtils.instance, 0, world, x, y, z); + return true; + } + /*else if (te != null && te instanceof TileAlvearyFrameHousing) + { + player.openGui(MiscUtils.instance, 0, world, x, y, z); + return true; + }*/ + return false; + } + + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item item, CreativeTabs tab, List list) + { + for (int i = 0; i < 4; i++) { + if (i != 1 && i != 0) { + list.add(new ItemStack(item, 1, i)); + } + } + } + + @Override + public int getRenderType() + { + return 0; + } + + @Override + public boolean renderAsNormalBlock() + { + return true; + } + + @Override + public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) + { + ArrayList<ItemStack> drop = new ArrayList<ItemStack>(); + drop.add(new ItemStack(this, 1, metadata != 1 ? metadata : 0)); + return drop; + } + + @Override + public int getDamageValue(World world, int x, int y, int z) + { + int meta = world.getBlockMetadata(x, y, z); + return meta != 1 ? meta : 0; + } + + @Override + public TileEntity createTileEntity(World world, int metadata) + { + if ((metadata < 0) || (metadata > Type.VALUES.length)) { + return null; + } + + + + Type type = Type.VALUES[metadata]; + switch (type) + { + case FRAME: + LanguageRegistry.addName(this, "Alveary Frame Housing"); + case MUTATOR: + LanguageRegistry.addName(this, "Alveary Mutator Block"); + case ERROR: + LanguageRegistry.addName(this, "Invalid Alveary Block"); + default: + LanguageRegistry.addName(this, "Unnamed Alveary Block"); + } + switch (type) + { + case FRAME: + return new TileAlvearyFrameHousing(); + case MUTATOR: + return new TileAlvearyPlain(); + case ERROR: + return new TileAlvearyPlain(); + default: + return new TileAlvearyPlain(); + } + } + + @Override + public Block setBlockName(String name) { + //int meta = this. + return super.setBlockName(name); + } + + @Override + public TileEntity createNewTileEntity(World world, int meta) + { + return createTileEntity(world, meta); + } + + /* ICONS */ + public static final int PLAIN = 0; + public static final int ENTRANCE = 1; + public static final int BOTTOM = 2; + public static final int LEFT = 3; + public static final int RIGHT = 4; + public static final int ALVEARY_FRAME_OFF = 5; + public static final int ALVEARY_FRAME_ON = 6; + public static final int ALVEARY_MUTATOR_OFF = 7; + public static final int ALVEARY_MUTATOR_ON = 8; + @SideOnly(Side.CLIENT) + private IIcon[] icons; + @SideOnly(Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister register) { + icons = new IIcon[9]; + icons[0] = TextureManager.registerTex(register, "apiculture/alveary.plain"); + icons[1] = TextureManager.registerTex(register, "apiculture/alveary.entrance"); + icons[2] = TextureManager.registerTex(register, "apiculture/alveary.bottom"); + icons[3] = TextureManager.registerTex(register, "apiculture/alveary.left"); + icons[4] = TextureManager.registerTex(register, "apiculture/alveary.right"); + icons[5] = TextureManager.registerTex(register, "apiculture/alveary.framehousing.off"); + icons[6] = TextureManager.registerTex(register, "apiculture/alveary.framehousing.on"); + icons[7] = TextureManager.registerTex(register, "apiculture/alveary.mutator.off"); + icons[8] = TextureManager.registerTex(register, "apiculture/alveary.mutator.on"); + } + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(int side, int metadata) { + if ((metadata <= 1 + || metadata == Type.FRAME.ordinal() || metadata == Type.MUTATOR.ordinal()) + && (side == 1 || side == 0)) { + return icons[BOTTOM]; + } + Type type = Type.VALUES[metadata]; + switch (type) { + case ERROR: + return icons[PLAIN]; + case FRAME: + return icons[ALVEARY_FRAME_OFF]; + case MUTATOR: + return icons[ALVEARY_MUTATOR_OFF]; + case HEATER: + return icons[ALVEARY_MUTATOR_OFF]; + case HYGRO: + return icons[ALVEARY_MUTATOR_OFF]; + case STABILIZER: + return icons[PLAIN]; + case SIEVE: + return icons[PLAIN]; + default: + return null; + } + } + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + int meta = world.getBlockMetadata(x, y, z); + if (meta == 1) { + return this.getIcon(side, meta); + } else if (meta > 1) { + return getBlockTextureFromSideAndTile(world, x, y, z, side); + } + Block blockXP = world.getBlock(x + 1, y, z); + Block blockXM = world.getBlock(x - 1, y, z); + if (blockXP == this && blockXM != this) { + if (world.getBlockMetadata(x + 1, y, z) == 1) { + if (world.getBlock(x, y, z + 1) != this) { + return switchForSide(42, side); + } + return switchForSide(41, side); + } + return this.getIcon(side, meta); + } else if (blockXP != this && blockXM == this) { + if (world.getBlockMetadata(x - 1, y, z) == 1) { + if (world.getBlock(x, y, z + 1) != this) { + return switchForSide(41, side); + } + return switchForSide(42, side); + } + return this.getIcon(side, meta); + } + return this.getIcon(side, meta); + } + @SideOnly(Side.CLIENT) + private IIcon getBlockTextureFromSideAndTile(IBlockAccess world, int x, int y, int z, int side) { + TileEntity tile = world.getTileEntity(x, y, z); + if (!(tile instanceof FR_TileAlveary)) { + return getIcon(side, 0); + } + return icons[((FR_TileAlveary) tile).getIcon(side)]; + } + @SideOnly(Side.CLIENT) + private IIcon switchForSide(int textureId, int side) { + if (side == 4 || side == 5) { + if (textureId == 41) { + return icons[LEFT]; + } + return icons[RIGHT]; + } else if (textureId == 41) { + return icons[RIGHT]; + } else { + return icons[LEFT]; + } + } + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block block) { + super.onNeighborBlockChange(world, x, y, z, block); + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity instanceof FR_TileAlveary) { + FR_TileAlveary tileAlveary = (FR_TileAlveary) tileEntity; + // We must check that the slabs on top were not removed + tileAlveary.getMultiblockLogic().getController().reassemble(); + } + } + public ItemStack get(Type type) { + return new ItemStack(this, 1, type.ordinal()); + } +}
\ No newline at end of file diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_TileAlveary.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_TileAlveary.java new file mode 100644 index 0000000000..cae1aaba5e --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/FR_TileAlveary.java @@ -0,0 +1,199 @@ +package miscutil.core.xmod.forestry.bees.alveary; + +import java.io.IOException; +import java.util.List; + +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.Vec3; +import net.minecraft.world.biome.BiomeGenBase; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeeHousingInventory; +import forestry.api.apiculture.IBeeListener; +import forestry.api.apiculture.IBeeModifier; +import forestry.api.apiculture.IBeekeepingLogic; +import forestry.api.core.EnumHumidity; +import forestry.api.core.EnumTemperature; +import forestry.api.core.IErrorLogic; +import forestry.api.multiblock.IAlvearyComponent; +import forestry.api.multiblock.IMultiblockController; +import forestry.apiculture.multiblock.MultiblockLogicAlveary; +import forestry.core.access.EnumAccess; +import forestry.core.access.IAccessHandler; +import forestry.core.access.IRestrictedAccess; +import forestry.core.config.Config; +import forestry.core.gui.IGuiHandlerForestry; +import forestry.core.gui.IHintSource; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.multiblock.MultiblockTileEntityForestry; +import forestry.core.network.DataInputStreamForestry; +import forestry.core.network.DataOutputStreamForestry; +import forestry.core.network.IStreamableGui; +import forestry.core.tiles.IClimatised; +import forestry.core.tiles.ITitled; + +public abstract class FR_TileAlveary +extends MultiblockTileEntityForestry<MultiblockLogicAlveary> +implements IBeeHousing, IAlvearyComponent, IRestrictedAccess, IStreamableGui, ITitled, IClimatised, IHintSource, IGuiHandlerForestry +{ + private final String unlocalizedTitle; + + protected FR_TileAlveary() + { + this(FR_BlockAlveary.Type.ERROR); + } + + protected FR_TileAlveary(FR_BlockAlveary.Type type) + { + super(new MultiblockLogicAlveary()); + this.unlocalizedTitle = ("advanced.tile.for.alveary." + type.ordinal() + ".name"); + + } + + public int getIcon(int side) + { + return 0; + } + + @Override + public void onMachineAssembled(IMultiblockController multiblockController, ChunkCoordinates minCoord, ChunkCoordinates maxCoord) + { + if (this.worldObj.isRemote) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, getBlockType()); + markDirty(); + } + + @Override + public void onMachineBroken() + { + if (this.worldObj.isRemote) { + this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord); + } + this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, getBlockType()); + markDirty(); + } + + @Override + public BiomeGenBase getBiome() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBiome(); + } + + @Override + public Iterable<IBeeModifier> getBeeModifiers() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeeModifiers(); + } + + @Override + public Iterable<IBeeListener> getBeeListeners() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeeListeners(); + } + + @Override + public IBeeHousingInventory getBeeInventory() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeeInventory(); + } + + @Override + public IBeekeepingLogic getBeekeepingLogic() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeekeepingLogic(); + } + + @Override + public Vec3 getBeeFXCoordinates() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeeFXCoordinates(); + } + + @Override + public EnumTemperature getTemperature() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getTemperature(); + } + + @Override + public EnumHumidity getHumidity() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getHumidity(); + } + + @Override + public int getBlockLightValue() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBlockLightValue(); + } + + @Override + public boolean canBlockSeeTheSky() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().canBlockSeeTheSky(); + } + + @Override + public IErrorLogic getErrorLogic() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getErrorLogic(); + } + + @Override + public IAccessHandler getAccessHandler() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getAccessHandler(); + } + + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) + { + ((MultiblockLogicAlveary)getMultiblockLogic()).getController().onSwitchAccess(oldAccess, newAccess); + } + + @Override + public IInventoryAdapter getInternalInventory() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getInternalInventory(); + } + + @Override + public String getUnlocalizedTitle() + { + return this.unlocalizedTitle; + } + + @Override + public List<String> getHints() + { + return Config.hints.get("apiary"); + } + + @Override + public float getExactTemperature() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getExactTemperature(); + } + + @Override + public float getExactHumidity() + { + return ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getExactHumidity(); + } + + @Override + public void writeGuiData(DataOutputStreamForestry data) + throws IOException + { + ((MultiblockLogicAlveary)getMultiblockLogic()).getController().writeGuiData(data); + } + + @Override + public void readGuiData(DataInputStreamForestry data) + throws IOException + { + ((MultiblockLogicAlveary)getMultiblockLogic()).getController().readGuiData(data); + } + +} diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/IAlvearyComponentAdvanced.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/IAlvearyComponentAdvanced.java new file mode 100644 index 0000000000..46b65842b1 --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/IAlvearyComponentAdvanced.java @@ -0,0 +1,28 @@ +package miscutil.core.xmod.forestry.bees.alveary; + +import forestry.api.apiculture.IBeeModifier; +import forestry.api.core.IClimateControlled; +import forestry.api.multiblock.IMultiblockComponent; +import forestry.api.multiblock.IMultiblockLogicAlveary; + +public abstract interface IAlvearyComponentAdvanced<T extends IMultiblockLogicAlveary> +extends IMultiblockComponent +{ + @Override + public abstract T getMultiblockLogic(); + + + public static abstract interface FrameHouse + extends IAlvearyComponentAdvanced + { + public abstract void changeClimate(int paramInt, IClimateControlled paramIClimateControlled); + } + + + public static abstract interface BeeModifier + extends IAlvearyComponentAdvanced + { + public abstract IBeeModifier getBeeModifier(); + } + +} diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/ISidedFrameWearingInventory.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/ISidedFrameWearingInventory.java new file mode 100644 index 0000000000..f618e4f77b --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/ISidedFrameWearingInventory.java @@ -0,0 +1,10 @@ +package miscutil.core.xmod.forestry.bees.alveary; + +import net.minecraft.inventory.ISidedInventory; +import forestry.api.apiculture.IBeeHousing; + +public abstract interface ISidedFrameWearingInventory + extends ISidedInventory +{ + public abstract void wearOutFrames(IBeeHousing paramIBeeHousing, int paramInt); +}
\ No newline at end of file diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/TileAlvearyFrameHousing.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/TileAlvearyFrameHousing.java new file mode 100644 index 0000000000..1500e7dcef --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/TileAlvearyFrameHousing.java @@ -0,0 +1,301 @@ +package miscutil.core.xmod.forestry.bees.alveary; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +import miscutil.core.xmod.forestry.bees.alveary.gui.CONTAINER_FrameHousing; +import miscutil.core.xmod.forestry.bees.alveary.gui.GUI_FrameHousing; +import miscutil.core.xmod.forestry.bees.alveary.gui.InventoryFrameHousing; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import forestry.api.apiculture.BeeManager; +import forestry.api.apiculture.IBee; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeeModifier; +import forestry.api.apiculture.IBeekeepingMode; +import forestry.api.apiculture.IHiveFrame; +import forestry.api.multiblock.IAlvearyComponent; +import forestry.apiculture.ApiaryBeeModifier; +import forestry.apiculture.multiblock.MultiblockLogicAlveary; +import forestry.apiculture.network.packets.PacketActiveUpdate; +import forestry.apiculture.worldgen.Hive; +import forestry.apiculture.worldgen.HiveDecorator; +import forestry.apiculture.worldgen.HiveDescriptionSwarmer; +import forestry.core.inventory.IInventoryAdapter; +import forestry.core.inventory.wrappers.IInvSlot; +import forestry.core.inventory.wrappers.InventoryIterator; +import forestry.core.proxy.Proxies; +import forestry.core.tiles.IActivatable; +import forestry.core.utils.ItemStackUtil; + +public class TileAlvearyFrameHousing +extends FR_TileAlveary +implements ISidedFrameWearingInventory, IActivatable, IAlvearyComponent.Active, IAlvearyComponent.BeeModifier +{ + private final InventoryFrameHousing inventory; + private final Stack<ItemStack> pendingSpawns = new Stack<ItemStack>(); + private boolean active; + + public TileAlvearyFrameHousing() + { + super(FR_BlockAlveary.Type.FRAME); + this.inventory = new InventoryFrameHousing(this); + + } + + @Override + public IInventoryAdapter getInternalInventory() + { + return this.inventory; + } + + @Override + public boolean allowsAutomation() + { + return true; + } + + @Override + public void updateServer(int tickCount) + { + + if (getInternalInventory() == null) { + return; + } + + if (this.inventory.getStackInSlot(0) != null) + { + setActive(true); + if (tickCount % 1000 == 0) { + wearOutFrames(this, 1); + } + } + else + { + setActive(false); + } + if (tickCount % 500 != 0) { + return; + } + + } + + @Override + public void updateClient(int tickCount) {} + + private ItemStack getPrincessStack() + { + ItemStack princessStack = ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeeInventory().getQueen(); + if (BeeManager.beeRoot.isMated(princessStack)) { + return princessStack; + } + return null; + } + + private int consumeInducerAndGetChance() + { + if (getInternalInventory() == null) { + return 0; + } + for (Iterator<?> i$ = InventoryIterator.getIterable(getInternalInventory()).iterator(); i$.hasNext();) + { + IInvSlot slot = (IInvSlot)i$.next(); + ItemStack stack = slot.getStackInSlot(); + for (Map.Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) { + if (ItemStackUtil.isIdenticalItem((ItemStack)entry.getKey(), stack)) + { + slot.decreaseStackInSlot(); + return ((Integer)entry.getValue()).intValue(); + } + } + } + IInvSlot slot; + ItemStack stack; + return 0; + } + + private void trySpawnSwarm() + { + ItemStack toSpawn = (ItemStack)this.pendingSpawns.peek(); + HiveDescriptionSwarmer hiveDescription = new HiveDescriptionSwarmer(new ItemStack[] { toSpawn }); + Hive hive = new Hive(hiveDescription); + + int chunkX = (this.xCoord + this.worldObj.rand.nextInt(80) - 40) / 16; + int chunkZ = (this.zCoord + this.worldObj.rand.nextInt(80) - 40) / 16; + if (HiveDecorator.genHive(this.worldObj, this.worldObj.rand, chunkX, chunkZ, hive)) { + this.pendingSpawns.pop(); + } + } + + @Override + protected void encodeDescriptionPacket(NBTTagCompound packetData) + { + super.encodeDescriptionPacket(packetData); + packetData.setBoolean("Active", this.active); + } + + @Override + protected void decodeDescriptionPacket(NBTTagCompound packetData) + { + super.decodeDescriptionPacket(packetData); + setActive(packetData.getBoolean("Active")); + } + + @Override + public int getIcon(int side) + { + if ((side == 0) || (side == 1)) { + return 2; + } + if (this.active) { + return 6; + } + return 5; + } + + @Override + public void readFromNBT(NBTTagCompound nbttagcompound) + { + super.readFromNBT(nbttagcompound); + setActive(nbttagcompound.getBoolean("Active")); + + NBTTagList nbttaglist = nbttagcompound.getTagList("PendingSpawns", 10); + for (int i = 0; i < nbttaglist.tagCount(); i++) + { + NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i); + this.pendingSpawns.add(ItemStack.loadItemStackFromNBT(nbttagcompound1)); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) + { + super.writeToNBT(nbttagcompound); + nbttagcompound.setBoolean("Active", this.active); + + NBTTagList nbttaglist = new NBTTagList(); + ItemStack[] offspring = (ItemStack[])this.pendingSpawns.toArray(new ItemStack[this.pendingSpawns.size()]); + for (int i = 0; i < offspring.length; i++) { + if (offspring[i] != null) + { + NBTTagCompound nbttagcompound1 = new NBTTagCompound(); + nbttagcompound1.setByte("Slot", (byte)i); + offspring[i].writeToNBT(nbttagcompound1); + nbttaglist.appendTag(nbttagcompound1); + } + } + nbttagcompound.setTag("PendingSpawns", nbttaglist); + } + + @Override + public boolean isActive() + { + return this.active; + } + + @Override + public void setActive(boolean active) + { + if (this.active == active) { + return; + } + this.active = active; + if (!this.worldObj.isRemote) { + Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), this.worldObj); + } + } + + @Override + public Object getGui(EntityPlayer player, int data) + { + return new GUI_FrameHousing(this, player); + } + + @Override + public Object getContainer(EntityPlayer player, int data) + { + return new CONTAINER_FrameHousing(this, player); + } + + private final IBeeModifier beeModifier = new ApiaryBeeModifier(); + //private final IBeeListener beeListener = new ApiaryBeeListener(this); + + @Override + public Collection<IBeeModifier> getBeeModifiers() + { + List<IBeeModifier> beeModifiers = new ArrayList<IBeeModifier>(); + + beeModifiers.add(this.beeModifier); + for (IHiveFrame frame : getFrames(this.inventory)) { + beeModifiers.add(frame.getBeeModifier()); + } + return beeModifiers; + } + + public Collection<IHiveFrame> getFrames(IInventory inventory) + { + Collection<IHiveFrame> hiveFrames = new ArrayList<IHiveFrame>(inventory.getSizeInventory()); + for (int i = 0; i < inventory.getSizeInventory(); i++) + { + ItemStack stackInSlot = getStackInSlot(i); + if (stackInSlot != null) + { + Item itemInSlot = stackInSlot.getItem(); + if ((itemInSlot instanceof IHiveFrame)) { + hiveFrames.add((IHiveFrame)itemInSlot); + } + } + } + return hiveFrames; + } + + @Override + public IBeeModifier getBeeModifier() { + List<IBeeModifier> beeModifiers = new ArrayList<IBeeModifier>(); + + beeModifiers.add(this.beeModifier); + for (IHiveFrame frame : getFrames(this.inventory)) { + beeModifiers.add(frame.getBeeModifier()); + } + return beeModifiers.get(0); + } + + private ItemStack getQueenStack() + { + ItemStack queenStack = ((MultiblockLogicAlveary)getMultiblockLogic()).getController().getBeeInventory().getQueen(); + return queenStack; + } + + @Override + public void wearOutFrames(IBeeHousing beeHousing, int amount) + { + IBeekeepingMode beekeepingMode = BeeManager.beeRoot.getBeekeepingMode(beeHousing.getWorld()); + int wear = Math.round(amount * beekeepingMode.getWearModifier()); + for (int i = 0; i < this.inventory.getSizeInventory(); i++) + { + ItemStack hiveFrameStack = getStackInSlot(i); + if (hiveFrameStack != null) + { + Item hiveFrameItem = hiveFrameStack.getItem(); + if ((hiveFrameItem instanceof IHiveFrame)) + { + IHiveFrame hiveFrame = (IHiveFrame)hiveFrameItem; + + ItemStack queenStack = getQueenStack(); + IBee queen = BeeManager.beeRoot.getMember(queenStack); + ItemStack usedFrame = hiveFrame.frameUsed(beeHousing, hiveFrameStack, queen, wear); + + setInventorySlotContents(i, usedFrame); + } + } + } + } +} diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/CONTAINER_FrameHousing.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/CONTAINER_FrameHousing.java new file mode 100644 index 0000000000..7a04b7b05e --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/CONTAINER_FrameHousing.java @@ -0,0 +1,98 @@ +package miscutil.core.xmod.forestry.bees.alveary.gui; + +import miscutil.core.lib.CORE; +import miscutil.core.slots.SlotFrame; +import miscutil.core.xmod.forestry.bees.alveary.TileAlvearyFrameHousing; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import forestry.api.apiculture.IHiveFrame; +import forestry.core.gui.tooltips.ToolTip; + +public class CONTAINER_FrameHousing extends Container +{ + private TileAlvearyFrameHousing te; + + public static final int INPUT_1 = 0; + private final ResourceLocation beeFrameIcon = new ResourceLocation(CORE.MODID, "textures/items/machine_Charger.png"); + public ToolTip newTip = new ToolTip(); + private final SlotFrame beeFrameSlot; + + private int slotID = 0; + + public CONTAINER_FrameHousing(TileAlvearyFrameHousing te, EntityPlayer player) + { + this.te = te; + this.beeFrameSlot = new SlotFrame(te, slotID++, 80, 35); + + //Fuel Slot A + beeFrameSlot.setBackgroundIconTexture(beeFrameIcon); + + addSlotToContainer(beeFrameSlot); + + //Inventory + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 9; j++) + { + addSlotToContainer(new Slot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + // Hotbar + for (int i = 0; i < 9; i++) + { + addSlotToContainer(new Slot(player.inventory, i, 8 + i * 18, 142)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slotRaw) + { + ItemStack stack = null; + Slot slot = (Slot)inventorySlots.get(slotRaw); + + if (slot != null && slot.getHasStack()) + { + ItemStack stackInSlot = slot.getStack(); + stack = stackInSlot.copy(); + + + //If your inventory only stores certain instances of Items, + //you can implement shift-clicking to your inventory like this: + // Check that the item is the right type + if (!(stack.getItem() instanceof IHiveFrame)){ + return null; + } + + if (slotRaw < 1) + { + if (!mergeItemStack(stackInSlot, 3 * 9, inventorySlots.size(), true)) + { + return null; + } + } + else if (!mergeItemStack(stackInSlot, 0, 3 * 9, false)) + { + return null; + } + + if (stackInSlot.stackSize == 0) + { + slot.putStack((ItemStack)null); + } + else + { + slot.onSlotChanged(); + } + } + return stack; + } + + @Override + public boolean canInteractWith(EntityPlayer player) + { + return te.isUseableByPlayer(player); + } +}
\ No newline at end of file diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/GUI_FrameHousing.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/GUI_FrameHousing.java new file mode 100644 index 0000000000..f2ab1e1e7e --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/GUI_FrameHousing.java @@ -0,0 +1,49 @@ +package miscutil.core.xmod.forestry.bees.alveary.gui; + +import miscutil.core.lib.CORE; +import miscutil.core.xmod.forestry.bees.alveary.TileAlvearyFrameHousing; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +public class GUI_FrameHousing extends GuiContainer +{ + private ResourceLocation texture = new ResourceLocation(CORE.MODID, "textures/gui/machine_Charger.png"); + + private InventoryPlayer inventory; + private TileAlvearyFrameHousing te; + + public GUI_FrameHousing(TileAlvearyFrameHousing te, EntityPlayer player) + { + super(new CONTAINER_FrameHousing(te, player)); + inventory = player.inventory; + this.te = te; + } + + @Override + protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) + { + Minecraft.getMinecraft().renderEngine.bindTexture(texture); + + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + int x = (width - xSize) / 2; + int y = (height - ySize) / 2; + + drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + } + + @Override + protected void drawGuiContainerForegroundLayer(int par1, int par2) + { + fontRendererObj.drawString(I18n.format("Alveary Frame Housing"), (xSize / 2) - (fontRendererObj.getStringWidth(I18n.format("Alveary Frame Housing")) / 2), 6, 4210752, false); + fontRendererObj.drawString(I18n.format(inventory.getInventoryName()), 8, ySize - 96 + 2, 4210752); + //fontRendererObj.drawString(I18n.format("Charge:"+te.getCharge()+"~"), 8, ySize - 96 + 2, 4210752); + //fontRendererObj.drawString(I18n.format("Progress:"+te.getProgress()+"ticks"), 80, ySize - 96 + 2, 4210752); + } +}
\ No newline at end of file diff --git a/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/InventoryFrameHousing.java b/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/InventoryFrameHousing.java new file mode 100644 index 0000000000..b9f60efc6c --- /dev/null +++ b/src/Java/miscutil/core/xmod/forestry/bees/alveary/gui/InventoryFrameHousing.java @@ -0,0 +1,21 @@ +package miscutil.core.xmod.forestry.bees.alveary.gui; + +import miscutil.core.xmod.forestry.bees.alveary.TileAlvearyFrameHousing; +import net.minecraft.item.ItemStack; +import forestry.api.apiculture.BeeManager; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.ItemStackUtil; + +public class InventoryFrameHousing extends InventoryAdapterTile<TileAlvearyFrameHousing> +{ + public InventoryFrameHousing(TileAlvearyFrameHousing alvearyFrame) + { + super(alvearyFrame, 1, "FrameHousingInv"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) + { + return ItemStackUtil.containsItemStack(BeeManager.inducers.keySet(), itemStack); + } +} diff --git a/src/Java/miscutil/core/xmod/forestry/bees/items/FR_ItemRegistry.java b/src/Java/miscutil/core/xmod/forestry/bees/items/FR_ItemRegistry.java index 305fb44dfb..230992ceb5 100644 --- a/src/Java/miscutil/core/xmod/forestry/bees/items/FR_ItemRegistry.java +++ b/src/Java/miscutil/core/xmod/forestry/bees/items/FR_ItemRegistry.java @@ -10,12 +10,16 @@ ******************************************************************************/ package miscutil.core.xmod.forestry.bees.items; import miscutil.core.lib.LoadedMods; +import miscutil.core.xmod.forestry.bees.alveary.FR_BlockAlveary; +import net.minecraft.block.Block; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.util.WeightedRandomChestContent; import net.minecraftforge.common.ChestGenHooks; import cpw.mods.fml.common.registry.GameRegistry; +import forestry.core.items.ItemBlockForestry; import forestry.core.utils.StringUtil; public class FR_ItemRegistry { @@ -38,6 +42,9 @@ public class FR_ItemRegistry { public static MB_ItemFrame hiveFrameSoul; public static MB_ItemFrame hiveFrameClay; public static MB_ItemFrame hiveFrameNova; + + //Alveary Stuff + public static FR_BlockAlveary alveary; public static void Register() { @@ -63,6 +70,8 @@ public class FR_ItemRegistry { hiveFrameSoul = new MB_ItemFrame(MB_FrameType.SOUL, EnumRarity.common, ""); hiveFrameClay = new MB_ItemFrame(MB_FrameType.CLAY, EnumRarity.common, ""); hiveFrameNova = new MB_ItemFrame(MB_FrameType.NOVA, EnumRarity.epic, "A Creative Only Frame."); + + alveary = registerBlock(new FR_BlockAlveary(), ItemBlockForestry.class, "alveary"); } @@ -75,6 +84,12 @@ public class FR_ItemRegistry { GameRegistry.registerItem(item, StringUtil.cleanItemName(item)); return item; } + + protected static <T extends Block> T registerBlock(T block, Class<? extends ItemBlock> itemClass, String name, Object... itemCtorArgs) { + block.setBlockName("for." + name); + GameRegistry.registerBlock(block, itemClass, StringUtil.cleanBlockName(block), itemCtorArgs); + return block; + } } |