diff options
Diffstat (limited to 'src/Java/miscutil')
22 files changed, 1820 insertions, 1 deletions
diff --git a/src/Java/miscutil/MiscUtils.java b/src/Java/miscutil/MiscUtils.java index ba9cf34692..5f8dfec89a 100644 --- a/src/Java/miscutil/MiscUtils.java +++ b/src/Java/miscutil/MiscUtils.java @@ -23,7 +23,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStartingEvent; import cpw.mods.fml.common.event.FMLServerStoppingEvent; -@Mod(modid=CORE.MODID, name="Misc. Utils", version=CORE.VERSION, dependencies="required-after:Forge; after:IC2; after:gregtech; after:Growthcraft; after:Railcraft; after:CompactWindmills; after:ForbiddenMagic; after:MorePlanet; after:PneumaticCraft; after:ExtraUtilities; after:Thaumcraft; after:rftools; after:simplyjetpacks; after:BigReactors; after:EnderIO;") +@Mod(modid=CORE.MODID, name="Misc. Utils", version=CORE.VERSION, dependencies="required-after:Forge; after:IC2; after:gregtech; after:Forestry; after:MagicBees; after:CoFHCore; after:Growthcraft; after:Railcraft; after:CompactWindmills; after:ForbiddenMagic; after:MorePlanet; after:PneumaticCraft; after:ExtraUtilities; after:Thaumcraft; after:rftools; after:simplyjetpacks; after:BigReactors; after:EnderIO;") public class MiscUtils implements ActionListener { diff --git a/src/Java/miscutil/core/handler/COMPAT_IntermodStaging.java b/src/Java/miscutil/core/handler/COMPAT_IntermodStaging.java index 668487c5b7..a1e12cea8b 100644 --- a/src/Java/miscutil/core/handler/COMPAT_IntermodStaging.java +++ b/src/Java/miscutil/core/handler/COMPAT_IntermodStaging.java @@ -1,5 +1,6 @@ package miscutil.core.handler; +import miscutil.core.intermod.forestry.HANDLER_Forestry; import miscutil.core.intermod.growthcraft.HANDLER_Growthcraft; import miscutil.core.intermod.thermalfoundation.HANDLER_ThermalFoundation; import miscutil.gregtech.HANDLER_Gregtech; @@ -10,17 +11,20 @@ public class COMPAT_IntermodStaging { HANDLER_Growthcraft.preInit(); HANDLER_ThermalFoundation.preInit(); HANDLER_Gregtech.preInit(); + HANDLER_Forestry.preInit(); } public static void init(){ HANDLER_ThermalFoundation.Init(); HANDLER_Gregtech.init(); + HANDLER_Forestry.Init(); } public static void postInit(){ HANDLER_ThermalFoundation.postInit(); HANDLER_Gregtech.postInit(); + HANDLER_Forestry.postInit(); } diff --git a/src/Java/miscutil/core/intermod/forestry/HANDLER_Forestry.java b/src/Java/miscutil/core/intermod/forestry/HANDLER_Forestry.java new file mode 100644 index 0000000000..f670477318 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/HANDLER_Forestry.java @@ -0,0 +1,25 @@ +package miscutil.core.intermod.forestry; + +import miscutil.core.intermod.forestry.apiculture.items.FR_ItemRegistryApiculture; +import miscutil.core.lib.LoadedMods; + +public class HANDLER_Forestry { + + public static void preInit(){ + if (LoadedMods.Forestry){ + FR_ItemRegistryApiculture.RegisterApiculture(); + } + } + + public static void Init(){ + if (LoadedMods.Forestry){ + + } + } + + public static void postInit(){ + if (LoadedMods.Forestry){ + + } + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/blocks/FR_BlockAlveary.java b/src/Java/miscutil/core/intermod/forestry/apiculture/blocks/FR_BlockAlveary.java new file mode 100644 index 0000000000..24f34e3829 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/blocks/FR_BlockAlveary.java @@ -0,0 +1,240 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.apiculture.blocks; + +import java.util.ArrayList; +import java.util.List; + +import miscutil.core.creative.AddToCreativeTab; +import miscutil.core.intermod.forestry.apiculture.multiblock.TileAlvearyMutatron; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +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.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.apiculture.MaterialBeehive; +import forestry.apiculture.multiblock.TileAlveary; +import forestry.apiculture.multiblock.TileAlvearyPlain; +import forestry.core.blocks.BlockStructure; +import forestry.core.render.TextureManager; + +public class FR_BlockAlveary extends BlockStructure { + public enum Type { + PLAIN, + MUTATRON; + public static final Type[] VALUES = values(); + } + + public FR_BlockAlveary() { + super(new MaterialBeehive(false)); + setHardness(1.0f); + setCreativeTab(AddToCreativeTab.tabMisc); + setHarvestLevel("axe", 0); + } + + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override + @SideOnly(Side.CLIENT) + public void getSubBlocks(Item item, CreativeTabs tab, List list) { + for (int i = 0; i < 8; i++) { + if (i == 1) { + continue; + } + 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<>(); + 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; + } + + /* TILE ENTITY CREATION */ + @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 MUTATRON: + return new TileAlvearyMutatron(); + case PLAIN: + default: + return new TileAlvearyPlain(); + } + } + + @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 MUTATRON_OFF = 5; + public static final int MUTATRON_ON = 6; + + @SideOnly(Side.CLIENT) + private IIcon[] icons; + + @SideOnly(Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister register) { + icons = new IIcon[14]; + 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.mutatron.off"); + icons[6] = TextureManager.registerTex(register, "apiculture/alveary.mutatron.on"); + } + + @SideOnly(Side.CLIENT) + @Override + public IIcon getIcon(int side, int metadata) { + if ((metadata <= 1 || metadata == Type.MUTATRON.ordinal()) + && (side == 1 || side == 0)) { + return icons[BOTTOM]; + } + + Type type = Type.VALUES[metadata]; + + switch (type) { + case PLAIN: + return icons[PLAIN]; + case MUTATRON: + return icons[MUTATRON_OFF]; + 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); + } else { + return switchForSide(41, side); + } + + } else { + 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); + } else { + return switchForSide(42, side); + } + + } else { + 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 TileAlveary)) { + return getIcon(side, 0); + } + + return icons[((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]; + } else { + 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 TileAlveary) { + TileAlveary tileAlveary = (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()); + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/items/FR_ItemHiveFrame.java b/src/Java/miscutil/core/intermod/forestry/apiculture/items/FR_ItemHiveFrame.java new file mode 100644 index 0000000000..de8de491af --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/items/FR_ItemHiveFrame.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.apiculture.items; + +import miscutil.core.creative.AddToCreativeTab; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import forestry.api.apiculture.DefaultBeeModifier; +import forestry.api.apiculture.IBee; +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeeModifier; +import forestry.api.apiculture.IHiveFrame; + +public class FR_ItemHiveFrame extends Item implements IHiveFrame { + + private final IBeeModifier beeModifier; + + public FR_ItemHiveFrame(int maxDamage, float geneticDecay) { + setMaxStackSize(1); + setMaxDamage(maxDamage); + setCreativeTab(AddToCreativeTab.tabMisc); + + this.beeModifier = new HiveFrameBeeModifier(geneticDecay); + } + + @Override + public ItemStack frameUsed(IBeeHousing housing, ItemStack frame, IBee queen, int wear) { + frame.setItemDamage(frame.getItemDamage() + wear); + if (frame.getItemDamage() >= frame.getMaxDamage()) { + return null; + } else { + return frame; + } + } + + @Override + public IBeeModifier getBeeModifier() { + return beeModifier; + } + + private static class HiveFrameBeeModifier extends DefaultBeeModifier { + private final float geneticDecay; + + public HiveFrameBeeModifier(float geneticDecay) { + this.geneticDecay = geneticDecay; + } + + @Override + public float getProductionModifier(IBeeGenome genome, float currentModifier) { + return (currentModifier < 10f) ? 2f : 1f; + } + + @Override + public float getGeneticDecay(IBeeGenome genome, float currentModifier) { + return this.geneticDecay; + } + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/items/FR_ItemRegistryApiculture.java b/src/Java/miscutil/core/intermod/forestry/apiculture/items/FR_ItemRegistryApiculture.java new file mode 100644 index 0000000000..f648077f4e --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/items/FR_ItemRegistryApiculture.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.apiculture.items; +import miscutil.core.intermod.forestry.apiculture.items.magicbees.MB_HiveFrameType; +import miscutil.core.intermod.forestry.apiculture.items.magicbees.MB_ItemMagicHiveFrame; +import net.minecraft.item.Item; +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.ItemRegistry; +import forestry.core.utils.StringUtil; + +public class FR_ItemRegistryApiculture extends ItemRegistry { + + + //----- Apiary Frames ---------------------- + public static FR_ItemHiveFrame frameUntreated; + public static FR_ItemHiveFrame frameImpregnated; + public static FR_ItemHiveFrame frameProven; + //Magic Bee Frame Items + public static MB_ItemMagicHiveFrame hiveFrameMetabolic; + public static MB_ItemMagicHiveFrame hiveFrameOblivion; + + public static void RegisterApiculture() { + + //Forestry Frames + //frameUntreated = registerItem(new FR_ItemHiveFrame(80, 0.9f), "frameUntreated"); + //frameImpregnated = registerItem(new FR_ItemHiveFrame(240, 0.4f), "frameImpregnated"); + //frameProven = registerItem(new FR_ItemHiveFrame(720, 0.3f), "frameProven"); + + //Magic Bee like Frames + hiveFrameMetabolic = new MB_ItemMagicHiveFrame(MB_HiveFrameType.ACCELERATED); + hiveFrameOblivion = new MB_ItemMagicHiveFrame(MB_HiveFrameType.VOID); + ChestGenHooks.addItem(ChestGenHooks.STRONGHOLD_CORRIDOR, new WeightedRandomChestContent(new ItemStack(hiveFrameOblivion), 1, 1, 18)); + ChestGenHooks.addItem(ChestGenHooks.STRONGHOLD_LIBRARY, new WeightedRandomChestContent(new ItemStack(hiveFrameOblivion), 1, 3, 23)); + + + + + } + + protected static <T extends Item> T registerItem(T item, String name) { + item.setUnlocalizedName(name); + GameRegistry.registerItem(item, StringUtil.cleanItemName(item)); + return item; + } +} + + diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/FR_StringManager.java b/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/FR_StringManager.java new file mode 100644 index 0000000000..991b961ba9 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/FR_StringManager.java @@ -0,0 +1,30 @@ +package miscutil.core.intermod.forestry.apiculture.items.magicbees; + +import net.minecraft.util.StatCollector; + +public class FR_StringManager +{ + public static String getLocalizedString(String key) + { + if(StatCollector.canTranslate(key)) + { + return StatCollector.translateToLocal(key); + } + else + { + return StatCollector.translateToFallback(key); + } + } + + public static String getLocalizedString(String key, Object... objects) + { + if(StatCollector.canTranslate(key)) + { + return String.format(StatCollector.translateToLocal(key), objects); + } + else + { + return String.format(StatCollector.translateToFallback(key), objects); + } + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/MB_HiveFrameType.java b/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/MB_HiveFrameType.java new file mode 100644 index 0000000000..a168c8157b --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/MB_HiveFrameType.java @@ -0,0 +1,107 @@ +package miscutil.core.intermod.forestry.apiculture.items.magicbees; + +import forestry.api.apiculture.IBeeGenome; +import forestry.api.apiculture.IBeeModifier; + +public enum MB_HiveFrameType implements IBeeModifier +{ + ACCELERATED("Accelerated", 175, 1f, 2.5f, 0.9f, 1.8f, 1f), + VOID("Void", 20, 1f, 1f, 0.0001f, 10f, 1f); + + private final String frameName; + public final int maxDamage; + + private final float territoryMod; + private final float mutationMod; + private final float lifespanMod; + private final float productionMod; + private final float floweringMod; + private final float geneticDecayMod; + private final boolean isSealed; + private final boolean isLit; + private final boolean isSunlit; + private final boolean isHellish; + + MB_HiveFrameType(String name, int damage, float territory, float mutation, float lifespan, float production, float geneticDecay) { + this(name, damage, territory, mutation, lifespan, production, 1f, geneticDecay, false, false, false, false); + } + + MB_HiveFrameType(String name, int damage, + float territory, float mutation, float lifespan, float production, float flowering, float geneticDecay, + boolean sealed, boolean lit, boolean sunlit, boolean hellish) + { + this.frameName = name; + this.maxDamage = damage; + + this.territoryMod = territory; + this.mutationMod = mutation; + this.lifespanMod = lifespan; + this.productionMod = production; + this.floweringMod = flowering; + this.geneticDecayMod = geneticDecay; + this.isSealed = sealed; + this.isLit = lit; + this.isSunlit = sunlit; + this.isHellish = hellish; + } + + public String getName() + { + return this.frameName; + } + + public String getLocalizedName() + { + return FR_StringManager.getLocalizedString("frame." + this.frameName); + } + + @Override + public float getTerritoryModifier(IBeeGenome genome, float currentModifier) { + return territoryMod; + } + + @Override + public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) { + return mutationMod; + } + + @Override + public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) { + return lifespanMod; + } + + @Override + public float getProductionModifier(IBeeGenome genome, float currentModifier) { + return productionMod; + } + + @Override + public float getFloweringModifier(IBeeGenome genome, float currentModifier) { + return floweringMod; + } + + @Override + public float getGeneticDecay(IBeeGenome genome, float currentModifier) { + return geneticDecayMod; + } + + @Override + public boolean isSealed() { + return isSealed; + } + + @Override + public boolean isSelfLighted() { + return isLit; + } + + @Override + public boolean isSunlightSimulated() { + return isSunlit; + } + + @Override + public boolean isHellish() { + return isHellish; + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/MB_ItemMagicHiveFrame.java b/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/MB_ItemMagicHiveFrame.java new file mode 100644 index 0000000000..14234e7aae --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/items/magicbees/MB_ItemMagicHiveFrame.java @@ -0,0 +1,62 @@ +package miscutil.core.intermod.forestry.apiculture.items.magicbees; + +import miscutil.core.creative.AddToCreativeTab; +import miscutil.core.lib.CORE; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import forestry.api.apiculture.IBee; +import forestry.api.apiculture.IBeeHousing; +import forestry.api.apiculture.IBeeModifier; +import forestry.api.apiculture.IHiveFrame; + +public class MB_ItemMagicHiveFrame extends Item implements IHiveFrame +{ + private MB_HiveFrameType type; + + public MB_ItemMagicHiveFrame(MB_HiveFrameType frameType) + { + super(); + this.type = frameType; + this.setMaxDamage(this.type.maxDamage); + this.setMaxStackSize(1); + this.setCreativeTab(AddToCreativeTab.tabMisc); + this.setUnlocalizedName("frame" + frameType.getName()); + GameRegistry.registerItem(this, "frame" + frameType.getName()); + } + + @SideOnly(Side.CLIENT) + public void registerIcons(IIconRegister par1IconRegister) + { + this.itemIcon = par1IconRegister.registerIcon(CORE.MODID + ":frame" + type.getName()); + } + + // --------- IHiveFrame functions ----------------------------------------- + + @Override + public ItemStack frameUsed(IBeeHousing housing, ItemStack frame, IBee queen, int wear) { + frame.setItemDamage(frame.getItemDamage() + wear); + + if (frame.getItemDamage() >= frame.getMaxDamage()) { + // Break the frame. + frame = null; + } + + return frame; + } + + @Override + public IBeeModifier getBeeModifier() { + return type; + } + + @Override + public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2) + { + return false; + } + +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/FR_TileAlveary.java b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/FR_TileAlveary.java new file mode 100644 index 0000000000..29c4a7f445 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/FR_TileAlveary.java @@ -0,0 +1,199 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.apiculture.multiblock; + +import java.io.IOException; +import java.util.List; + +import miscutil.core.intermod.forestry.apiculture.blocks.FR_BlockAlveary; +import net.minecraft.entity.player.EntityPlayer; +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.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 { + private final String unlocalizedTitle; + + protected FR_TileAlveary() { + this(FR_BlockAlveary.Type.PLAIN); + } + + protected FR_TileAlveary(FR_BlockAlveary.Type type) { + super(new MultiblockLogicAlveary()); + this.unlocalizedTitle = "tile.alveary." + type.ordinal() + ".name"; + } + + /* TEXTURES */ + public int getIcon(int side) { + return FR_BlockAlveary.PLAIN; + } + + @Override + public void onMachineAssembled(IMultiblockController multiblockController, ChunkCoordinates minCoord, ChunkCoordinates maxCoord) { + // Re-render this block on the client + if (worldObj.isRemote) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType()); + markDirty(); + } + + @Override + public void onMachineBroken() { + // Re-render this block on the client + if (worldObj.isRemote) { + this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType()); + markDirty(); + } + + /* IHousing */ + @Override + public BiomeGenBase getBiome() { + return getMultiblockLogic().getController().getBiome(); + } + + /* IBeeHousing */ + @Override + public Iterable<IBeeModifier> getBeeModifiers() { + return getMultiblockLogic().getController().getBeeModifiers(); + } + + @Override + public Iterable<IBeeListener> getBeeListeners() { + return getMultiblockLogic().getController().getBeeListeners(); + } + + @Override + public IBeeHousingInventory getBeeInventory() { + return getMultiblockLogic().getController().getBeeInventory(); + } + + @Override + public IBeekeepingLogic getBeekeepingLogic() { + return getMultiblockLogic().getController().getBeekeepingLogic(); + } + + @Override + public Vec3 getBeeFXCoordinates() { + return getMultiblockLogic().getController().getBeeFXCoordinates(); + } + + /* IClimatised */ + @Override + public EnumTemperature getTemperature() { + return getMultiblockLogic().getController().getTemperature(); + } + + @Override + public EnumHumidity getHumidity() { + return getMultiblockLogic().getController().getHumidity(); + } + + @Override + public int getBlockLightValue() { + return getMultiblockLogic().getController().getBlockLightValue(); + } + + @Override + public boolean canBlockSeeTheSky() { + return getMultiblockLogic().getController().canBlockSeeTheSky(); + } + + @Override + public IErrorLogic getErrorLogic() { + return getMultiblockLogic().getController().getErrorLogic(); + } + + @Override + public IAccessHandler getAccessHandler() { + return getMultiblockLogic().getController().getAccessHandler(); + } + + @Override + public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) { + getMultiblockLogic().getController().onSwitchAccess(oldAccess, newAccess); + } + + @Override + public IInventoryAdapter getInternalInventory() { + return getMultiblockLogic().getController().getInternalInventory(); + } + + @Override + public String getUnlocalizedTitle() { + return unlocalizedTitle; + } + + /* IHintSource */ + @Override + public List<String> getHints() { + return Config.hints.get("apiary"); + } + + /* IClimatised */ + @Override + public float getExactTemperature() { + return getMultiblockLogic().getController().getExactTemperature(); + } + + @Override + public float getExactHumidity() { + return getMultiblockLogic().getController().getExactHumidity(); + } + + /* IStreamableGui */ + @Override + public void writeGuiData(DataOutputStreamForestry data) throws IOException { + getMultiblockLogic().getController().writeGuiData(data); + } + + @Override + public void readGuiData(DataInputStreamForestry data) throws IOException { + getMultiblockLogic().getController().readGuiData(data); + } + + @Override + public Object getGui(EntityPlayer player, int data) { + //return new GuiAlveary(player.inventory, this); + return null; //TODO + } + + @Override + public Object getContainer(EntityPlayer player, int data) { + //return new ContainerAlveary(player.inventory, this); + return null; //TODO + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/TileAlvearyMutatron.java b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/TileAlvearyMutatron.java new file mode 100644 index 0000000000..c396acf325 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/TileAlvearyMutatron.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.apiculture.multiblock; + +import java.util.Map.Entry; +import java.util.Stack; + +import miscutil.core.intermod.forestry.apiculture.blocks.FR_BlockAlveary; +import miscutil.core.intermod.forestry.apiculture.multiblock.inventory.FR_ContainerAlvearyMutatron; +import miscutil.core.intermod.forestry.apiculture.multiblock.inventory.FR_GuiAlvearyMutatron; +import miscutil.core.intermod.forestry.apiculture.multiblock.inventory.FR_InventoryMutatron; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import forestry.api.apiculture.BeeManager; +import forestry.api.apiculture.EnumBeeType; +import forestry.api.apiculture.IBee; +import forestry.api.multiblock.IAlvearyComponent; +import forestry.apiculture.blocks.BlockAlveary; +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 TileAlvearyMutatron extends FR_TileAlveary implements ISidedInventory, IActivatable, IAlvearyComponent.Active { + + private final FR_InventoryMutatron inventory; + private final Stack<ItemStack> pendingSpawns = new Stack<>(); + private boolean active; + + public TileAlvearyMutatron() { + super(FR_BlockAlveary.Type.MUTATRON); + this.inventory = new FR_InventoryMutatron(this); + } + + @Override + public IInventoryAdapter getInternalInventory() { + return inventory; + } + + @Override + public boolean allowsAutomation() { + return true; + } + + /* UPDATING */ + @Override + public void updateServer(int tickCount) { + if (pendingSpawns.size() > 0) { + setActive(true); + if (tickCount % 1000 == 0) { + trySpawnSwarm(); + } + } else { + setActive(false); + } + + if (tickCount % 500 != 0) { + return; + } + + ItemStack princessStack = getPrincessStack(); + if (princessStack == null) { + return; + } + + int chance = consumeInducerAndGetChance(); + if (chance == 0) { + return; + } + + // Try to spawn princess + if (worldObj.rand.nextInt(1000) >= chance) { + return; + } + + // Queue swarm spawn + IBee princess = BeeManager.beeRoot.getMember(princessStack); + princess.setIsNatural(false); + pendingSpawns.push(BeeManager.beeRoot.getMemberStack(princess, EnumBeeType.PRINCESS.ordinal())); + } + + @Override + public void updateClient(int tickCount) { + + } + + private ItemStack getPrincessStack() { + ItemStack princessStack = getMultiblockLogic().getController().getBeeInventory().getQueen(); + + if (BeeManager.beeRoot.isMated(princessStack)) { + return princessStack; + } + + return null; + } + + private int consumeInducerAndGetChance() { + if (getInternalInventory() == null) { + return 0; + } + + for (IInvSlot slot : InventoryIterator.getIterable(getInternalInventory())) { + ItemStack stack = slot.getStackInSlot(); + for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) { + if (ItemStackUtil.isIdenticalItem(entry.getKey(), stack)) { + slot.decreaseStackInSlot(); + return entry.getValue(); + } + } + } + + return 0; + } + + private void trySpawnSwarm() { + + ItemStack toSpawn = pendingSpawns.peek(); + HiveDescriptionSwarmer hiveDescription = new HiveDescriptionSwarmer(toSpawn); + Hive hive = new Hive(hiveDescription); + + int chunkX = (xCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16; + int chunkZ = (zCoord + worldObj.rand.nextInt(40 * 2) - 40) / 16; + + if (HiveDecorator.genHive(worldObj, worldObj.rand, chunkX, chunkZ, hive)) { + pendingSpawns.pop(); + } + } + + /* NETWORK */ + + @Override + protected void encodeDescriptionPacket(NBTTagCompound packetData) { + super.encodeDescriptionPacket(packetData); + packetData.setBoolean("Active", active); + } + + @Override + protected void decodeDescriptionPacket(NBTTagCompound packetData) { + super.decodeDescriptionPacket(packetData); + setActive(packetData.getBoolean("Active")); + } + + /* TEXTURES */ + @Override + public int getIcon(int side) { + if (side == 0 || side == 1) { + return BlockAlveary.BOTTOM; + } + + if (active) { + return BlockAlveary.ALVEARY_SWARMER_ON; + } else { + return BlockAlveary.ALVEARY_SWARMER_OFF; + } + } + + /* SAVING & LOADING */ + @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); + pendingSpawns.add(ItemStack.loadItemStackFromNBT(nbttagcompound1)); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbttagcompound) { + super.writeToNBT(nbttagcompound); + nbttagcompound.setBoolean("Active", active); + + NBTTagList nbttaglist = new NBTTagList(); + ItemStack[] offspring = pendingSpawns.toArray(new ItemStack[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 active; + } + + @Override + public void setActive(boolean active) { + if (this.active == active) { + return; + } + + this.active = active; + + if (!worldObj.isRemote) { + Proxies.net.sendNetworkPacket(new PacketActiveUpdate(this), worldObj); + } + } + + @Override + public Object getGui(EntityPlayer player, int data) { + return new FR_GuiAlvearyMutatron(player.inventory, this); + } + + @Override + public Object getContainer(EntityPlayer player, int data) { + return new FR_ContainerAlvearyMutatron(player.inventory, this); + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_ContainerAlvearyMutatron.java b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_ContainerAlvearyMutatron.java new file mode 100644 index 0000000000..3a4f76dfaa --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_ContainerAlvearyMutatron.java @@ -0,0 +1,28 @@ +package miscutil.core.intermod.forestry.apiculture.multiblock.inventory; + +import miscutil.core.intermod.forestry.apiculture.multiblock.TileAlvearyMutatron; +import net.minecraft.entity.player.InventoryPlayer; +import forestry.core.gui.ContainerTile; +import forestry.core.gui.slots.SlotFiltered; + +public class FR_ContainerAlvearyMutatron extends ContainerTile<TileAlvearyMutatron> { + public FR_ContainerAlvearyMutatron(InventoryPlayer player, TileAlvearyMutatron tile) { + super(tile, player, 8, 87); + this.addSlotToContainer(new SlotFiltered(tile, 0, 79, 52)); + this.addSlotToContainer(new SlotFiltered(tile, 1, 100, 39)); + this.addSlotToContainer(new SlotFiltered(tile, 2, 58, 39)); + this.addSlotToContainer(new SlotFiltered(tile, 3, 79, 26)); + } +} + + +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_GuiAlvearyMutatron.java b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_GuiAlvearyMutatron.java new file mode 100644 index 0000000000..212fff895c --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_GuiAlvearyMutatron.java @@ -0,0 +1,26 @@ +package miscutil.core.intermod.forestry.apiculture.multiblock.inventory; + +import miscutil.core.intermod.forestry.apiculture.multiblock.TileAlvearyMutatron; +import miscutil.core.intermod.forestry.core.gui.FR_GuiForestryTitled; +import miscutil.core.lib.CORE; +import net.minecraft.entity.player.InventoryPlayer; + +public class FR_GuiAlvearyMutatron extends FR_GuiForestryTitled<FR_ContainerAlvearyMutatron, TileAlvearyMutatron> { + + public FR_GuiAlvearyMutatron(InventoryPlayer inventory, TileAlvearyMutatron tile) { + super(CORE.MODID+"/swarmer.png", new FR_ContainerAlvearyMutatron(inventory, tile), tile); + } + + } + + +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/
\ No newline at end of file diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_InventoryMutatron.java b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_InventoryMutatron.java new file mode 100644 index 0000000000..16032046f9 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/FR_InventoryMutatron.java @@ -0,0 +1,29 @@ +package miscutil.core.intermod.forestry.apiculture.multiblock.inventory; + +import miscutil.core.intermod.forestry.apiculture.multiblock.TileAlvearyMutatron; +import net.minecraft.item.ItemStack; +import forestry.api.apiculture.BeeManager; +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.ItemStackUtil; + +public class FR_InventoryMutatron extends InventoryAdapterTile<TileAlvearyMutatron> { + public FR_InventoryMutatron(TileAlvearyMutatron alvearyMutatron) { + super(alvearyMutatron, 4, "mutatronInv"); + } + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return ItemStackUtil.containsItemStack(BeeManager.inducers.keySet(), itemStack); + } +} + + +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/
\ No newline at end of file diff --git a/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/MutatronHandler.java b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/MutatronHandler.java new file mode 100644 index 0000000000..1a66cafb0d --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/apiculture/multiblock/inventory/MutatronHandler.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.apiculture.multiblock.inventory; + +public class MutatronHandler { + + + + + + + + +}
\ No newline at end of file diff --git a/src/Java/miscutil/core/intermod/forestry/core/gui/FR_FontRenderer.java b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_FontRenderer.java new file mode 100644 index 0000000000..62876c0bea --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_FontRenderer.java @@ -0,0 +1,111 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.core.gui; + +import net.minecraft.client.gui.FontRenderer; + +import org.lwjgl.opengl.GL11; + +import forestry.core.render.FontColour; + +public class FR_FontRenderer { + private static final int LINE_HEIGHT = 12; + + private final FR_GuiForestry guiForestry; + private final int defaultFontColor; + private FontRenderer fontRendererObj; + + public int column0; + public int column1; + public int column2; + public int line; + + public FR_FontRenderer(FR_GuiForestry guiForestry, FontColour fontColour) { + this.guiForestry = guiForestry; + this.defaultFontColor = fontColour.get("gui.screen"); + } + + public void setFontRendererObj(FontRenderer fontRendererObj) { + this.fontRendererObj = fontRendererObj; + } + + public void startPage() { + line = LINE_HEIGHT; + GL11.glPushMatrix(); + } + + public void startPage(int column0, int column1, int column2) { + + this.column0 = column0; + this.column1 = column1; + this.column2 = column2; + + startPage(); + } + + public int getLineY() { + return line; + } + + public void newLine() { + line += LINE_HEIGHT; + } + + public void newLineCompressed() { + line += (LINE_HEIGHT - 2); + } + + public void newLine(int lineHeight) { + line += lineHeight; + } + + public void endPage() { + GL11.glPopMatrix(); + } + + public void drawRow(String text0, String text1, String text2, int colour0, int colour1, int colour2) { + drawLine(text0, column0, colour0); + drawLine(text1, column1, colour1); + drawLine(text2, column2, colour2); + } + + public void drawLine(String text, int x) { + drawLine(text, x, defaultFontColor); + } + + public void drawSplitLine(String text, int x, int maxWidth) { + drawSplitLine(text, x, maxWidth, defaultFontColor); + } + + public void drawCenteredLine(String text, int x, int color) { + drawCenteredLine(text, x, guiForestry.getSizeX(), color); + } + + public void drawCenteredLine(String text, int x, int width, int color) { + fontRendererObj.drawString(text, guiForestry.getGuiLeft() + x + getCenteredOffset(text, width), guiForestry.getGuiTop() + line, color); + } + + public void drawLine(String text, int x, int color) { + fontRendererObj.drawString(text, guiForestry.getGuiLeft() + x, guiForestry.getGuiTop() + line, color); + } + + public void drawSplitLine(String text, int x, int maxWidth, int color) { + fontRendererObj.drawSplitString(text, guiForestry.getGuiLeft() + x, guiForestry.getGuiTop() + line, maxWidth, color); + } + + public int getCenteredOffset(String string) { + return getCenteredOffset(string, guiForestry.getSizeX()); + } + + public int getCenteredOffset(String string, int xWidth) { + return (xWidth - fontRendererObj.getStringWidth(string)) / 2; + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiForestry.java b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiForestry.java new file mode 100644 index 0000000000..1bfbbd388e --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiForestry.java @@ -0,0 +1,272 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.core.gui; + +import java.util.List; + +import miscutil.core.lib.CORE; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import forestry.api.core.IErrorLogicSource; +import forestry.api.core.IErrorSource; +import forestry.core.access.IRestrictedAccess; +import forestry.core.config.Config; +import forestry.core.gui.IHintSource; +import forestry.core.gui.ledgers.ClimateLedger; +import forestry.core.gui.ledgers.HintLedger; +import forestry.core.gui.ledgers.LedgerManager; +import forestry.core.gui.ledgers.OwnerLedger; +import forestry.core.gui.ledgers.PowerLedger; +import forestry.core.proxy.Proxies; +import forestry.core.render.FontColour; +import forestry.core.tiles.IClimatised; +import forestry.core.tiles.IPowerHandler; + +public abstract class FR_GuiForestry<C extends Container, I extends IInventory> extends GuiContainer { + protected final I inventory; + protected final C container; + + public final ResourceLocation textureFile; + protected final FR_WidgetManager widgetManager; + protected LedgerManager ledgerManager; + protected FR_FontRenderer textLayout; + protected FontColour fontColor; + + protected FR_GuiForestry(String texture, C container, I inventory) { + this(new ResourceLocation(CORE.MODID, texture), container, inventory); + } + + protected FR_GuiForestry(ResourceLocation texture, C container, I inventory) { + super(container); + + this.widgetManager = new FR_WidgetManager(this); + + this.textureFile = texture; + + this.inventory = inventory; + this.container = container; + + this.fontColor = new FontColour(Proxies.render.getSelectedTexturePack()); + this.textLayout = new FR_FontRenderer(this, this.fontColor); + } + + @Override + public void setWorldAndResolution(Minecraft minecraft, int width, int height) { + super.setWorldAndResolution(minecraft, width, height); + textLayout.setFontRendererObj(fontRendererObj); + } + + /* LEDGERS */ + @Override + public void initGui() { + super.initGui(); + + int maxLedgerWidth = (this.width - this.xSize) / 2; + //this.ledgerManager = new LedgerManager(this, maxLedgerWidth); + + addLedgers(); + } + + protected void addLedgers() { + if (inventory instanceof IErrorSource) { + ledgerManager.add((IErrorSource) inventory); + } + + if (inventory instanceof IErrorLogicSource) { + IErrorLogicSource errorLogicSource = (IErrorLogicSource) inventory; + ledgerManager.add(errorLogicSource.getErrorLogic()); + } + + if (inventory instanceof IClimatised) { + ledgerManager.add(new ClimateLedger(ledgerManager, (IClimatised) inventory)); + } + + if (Config.enableEnergyStat && inventory instanceof IPowerHandler && ((IPowerHandler) inventory).getEnergyManager().getMaxEnergyStored() > 0) { + ledgerManager.add(new PowerLedger(ledgerManager, (IPowerHandler) inventory)); + } + + if (Config.enableHints && inventory instanceof IHintSource) { + IHintSource hintSource = (IHintSource) inventory; + List<String> hints = hintSource.getHints(); + if (hints != null && hints.size() > 0) { + ledgerManager.add(new HintLedger(ledgerManager, hintSource)); + } + } + + if (inventory instanceof IRestrictedAccess) { + ledgerManager.add(new OwnerLedger(ledgerManager, (IRestrictedAccess) inventory)); + } + } + + @Override + public void onGuiClosed() { + super.onGuiClosed(); + ledgerManager.onGuiClosed(); + } + + public FontColour getFontColor() { + return fontColor; + } + + public FontRenderer getFontRenderer() { + return fontRendererObj; + } + + @Override + protected void mouseClicked(int xPos, int yPos, int mouseButton) { + super.mouseClicked(xPos, yPos, mouseButton); + + // / Handle ledger clicks + ledgerManager.handleMouseClicked(xPos, yPos, mouseButton); + widgetManager.handleMouseClicked(xPos, yPos, mouseButton); + } + + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int eventType) { + super.mouseMovedOrUp(mouseX, mouseY, eventType); + + widgetManager.handleMouseRelease(mouseX, mouseY, eventType); + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int mouseButton, long time) { + + widgetManager.handleMouseMove(mouseX, mouseY, mouseButton, time); + + super.mouseClickMove(mouseX, mouseY, mouseButton, time); + } + + protected Slot getSlotAtPosition(int par1, int par2) { + for (int k = 0; k < this.inventorySlots.inventorySlots.size(); ++k) { + Slot slot = (Slot) this.inventorySlots.inventorySlots.get(k); + + if (isMouseOverSlot(slot, par1, par2)) { + return slot; + } + } + + return null; + } + + private boolean isMouseOverSlot(Slot par1Slot, int par2, int par3) { + return this.func_146978_c(par1Slot.xDisplayPosition, par1Slot.yDisplayPosition, 16, 16, par2, par3); + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + { + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + ledgerManager.drawTooltips(mouseX, mouseY); + + InventoryPlayer playerInv = mc.thePlayer.inventory; + + if (playerInv.getItemStack() == null) { + FR_GuiUtil.drawToolTips(this, widgetManager.getWidgets(), mouseX, mouseY); + FR_GuiUtil.drawToolTips(this, buttonList, mouseX, mouseY); + FR_GuiUtil.drawToolTips(this, inventorySlots.inventorySlots, mouseX, mouseY); + } + } + GL11.glPopAttrib(); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { + bindTexture(textureFile); + + int x = (width - xSize) / 2; + int y = (height - ySize) / 2; + drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + { + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glPushMatrix(); + { + GL11.glTranslatef(guiLeft, guiTop, 0.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + + drawWidgets(); + } + GL11.glPopMatrix(); + } + GL11.glPopAttrib(); + + bindTexture(textureFile); + } + + protected void drawWidgets() { + ledgerManager.drawLedgers(); + widgetManager.drawWidgets(); + } + + protected void bindTexture(ResourceLocation texturePath) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + Proxies.render.bindTexture(texturePath); + } + + public void setZLevel(float level) { + this.zLevel = level; + } + + public static RenderItem getItemRenderer() { + return itemRender; + } + + public int getSizeX() { + return xSize; + } + + public int getSizeY() { + return ySize; + } + + public int getGuiLeft() { + return guiLeft; + } + + public int getGuiTop() { + return guiTop; + } + + @Override + public void drawGradientRect(int par1, int par2, int par3, int par4, int par5, int par6) { + super.drawGradientRect(par1, par2, par3, par4, par5, par6); + } +} + + + + diff --git a/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiForestryTitled.java b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiForestryTitled.java new file mode 100644 index 0000000000..c338c83ce0 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiForestryTitled.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.core.gui; + +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.util.StatCollector; +import forestry.core.tiles.ITitled; + +public abstract class FR_GuiForestryTitled<C extends Container, I extends ITitled & IInventory> extends FR_GuiForestry<C, I> { + + protected FR_GuiForestryTitled(String texture, C container, I inventory) { + super(texture, container, inventory); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); + + String name = StatCollector.translateToLocal(inventory.getUnlocalizedTitle()); + textLayout.line = 6; + textLayout.drawCenteredLine(name, 0, fontColor.get("gui.title")); + bindTexture(textureFile); + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiUtil.java b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiUtil.java new file mode 100644 index 0000000000..a4118812c4 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_GuiUtil.java @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.core.gui; + +import java.awt.Color; +import java.util.Collection; + +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; + +import org.lwjgl.opengl.GL11; + +import forestry.core.gui.tooltips.IToolTipProvider; +import forestry.core.gui.tooltips.ToolTip; +import forestry.core.gui.tooltips.ToolTipLine; + +public class FR_GuiUtil { + public static void drawItemStack(FR_GuiForestry gui, ItemStack stack, int xPos, int yPos) { + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + RenderHelper.enableGUIStandardItemLighting(); + + RenderItem itemRender = FR_GuiForestry.getItemRenderer(); + + GL11.glTranslatef(0.0F, 0.0F, 32.0F); + gui.setZLevel(100.0F); + itemRender.zLevel = 100.0F; + FontRenderer font = null; + if (stack != null) { + font = stack.getItem().getFontRenderer(stack); + } + if (font == null) { + font = gui.getFontRenderer(); + } + itemRender.renderItemAndEffectIntoGUI(font, gui.mc.getTextureManager(), stack, xPos, yPos); + itemRender.renderItemOverlayIntoGUI(font, gui.mc.getTextureManager(), stack, xPos, yPos); + gui.setZLevel(0.0F); + itemRender.zLevel = 0.0F; + + RenderHelper.disableStandardItemLighting(); + GL11.glPopAttrib(); + } + + public static void drawToolTips(FR_GuiForestry gui, ToolTip toolTips, int mouseX, int mouseY) { + if (toolTips == null) { + return; + } + if (toolTips.isEmpty()) { + return; + } + + RenderItem itemRender = FR_GuiForestry.getItemRenderer(); + FontRenderer fontRendererObj = gui.getFontRenderer(); + + int left = gui.getGuiLeft(); + int top = gui.getGuiTop(); + int length = 0; + int height = 0; + int x; + int y; + + for (ToolTipLine tip : toolTips) { + y = fontRendererObj.getStringWidth(tip.toString()); + + height += 10 + tip.getSpacing(); + if (y > length) { + length = y; + } + } + + x = mouseX - left + 12; + y = mouseY - top - 12; + + gui.setZLevel(300.0F); + itemRender.zLevel = 300.0F; + Color backgroundColor = new Color(16, 0, 16, 240); + int backgroundColorInt = backgroundColor.getRGB(); + gui.drawGradientRect(x - 3, y - 4, x + length + 2, y - 3, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x - 3, y + height + 1, x + length + 2, y + height + 2, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x - 3, y - 3, x + length + 2, y + height + 1, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x - 4, y - 3, x - 3, y + height + 1, backgroundColorInt, backgroundColorInt); + gui.drawGradientRect(x + length + 2, y - 3, x + length + 3, y + height + 1, backgroundColorInt, backgroundColorInt); + + Color borderColorTop = new Color(80, 0, 255, 80); + int borderColorTopInt = borderColorTop.getRGB(); + Color borderColorBottom = new Color((borderColorTopInt & 0xfefefe) >> 1 | borderColorTopInt & -0x1000000, true); + int borderColorBottomInt = borderColorBottom.getRGB(); + gui.drawGradientRect(x - 3, y - 3 + 1, x - 3 + 1, y + height, borderColorTopInt, borderColorBottomInt); + gui.drawGradientRect(x + length + 1, y - 3 + 1, x + length + 2, y + height, borderColorTopInt, borderColorBottomInt); + gui.drawGradientRect(x - 3, y - 3, x + length + 2, y - 3 + 1, borderColorTopInt, borderColorTopInt); + gui.drawGradientRect(x - 3, y + height, x + length + 2, y + height + 1, borderColorBottomInt, borderColorBottomInt); + + boolean firstLine = true; + for (ToolTipLine tip : toolTips) { + String line; + + if (firstLine) { + line = tip.toString(); + } else { + line = EnumChatFormatting.GRAY + tip.toString(); + } + + fontRendererObj.drawStringWithShadow(line, x, y, -1); + + y += 10 + tip.getSpacing(); + + firstLine = false; + } + + gui.setZLevel(0.0F); + itemRender.zLevel = 0.0F; + } + + public static void drawToolTips(FR_GuiForestry gui, Collection<?> objects, int mouseX, int mouseY) { + for (Object obj : objects) { + if (!(obj instanceof IToolTipProvider)) { + continue; + } + IToolTipProvider provider = (IToolTipProvider) obj; + if (!provider.isToolTipVisible()) { + continue; + } + ToolTip tips = provider.getToolTip(mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop()); + if (tips == null) { + continue; + } + boolean mouseOver = provider.isMouseOver(mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop()); + tips.onTick(mouseOver); + if (mouseOver && tips.isReady()) { + tips.refresh(); + drawToolTips(gui, tips, mouseX, mouseY); + } + } + } +} diff --git a/src/Java/miscutil/core/intermod/forestry/core/gui/FR_WidgetManager.java b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_WidgetManager.java new file mode 100644 index 0000000000..5f068b4189 --- /dev/null +++ b/src/Java/miscutil/core/intermod/forestry/core/gui/FR_WidgetManager.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package miscutil.core.intermod.forestry.core.gui; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.client.Minecraft; + +import org.lwjgl.opengl.GL11; + +import forestry.core.gui.widgets.Widget; +import forestry.core.proxy.Proxies; + +public class FR_WidgetManager { + + public final FR_GuiForestry gui; + public final Minecraft minecraft; + protected final List<Widget> widgets = new ArrayList<>(); + + public FR_WidgetManager(FR_GuiForestry gui) { + this.gui = gui; + this.minecraft = Proxies.common.getClientInstance(); + } + + public void add(Widget slot) { + this.widgets.add(slot); + } + + public void remove(Widget slot) { + this.widgets.remove(slot); + } + + public void clear() { + this.widgets.clear(); + } + + public List<Widget> getWidgets() { + return widgets; + } + + public Widget getAtPosition(int mX, int mY) { + for (Widget slot : widgets) { + if (slot.isMouseOver(mX, mY)) { + return slot; + } + } + + return null; + } + + public void drawWidgets() { + gui.setZLevel(100.0F); + FR_GuiForestry.getItemRenderer().zLevel = 100.0F; + for (Widget slot : widgets) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + slot.draw(0, 0); + } + gui.setZLevel(0.0F); + FR_GuiForestry.getItemRenderer().zLevel = 0.0F; + + } + + public void handleMouseClicked(int mouseX, int mouseY, int mouseButton) { + Widget slot = getAtPosition(mouseX - gui.getGuiLeft(), mouseY - gui.getGuiTop()); + if (slot != null) { + slot.handleMouseClick(mouseX, mouseY, mouseButton); + } + } + + public void handleMouseRelease(int mouseX, int mouseY, int eventType) { + for (Widget slot : widgets) { + slot.handleMouseRelease(mouseX, mouseY, eventType); + } + } + + public void handleMouseMove(int mouseX, int mouseY, int mouseButton, long time) { + for (Widget slot : widgets) { + slot.handleMouseMove(mouseX, mouseY, mouseButton, time); + } + } +} diff --git a/src/Java/miscutil/core/lib/LoadedMods.java b/src/Java/miscutil/core/lib/LoadedMods.java index 6baa6c115a..f7afcc3225 100644 --- a/src/Java/miscutil/core/lib/LoadedMods.java +++ b/src/Java/miscutil/core/lib/LoadedMods.java @@ -23,6 +23,8 @@ public class LoadedMods { public static boolean Railcraft = false; public static boolean Growthcraft = false; public static boolean CoFHCore = false; + public static boolean Forestry = false; + public static boolean MagicBees = false; public static boolean MiscUtils = true; //Dummy For MetaData Lookups in MT Wrapper @@ -114,6 +116,16 @@ public class LoadedMods { Utils.LOG_INFO("Components enabled for: CoFHCore"); totalMods++; } + if (Loader.isModLoaded("Forestry") == true){ + Forestry = true; + Utils.LOG_INFO("Components enabled for: Forestry"); + totalMods++; + } + if (Loader.isModLoaded("MagicBees") == true){ + MagicBees = true; + Utils.LOG_INFO("Components enabled for: MagicBees"); + totalMods++; + } Utils.LOG_INFO("Content found for "+totalMods+" mods"); diff --git a/src/Java/miscutil/gregtech/api/objects/GregtechFluid.java b/src/Java/miscutil/gregtech/api/objects/GregtechFluid.java new file mode 100644 index 0000000000..6352883995 --- /dev/null +++ b/src/Java/miscutil/gregtech/api/objects/GregtechFluid.java @@ -0,0 +1,27 @@ +package miscutil.gregtech.api.objects; + +import gregtech.api.GregTech_API; +import miscutil.core.lib.CORE; +import net.minecraftforge.fluids.Fluid; + +public class GregtechFluid extends Fluid implements Runnable { + public final String mTextureName; + private final short[] mRGBa; + + public GregtechFluid(String aName, String aTextureName, short[] aRGBa) { + super(aName); + mRGBa = aRGBa; + mTextureName = aTextureName; + GregTech_API.sGTBlockIconload.add(this); + } + + @Override + public int getColor() { + return (Math.max(0, Math.min(255, mRGBa[0])) << 16) | (Math.max(0, Math.min(255, mRGBa[1])) << 8) | Math.max(0, Math.min(255, mRGBa[2])); + } + + @Override + public void run() { + setIcons(GregTech_API.sBlockIcons.registerIcon(CORE.MODID + "fluids/fluid." + mTextureName)); + } +}
\ No newline at end of file |