diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-07 16:36:25 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-09-07 16:36:25 +1000 |
commit | 221c2f0fe81430e7dd4087e5f5845bd7c62ec56d (patch) | |
tree | d6e0faaef01b9d517828557e1be82500d476f95e /src/Java/gtPlusPlus/xmod/forestry/bees/alveary | |
parent | 5872c0947ce7bc788b03fa2fb690b8815d3d0a04 (diff) | |
download | GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.tar.gz GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.tar.bz2 GT5-Unofficial-221c2f0fe81430e7dd4087e5f5845bd7c62ec56d.zip |
% Refactored the entire project to stop using MiscUtils everywhere possible, now it's gtPlusPlus.
Diffstat (limited to 'src/Java/gtPlusPlus/xmod/forestry/bees/alveary')
9 files changed, 1025 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/FR_AlvearyFrameBlock.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/FR_AlvearyFrameBlock.java new file mode 100644 index 0000000000..2f4437afd1 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/FR_AlvearyFrameBlock.java @@ -0,0 +1,45 @@ +package gtPlusPlus.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/gtPlusPlus/xmod/forestry/bees/alveary/FR_BlockAlveary.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/FR_BlockAlveary.java new file mode 100644 index 0000000000..f087ad75f4 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/FR_BlockAlveary.java @@ -0,0 +1,274 @@ +package gtPlusPlus.xmod.forestry.bees.alveary; + +import java.util.ArrayList; +import java.util.List; + +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; +import gtPlusPlus.GTplusplus; +import gtPlusPlus.core.creative.AddToCreativeTab; + +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(GTplusplus.instance, 0, world, x, y, z); + return true; + } + /*else if (te != null && te instanceof TileAlvearyFrameHousing) + { + player.openGui(GTplusplus.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/gtPlusPlus/xmod/forestry/bees/alveary/FR_TileAlveary.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/FR_TileAlveary.java new file mode 100644 index 0000000000..b5b3b73e6b --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/FR_TileAlveary.java @@ -0,0 +1,199 @@ +package gtPlusPlus.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/gtPlusPlus/xmod/forestry/bees/alveary/IAlvearyComponentAdvanced.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/IAlvearyComponentAdvanced.java new file mode 100644 index 0000000000..b55d2d37a6 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/IAlvearyComponentAdvanced.java @@ -0,0 +1,28 @@ +package gtPlusPlus.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/gtPlusPlus/xmod/forestry/bees/alveary/ISidedFrameWearingInventory.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/ISidedFrameWearingInventory.java new file mode 100644 index 0000000000..523c3e2434 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/ISidedFrameWearingInventory.java @@ -0,0 +1,10 @@ +package gtPlusPlus.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/gtPlusPlus/xmod/forestry/bees/alveary/TileAlvearyFrameHousing.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/TileAlvearyFrameHousing.java new file mode 100644 index 0000000000..12f97b5f0c --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/TileAlvearyFrameHousing.java @@ -0,0 +1,301 @@ +package gtPlusPlus.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 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; +import gtPlusPlus.xmod.forestry.bees.alveary.gui.CONTAINER_FrameHousing; +import gtPlusPlus.xmod.forestry.bees.alveary.gui.GUI_FrameHousing; +import gtPlusPlus.xmod.forestry.bees.alveary.gui.InventoryFrameHousing; + +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/gtPlusPlus/xmod/forestry/bees/alveary/gui/CONTAINER_FrameHousing.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/gui/CONTAINER_FrameHousing.java new file mode 100644 index 0000000000..c685482266 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/gui/CONTAINER_FrameHousing.java @@ -0,0 +1,98 @@ +package gtPlusPlus.xmod.forestry.bees.alveary.gui; + +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; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.slots.SlotFrame; +import gtPlusPlus.xmod.forestry.bees.alveary.TileAlvearyFrameHousing; + +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/gtPlusPlus/xmod/forestry/bees/alveary/gui/GUI_FrameHousing.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/gui/GUI_FrameHousing.java new file mode 100644 index 0000000000..dcf8da3a1a --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/gui/GUI_FrameHousing.java @@ -0,0 +1,49 @@ +package gtPlusPlus.xmod.forestry.bees.alveary.gui; + +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.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/gtPlusPlus/xmod/forestry/bees/alveary/gui/InventoryFrameHousing.java b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/gui/InventoryFrameHousing.java new file mode 100644 index 0000000000..406c3c47cb --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/bees/alveary/gui/InventoryFrameHousing.java @@ -0,0 +1,21 @@ +package gtPlusPlus.xmod.forestry.bees.alveary.gui; + +import net.minecraft.item.ItemStack; +import forestry.api.apiculture.BeeManager; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.ItemStackUtil; +import gtPlusPlus.xmod.forestry.bees.alveary.TileAlvearyFrameHousing; + +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); + } +} |