├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src └── main │ └── java │ └── cofh │ ├── api │ ├── CoFHAPIProps.java │ ├── package-info.java │ ├── core │ │ ├── package-info.java │ │ ├── IAccelerable.java │ │ ├── IPortableData.java │ │ ├── IAugmentable.java │ │ └── ISecurable.java │ ├── item │ │ ├── package-info.java │ │ ├── IInventoryContainerItem.java │ │ ├── IUpgradeItem.java │ │ ├── IAugmentItem.java │ │ ├── IMultiModeItem.java │ │ └── IToolHammer.java │ ├── util │ │ ├── package-info.java │ │ └── ThermalFoundationHelper.java │ ├── block │ │ ├── package-info.java │ │ ├── IBlockConfigGui.java │ │ ├── IDismantleable.java │ │ └── IBlockInfo.java │ ├── energy │ │ ├── package-info.java │ │ ├── IEnergyConnection.java │ │ ├── IEnergyHandler.java │ │ ├── IEnergyReceiver.java │ │ ├── IEnergyProvider.java │ │ ├── IEnergyStorage.java │ │ ├── TileEnergyHandler.java │ │ ├── IEnergyContainerItem.java │ │ ├── ItemEnergyContainer.java │ │ ├── EnergyStorage.java │ │ └── IEnergyTransport.java │ └── tileentity │ │ ├── package-info.java │ │ ├── IInventoryConnection.java │ │ ├── IEnergyInfo.java │ │ ├── ITileInfo.java │ │ └── IReconfigurableFacing.java │ └── lib │ ├── CoFHLibProps.java │ ├── gui │ ├── GuiBook.java │ ├── package-info.java │ ├── GuiProps.java │ ├── element │ │ ├── package-info.java │ │ ├── listbox │ │ │ ├── IListBoxElement.java │ │ │ ├── package-info.java │ │ │ ├── ListBoxElementText.java │ │ │ ├── SliderVertical.java │ │ │ └── SliderHorizontal.java │ │ ├── ElementSimpleBox.java │ │ ├── ElementSimple.java │ │ ├── ElementFluid.java │ │ ├── ElementTextFieldLimited.java │ │ ├── ElementTextFieldFiltered.java │ │ ├── ElementIcon.java │ │ ├── ElementButtonBase.java │ │ ├── ElementDualScaled.java │ │ ├── ElementButtonOption.java │ │ ├── ElementSimpleTooltip.java │ │ ├── ElementButtonManaged.java │ │ ├── ElementEnergyStored.java │ │ └── ElementFluidTank.java │ ├── slot │ │ ├── package-info.java │ │ ├── ISlotValidator.java │ │ ├── SlotRemoveOnly.java │ │ ├── SlotPotion.java │ │ ├── SlotAcceptValid.java │ │ ├── SlotEnergy.java │ │ ├── SlotPotionIngredient.java │ │ ├── SlotAcceptAssignable.java │ │ ├── SlotValidated.java │ │ ├── SlotCraftingLocked.java │ │ ├── SlotAcceptInsertable.java │ │ ├── SlotFalseCopy.java │ │ ├── SlotLocked.java │ │ ├── SlotSpecificItem.java │ │ ├── SlotViewOnly.java │ │ ├── SlotInvisible.java │ │ └── SlotCustomInventory.java │ ├── container │ │ ├── package-info.java │ │ ├── ContainerFalse.java │ │ ├── ICustomInventory.java │ │ ├── IAugmentableContainer.java │ │ └── CustomInventoryWrapper.java │ ├── TabTracker.java │ └── GuiColor.java │ ├── audio │ ├── ISoundSource.java │ ├── package-info.java │ └── SoundTile.java │ ├── package-info.java │ ├── util │ ├── package-info.java │ ├── helpers │ │ ├── package-info.java │ │ ├── SoundHelper.java │ │ ├── ServerHelper.java │ │ ├── ColorHelper.java │ │ ├── WrenchHelper.java │ │ └── DamageHelper.java │ ├── WeightedRandomNBTTag.java │ ├── CharacterSingleton.java │ ├── numbers │ │ ├── INumberProvider.java │ │ ├── SkellamRandomProvider.java │ │ ├── ConstantProvider.java │ │ └── UniformRandomProvider.java │ ├── WeightedRandomWorldGenerator.java │ ├── WeightedRandomItemStack.java │ ├── TimeTracker.java │ ├── IdentityLinkedHashList.java │ ├── ItemWrapper.java │ ├── OreDictionaryProxy.java │ ├── capabilities │ │ ├── EnergyContainerItemWrapper.java │ │ └── FluidContainerItemWrapper.java │ ├── Rectangle4i.java │ ├── BlockWrapper.java │ ├── WeightedRandomBlock.java │ ├── ChunkCoord.java │ ├── ComparableItem.java │ └── RayTracer.java │ ├── world │ ├── package-info.java │ ├── feature │ │ ├── package-info.java │ │ ├── FeatureGenUniform.java │ │ ├── FeatureGenSurface.java │ │ ├── FeatureGenTopBlock.java │ │ ├── FeatureGenGaussian.java │ │ ├── FeatureGenCave.java │ │ ├── FeatureGenLargeVein.java │ │ ├── FeatureBase.java │ │ └── FeatureGenUnderfluid.java │ ├── IFeatureHandler.java │ ├── IFeatureParser.java │ ├── biome │ │ ├── BiomeInfoRarity.java │ │ ├── BiomeDictionaryArbiter.java │ │ └── BiomeInfo.java │ ├── WorldGenMulti.java │ ├── IGeneratorParser.java │ ├── IFeatureGenerator.java │ ├── WorldGenStalactite.java │ ├── WorldGenMinablePlate.java │ ├── WorldGenBoulder.java │ ├── WorldGenSpike.java │ └── WorldGenStalagmite.java │ └── inventory │ ├── package-info.java │ ├── IInventoryManager.java │ ├── InventoryManager.java │ ├── InventoryManagerSided.java │ ├── InventoryCraftingFalse.java │ ├── ComparableItemStackNBT.java │ ├── ComparableItemStackSafe.java │ ├── ComparableItemStack.java │ └── InventoryCraftingCustom.java ├── README.md ├── gradlew.bat └── .gitignore /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCBProject/CoFHLib/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/java/cofh/api/CoFHAPIProps.java: -------------------------------------------------------------------------------- 1 | package cofh.api; 2 | 3 | public class CoFHAPIProps { 4 | 5 | private CoFHAPIProps() { 6 | 7 | } 8 | 9 | public static final String VERSION = "1.7.0"; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/CoFHLibProps.java: -------------------------------------------------------------------------------- 1 | package cofh.lib; 2 | 3 | public class CoFHLibProps { 4 | 5 | private CoFHLibProps() { 6 | 7 | } 8 | 9 | public static final String VERSION = "1.7.0"; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/GuiBook.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui; 2 | 3 | import net.minecraft.client.gui.GuiScreen; 4 | 5 | public class GuiBook extends GuiScreen { 6 | 7 | protected int mouseX = 0; 8 | protected int mouseY = 0; 9 | 10 | } 11 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 14 12:28:28 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip 7 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/audio/ISoundSource.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.audio; 2 | 3 | public interface ISoundSource { 4 | 5 | /** 6 | * Should actually return an ISound. The object return prevents server crashes. 7 | */ 8 | Object getSound(); 9 | 10 | boolean shouldPlaySound(); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHAPIProps.VERSION, owner = "cofhlib", provides = "cofhapi") 6 | package cofh.api; 7 | 8 | import net.minecraftforge.fml.common.API; 9 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhcore", provides = "cofhlib") 6 | package cofh.lib; 7 | 8 | import net.minecraftforge.fml.common.API; 9 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|gui") 6 | package cofh.lib.gui; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/core/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHAPIProps.VERSION, owner = "cofhapi", provides = "cofhapi|core") 6 | package cofh.api.core; 7 | 8 | import cofh.api.CoFHAPIProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/item/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHAPIProps.VERSION, owner = "cofhapi", provides = "cofhapi|item") 6 | package cofh.api.item; 7 | 8 | import cofh.api.CoFHAPIProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHAPIProps.VERSION, owner = "cofhapi", provides = "cofhapi|util") 6 | package cofh.api.util; 7 | 8 | import cofh.api.CoFHAPIProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/block/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHAPIProps.VERSION, owner = "cofhapi", provides = "cofhapi|block") 6 | package cofh.api.block; 7 | 8 | import cofh.api.CoFHAPIProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHAPIProps.VERSION, owner = "cofhapi", provides = "cofhapi|energy") 6 | package cofh.api.energy; 7 | 8 | import cofh.api.CoFHAPIProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/audio/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|audio") 6 | package cofh.lib.audio; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|util") 6 | package cofh.lib.util; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|world") 6 | package cofh.lib.world; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/GuiProps.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui; 2 | 3 | public class GuiProps { 4 | 5 | /* GUI */ 6 | public static final String PATH_GFX = "cofh:textures/"; 7 | public static final String PATH_GUI = PATH_GFX + "gui/"; 8 | public static final String PATH_ELEMENTS = PATH_GUI + "elements/"; 9 | 10 | private GuiProps() { 11 | 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|inventory") 6 | package cofh.lib.inventory; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/tileentity/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHAPIProps.VERSION, owner = "cofhapi", provides = "cofhapi|tileentity") 6 | package cofh.api.tileentity; 7 | 8 | import cofh.api.CoFHAPIProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|gui|element") 6 | package cofh.lib.gui.element; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|gui|slot") 6 | package cofh.lib.gui.slot; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/container/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|gui|container") 6 | package cofh.lib.gui.container; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/helpers/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|util|helpers") 6 | package cofh.lib.util.helpers; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/listbox/IListBoxElement.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element.listbox; 2 | 3 | import cofh.lib.gui.element.ElementListBox; 4 | 5 | public interface IListBoxElement { 6 | 7 | int getHeight(); 8 | 9 | int getWidth(); 10 | 11 | Object getValue(); 12 | 13 | void draw(ElementListBox listBox, int x, int y, int backColor, int textColor); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|world|feature") 6 | package cofh.lib.world.feature; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/listbox/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * (C) 2014-2017 Team CoFH / CoFH / Cult of the Full Hub 3 | * http://www.teamcofh.com 4 | */ 5 | @API (apiVersion = CoFHLibProps.VERSION, owner = "cofhlib", provides = "cofhlib|gui|element|listbox") 6 | package cofh.lib.gui.element.listbox; 7 | 8 | import cofh.lib.CoFHLibProps; 9 | import net.minecraftforge.fml.common.API; 10 | 11 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/WeightedRandomNBTTag.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.nbt.NBTBase; 4 | import net.minecraft.util.WeightedRandom; 5 | 6 | public class WeightedRandomNBTTag extends WeightedRandom.Item { 7 | 8 | public final NBTBase tag; 9 | 10 | public WeightedRandomNBTTag(int weight, NBTBase tag) { 11 | 12 | super(weight); 13 | this.tag = tag; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/ISlotValidator.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.item.ItemStack; 4 | 5 | /** 6 | * Interface used in conjunction with {@link SlotValidated}. 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface ISlotValidator { 11 | 12 | /** 13 | * Essentially a passthrough so an arbitrary criterion can be checked against. 14 | */ 15 | boolean isItemValid(ItemStack stack); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/item/IInventoryContainerItem.java: -------------------------------------------------------------------------------- 1 | package cofh.api.item; 2 | 3 | import net.minecraft.item.ItemStack; 4 | 5 | /** 6 | * Implement this interface on Item classes that are themselves inventories. 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface IInventoryContainerItem { 11 | 12 | /** 13 | * Get the size of this inventory of this container item. 14 | */ 15 | int getSizeInventory(ItemStack container); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/container/ContainerFalse.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.container; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.Container; 5 | 6 | /** 7 | * Basic false container class. You'll know if you need one. 8 | * 9 | * @author King Lemming 10 | */ 11 | public final class ContainerFalse extends Container { 12 | 13 | @Override 14 | public boolean canInteractWith(EntityPlayer player) { 15 | 16 | return false; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/CharacterSingleton.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | public class CharacterSingleton implements CharSequence { 4 | 5 | public char character; 6 | 7 | @Override 8 | public int length() { 9 | 10 | return 1; 11 | } 12 | 13 | @Override 14 | public char charAt(int index) { 15 | 16 | return character; 17 | } 18 | 19 | @Override 20 | public CharSequence subSequence(int start, int end) { 21 | 22 | if (start == end) { 23 | return ""; 24 | } 25 | return this; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/numbers/INumberProvider.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.numbers; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | import net.minecraft.world.World; 5 | 6 | import java.util.Random; 7 | 8 | public interface INumberProvider { 9 | 10 | int intValue(World world, Random rand, BlockPos pos); 11 | 12 | long longValue(World world, Random rand, BlockPos pos); 13 | 14 | float floatValue(World world, Random rand, BlockPos pos); 15 | 16 | double doubleValue(World world, Random rand, BlockPos pos); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotRemoveOnly.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import net.minecraft.inventory.Slot; 5 | import net.minecraft.item.ItemStack; 6 | 7 | /** 8 | * Slot which players can only remove items from. 9 | */ 10 | public class SlotRemoveOnly extends Slot { 11 | 12 | public SlotRemoveOnly(IInventory inventory, int index, int x, int y) { 13 | 14 | super(inventory, index, x, y); 15 | } 16 | 17 | @Override 18 | public boolean isItemValid(ItemStack stack) { 19 | 20 | return false; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/WeightedRandomWorldGenerator.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.util.WeightedRandom; 4 | import net.minecraft.world.gen.feature.WorldGenerator; 5 | 6 | public final class WeightedRandomWorldGenerator extends WeightedRandom.Item { 7 | 8 | public final WorldGenerator generator; 9 | 10 | public WeightedRandomWorldGenerator(WorldGenerator worldgen) { 11 | 12 | this(worldgen, 100); 13 | } 14 | 15 | public WeightedRandomWorldGenerator(WorldGenerator worldgen, int weight) { 16 | 17 | super(weight); 18 | generator = worldgen; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/IFeatureHandler.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | /** 4 | * Provides an interface to allow for the addition of Features to world generation. 5 | * 6 | * See {@link IFeatureGenerator}. 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface IFeatureHandler { 11 | 12 | /** 13 | * Register a feature with an IFeatureHandler. 14 | * 15 | * @param feature The feature to register. 16 | * @return True if the registration was successful, false if a feature with that name existed. 17 | */ 18 | boolean registerFeature(IFeatureGenerator feature); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/container/ICustomInventory.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.container; 2 | 3 | import net.minecraft.item.ItemStack; 4 | 5 | /** 6 | * Interface to allow a Container to interact with a secondary inventory. 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface ICustomInventory { 11 | 12 | /** 13 | * @param inventoryIndex Internal index of the inventory (there may be multiple). Assume 0 as default. 14 | * @return An array of ItemStacks stored in the Inventory. 15 | */ 16 | ItemStack[] getInventorySlots(int inventoryIndex); 17 | 18 | int getSlotStackLimit(int slotIndex); 19 | 20 | void onSlotUpdate(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/core/IAccelerable.java: -------------------------------------------------------------------------------- 1 | package cofh.api.core; 2 | 3 | /** 4 | * Implemented on objects which perform a function that can be sped up. 5 | * 6 | * This is an elegant way of NOT calling another update(), preventing potential infinite-loop cases. 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface IAccelerable { 11 | 12 | /** 13 | * This method should be something small and low in CPU usage as it may be called multiple times per tick. 14 | * 15 | * The return is a measure of how much "work" was performed. In the case of an RF-using block, the amount of energy used. 16 | */ 17 | int updateAccelerable(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/IEnergyConnection.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | /** 6 | * Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not 7 | * accept it; otherwise just use IEnergyHandler. 8 | * 9 | * Note that {@link IEnergyHandler} is an extension of this. 10 | * 11 | * @author King Lemming 12 | */ 13 | public interface IEnergyConnection { 14 | 15 | /** 16 | * Returns TRUE if the TileEntity can connect on a given side. 17 | */ 18 | boolean canConnectEnergy(EnumFacing from); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/WeightedRandomItemStack.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.item.ItemStack; 4 | import net.minecraft.util.WeightedRandom; 5 | 6 | public class WeightedRandomItemStack extends WeightedRandom.Item { 7 | 8 | private final ItemStack stack; 9 | 10 | public WeightedRandomItemStack(ItemStack stack) { 11 | 12 | this(stack, 100); 13 | } 14 | 15 | public WeightedRandomItemStack(ItemStack stack, int weight) { 16 | 17 | super(weight); 18 | this.stack = stack; 19 | } 20 | 21 | public ItemStack getStack() { 22 | 23 | if (stack == null) { 24 | return null; 25 | } 26 | return stack.copy(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotPotion.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.init.Items; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.inventory.Slot; 6 | import net.minecraft.item.ItemStack; 7 | 8 | /** 9 | * Slot that will only accept Potions. 10 | */ 11 | public class SlotPotion extends Slot { 12 | 13 | public SlotPotion(IInventory inventory, int index, int x, int y) { 14 | 15 | super(inventory, index, x, y); 16 | } 17 | 18 | @Override 19 | public boolean isItemValid(ItemStack stack) { 20 | 21 | return stack != null && stack.getItem().equals(Items.POTIONITEM); //TODO Other potion items. 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/container/IAugmentableContainer.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.container; 2 | 3 | import net.minecraft.inventory.Slot; 4 | 5 | /** 6 | * Implement this interface on Container objects (the backend of a GUI). These are basically passthrough functions which should call back to the Tile Entity. 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface IAugmentableContainer { 11 | 12 | /** 13 | * Used by a tab to set lock status so that new Augments cannot be added (there may be many reasons for this). 14 | */ 15 | void setAugmentLock(boolean lock); 16 | 17 | /** 18 | * Returns the Augment slots. 19 | */ 20 | Slot[] getAugmentSlots(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotAcceptValid.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import net.minecraft.inventory.Slot; 5 | import net.minecraft.item.ItemStack; 6 | 7 | /** 8 | * Slot that will only accept ItemStacks when the IInventory returns true from isItemValidForSlot. 9 | */ 10 | public class SlotAcceptValid extends Slot { 11 | 12 | public SlotAcceptValid(IInventory inventory, int index, int x, int y) { 13 | 14 | super(inventory, index, x, y); 15 | } 16 | 17 | @Override 18 | public boolean isItemValid(ItemStack stack) { 19 | 20 | return stack != null && this.inventory.isItemValidForSlot(this.slotNumber, stack); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/IInventoryManager.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import net.minecraft.item.ItemStack; 4 | 5 | import java.util.Map; 6 | 7 | public interface IInventoryManager { 8 | 9 | boolean canAddItem(ItemStack stack, int slot); 10 | 11 | boolean canRemoveItem(ItemStack stack, int slot); 12 | 13 | ItemStack addItem(ItemStack stack); 14 | 15 | ItemStack removeItem(int maxRemove); 16 | 17 | ItemStack removeItem(int maxRemove, ItemStack type); 18 | 19 | ItemStack getSlotContents(int slot); 20 | 21 | int hasItem(ItemStack type); 22 | 23 | int findItem(ItemStack type); 24 | 25 | int[] getSlots(); 26 | 27 | Map getContents(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotEnergy.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import cofh.lib.util.helpers.EnergyHelper; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.inventory.Slot; 6 | import net.minecraft.item.ItemStack; 7 | 8 | /** 9 | * Slot which only accepts Energy (Redstone Flux) Containers as valid. 10 | * 11 | * @author King Lemming 12 | */ 13 | public class SlotEnergy extends Slot { 14 | 15 | public SlotEnergy(IInventory inventory, int index, int x, int y) { 16 | 17 | super(inventory, index, x, y); 18 | } 19 | 20 | @Override 21 | public boolean isItemValid(ItemStack stack) { 22 | 23 | return EnergyHelper.isEnergyContainerItem(stack); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotPotionIngredient.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import net.minecraft.inventory.Slot; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraftforge.common.brewing.BrewingRecipeRegistry; 7 | 8 | /** 9 | * Slot that will only accept Potion Ingredients. 10 | */ 11 | public class SlotPotionIngredient extends Slot { 12 | 13 | public SlotPotionIngredient(IInventory inventory, int index, int x, int y) { 14 | 15 | super(inventory, index, x, y); 16 | } 17 | 18 | @Override 19 | public boolean isItemValid(ItemStack stack) { 20 | 21 | return stack != null && BrewingRecipeRegistry.isValidIngredient(stack); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/InventoryManager.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import net.minecraft.inventory.ISidedInventory; 5 | import net.minecraft.util.EnumFacing; 6 | 7 | public class InventoryManager { 8 | 9 | private InventoryManager() { 10 | 11 | } 12 | 13 | public static IInventoryManager create(Object inventory, EnumFacing targetSide) { 14 | 15 | if (inventory instanceof ISidedInventory) { 16 | return new InventoryManagerSided((ISidedInventory) inventory, targetSide); 17 | } else if (inventory instanceof IInventory) { 18 | return new InventoryManagerStandard((IInventory) inventory, targetSide); 19 | } else { 20 | return null; 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/IFeatureParser.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import com.google.gson.JsonObject; 4 | import com.typesafe.config.Config; 5 | import org.apache.logging.log4j.Logger; 6 | 7 | public interface IFeatureParser { 8 | 9 | /** 10 | * Parse a {@link JsonObject} for registration with an with an {@link IFeatureHandler}. 11 | * 12 | * @param featureName The name of the feature to register. 13 | * @param genObject The JsonObject to parse. 14 | * @param log The {@link Logger} to log debug/error/etc. messages to. 15 | * @return The {@link IFeatureGenerator} to be registered with an IFeatureHandler 16 | */ 17 | IFeatureGenerator parseFeature(String featureName, Config genObject, Logger log); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/biome/BiomeInfoRarity.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.biome; 2 | 3 | import net.minecraft.world.biome.Biome; 4 | 5 | import java.util.Random; 6 | 7 | public class BiomeInfoRarity extends BiomeInfo { 8 | 9 | private final int rarity; 10 | 11 | public BiomeInfoRarity(String name, int r) { 12 | 13 | super(name); 14 | rarity = r; 15 | } 16 | 17 | public BiomeInfoRarity(Object d, int t, boolean wl, int r) { 18 | 19 | super(d, t, wl); 20 | rarity = r; 21 | } 22 | 23 | @Override 24 | public boolean isBiomeEqual(Biome biome, Random rand) { 25 | 26 | boolean r = super.isBiomeEqual(biome, rand); 27 | if (rand != null) { 28 | return r && (rarity <= 1 || rand.nextInt(rarity) == 0); 29 | } 30 | return r; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/TimeTracker.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.world.World; 4 | 5 | /** 6 | * A basic time tracker class. Nothing surprising here. 7 | * 8 | * @author King Lemming 9 | */ 10 | public class TimeTracker { 11 | 12 | private long lastMark = Long.MIN_VALUE; 13 | 14 | public boolean hasDelayPassed(World world, int delay) { 15 | 16 | long currentTime = world.getTotalWorldTime(); 17 | 18 | if (currentTime < lastMark) { 19 | lastMark = currentTime; 20 | return false; 21 | } else if (lastMark + delay <= currentTime) { 22 | lastMark = currentTime; 23 | return true; 24 | } 25 | return false; 26 | } 27 | 28 | public void markTime(World world) { 29 | 30 | lastMark = world.getTotalWorldTime(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/item/IUpgradeItem.java: -------------------------------------------------------------------------------- 1 | package cofh.api.item; 2 | 3 | import net.minecraft.item.ItemStack; 4 | 5 | public interface IUpgradeItem { 6 | 7 | /** 8 | * Enum for Upgrade Types - there aren't many. 9 | */ 10 | enum UpgradeType { 11 | INCREMENTAL, FULL, CREATIVE 12 | } 13 | 14 | /** 15 | * Get the Upgrade Type for a given Upgrade. 16 | * 17 | * @param stack ItemStack representing the Upgrade. 18 | * @return Upgrade Type of the stack. 19 | */ 20 | UpgradeType getUpgradeType(ItemStack stack); 21 | 22 | /** 23 | * Get the Upgrade Level for a given Upgrade. 24 | * 25 | * @param stack ItemStack representing the Upgrade. 26 | * @return Upgrade Level of the stack; -1 for a Creative Upgrade. 27 | */ 28 | int getUpgradeLevel(ItemStack stack); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/tileentity/IInventoryConnection.java: -------------------------------------------------------------------------------- 1 | package cofh.api.tileentity; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | /** 6 | * Implement this interface on TileEntities which should connect to item transportation blocks. 7 | */ 8 | public interface IInventoryConnection { 9 | 10 | /** 11 | * @param from Side to which a connector would connect 12 | * @return DEFAULT if the connector should decide how to connect; FORCE if the connector should always connect; DENY if the connector should never connect. 13 | */ 14 | ConnectionType canConnectInventory(EnumFacing from); 15 | 16 | enum ConnectionType { 17 | DEFAULT, FORCE, DENY; 18 | 19 | public final boolean canConnect = ordinal() != 2; 20 | public final boolean forceConnect = ordinal() == 1; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotAcceptAssignable.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import net.minecraft.inventory.Slot; 5 | import net.minecraft.item.Item; 6 | import net.minecraft.item.ItemStack; 7 | 8 | /** 9 | * Slot that will only accept ItemStacks whose items are a subclass of the given class. 10 | */ 11 | public class SlotAcceptAssignable extends Slot { 12 | 13 | protected Class clazz; 14 | 15 | public SlotAcceptAssignable(IInventory inventory, int index, int x, int y, Class c) { 16 | 17 | super(inventory, index, x, y); 18 | clazz = c; 19 | } 20 | 21 | @Override 22 | public boolean isItemValid(ItemStack stack) { 23 | 24 | return stack != null && clazz.isInstance(stack.getItem()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/tileentity/IEnergyInfo.java: -------------------------------------------------------------------------------- 1 | package cofh.api.tileentity; 2 | 3 | /** 4 | * Implement this interface on objects which can report information about their energy usage. 5 | * 6 | * This is used for reporting purposes - Energy transactions are handled via the RF API! 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface IEnergyInfo { 11 | 12 | /** 13 | * Returns energy usage/generation per tick (RF/t). 14 | */ 15 | int getInfoEnergyPerTick(); 16 | 17 | /** 18 | * Returns maximum energy usage/generation per tick (RF/t). 19 | */ 20 | int getInfoMaxEnergyPerTick(); 21 | 22 | /** 23 | * Returns energy stored (RF). 24 | */ 25 | int getInfoEnergyStored(); 26 | 27 | /** 28 | * Returns maximum energy stored (RF). 29 | */ 30 | int getInfoMaxEnergyStored(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotValidated.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import net.minecraft.inventory.Slot; 5 | import net.minecraft.item.ItemStack; 6 | 7 | /** 8 | * A slot where the input can be validated based on any arbitrary criteria by using a passthrough method to an {@link ISlotValidator}. 9 | * 10 | * @author King Lemming 11 | */ 12 | public class SlotValidated extends Slot { 13 | 14 | ISlotValidator validator; 15 | 16 | public SlotValidated(ISlotValidator validator, IInventory inventory, int index, int x, int y) { 17 | 18 | super(inventory, index, x, y); 19 | this.validator = validator; 20 | } 21 | 22 | @Override 23 | public boolean isItemValid(ItemStack stack) { 24 | 25 | return validator.isItemValid(stack); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/IEnergyHandler.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | /** 6 | * Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects. 7 | * 8 | * A reference implementation is provided {@link TileEnergyHandler}. 9 | * 10 | * Note that {@link IEnergyReceiver} and {@link IEnergyProvider} are extensions of this. 11 | * 12 | * @author King Lemming 13 | */ 14 | public interface IEnergyHandler extends IEnergyConnection { 15 | 16 | /** 17 | * Returns the amount of energy currently stored. 18 | */ 19 | int getEnergyStored(EnumFacing from); 20 | 21 | /** 22 | * Returns the maximum amount of energy that can be stored. 23 | */ 24 | int getMaxEnergyStored(EnumFacing from); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/block/IBlockConfigGui.java: -------------------------------------------------------------------------------- 1 | package cofh.api.block; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.util.EnumFacing; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.IBlockAccess; 7 | 8 | /** 9 | * Implement this interface on blocks which have a GUI that needs a tool (e.g., Multimeter) to open. 10 | */ 11 | public interface IBlockConfigGui { 12 | 13 | /** 14 | * This function will open a GUI if the player has permission. 15 | * 16 | * @param world Reference to the world. 17 | * @param pos Coordinates of the block. 18 | * @param side The side of the block. 19 | * @param player Player doing the configuring. 20 | * @return True if the GUI was opened. 21 | */ 22 | boolean openConfigGui(IBlockAccess world, BlockPos pos, EnumFacing side, EntityPlayer player); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/listbox/ListBoxElementText.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element.listbox; 2 | 3 | import cofh.lib.gui.element.ElementListBox; 4 | import net.minecraft.client.Minecraft; 5 | 6 | public class ListBoxElementText implements IListBoxElement { 7 | 8 | private final String _text; 9 | 10 | public ListBoxElementText(String text) { 11 | 12 | _text = text; 13 | } 14 | 15 | @Override 16 | public Object getValue() { 17 | 18 | return _text; 19 | } 20 | 21 | @Override 22 | public int getHeight() { 23 | 24 | return 10; 25 | } 26 | 27 | @Override 28 | public int getWidth() { 29 | 30 | return Minecraft.getMinecraft().fontRendererObj.getStringWidth(_text); 31 | } 32 | 33 | @Override 34 | public void draw(ElementListBox listBox, int x, int y, int backColor, int textColor) { 35 | 36 | listBox.getFontRenderer().drawStringWithShadow(_text, x, y, textColor); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/numbers/SkellamRandomProvider.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.numbers; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | import net.minecraft.world.World; 5 | 6 | import java.util.Random; 7 | 8 | import static cofh.lib.util.numbers.UniformRandomProvider.getRandomDouble; 9 | import static cofh.lib.util.numbers.UniformRandomProvider.getRandomLong; 10 | 11 | public class SkellamRandomProvider extends ConstantProvider { 12 | 13 | public SkellamRandomProvider(Number value) { 14 | 15 | super(value); 16 | } 17 | 18 | public long longValue(World world, Random rand, BlockPos pos) { 19 | 20 | long val = min.longValue(); 21 | return getRandomLong(val, rand) - getRandomLong(val, rand); 22 | } 23 | 24 | public double doubleValue(World world, Random rand, BlockPos pos) { 25 | 26 | double val = min.doubleValue(); 27 | return getRandomDouble(val, rand) - getRandomDouble(val, rand); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/WorldGenMulti.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import cofh.lib.util.WeightedRandomWorldGenerator; 4 | import net.minecraft.util.WeightedRandom; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import net.minecraft.world.gen.feature.WorldGenerator; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Random; 12 | 13 | public class WorldGenMulti extends WorldGenerator { 14 | 15 | private final List generators; 16 | 17 | public WorldGenMulti(ArrayList values) { 18 | 19 | generators = values; 20 | } 21 | 22 | @Override 23 | public boolean generate(World world, Random random, BlockPos pos) { 24 | 25 | WeightedRandomWorldGenerator gen = WeightedRandom.getRandomItem(random, generators); 26 | return gen.generator.generate(world, random, pos); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/tileentity/ITileInfo.java: -------------------------------------------------------------------------------- 1 | package cofh.api.tileentity; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.util.EnumFacing; 5 | import net.minecraft.util.text.ITextComponent; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Implement this interface on Tile Entities which can provide information about themselves. 11 | * 12 | * @author King Lemming 13 | */ 14 | public interface ITileInfo { 15 | 16 | /** 17 | * This function appends information to a list provided to it. 18 | * 19 | * @param info The list that the information should be appended to. 20 | * @param side The side of the block that is being queried. 21 | * @param player Player doing the querying - this can be NULL. 22 | * @param debug If true, the block should return "debug" information. 23 | */ 24 | void getTileInfo(List info, EnumFacing side, EntityPlayer player, boolean debug); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotCraftingLocked.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.inventory.InventoryCrafting; 6 | import net.minecraft.inventory.SlotCrafting; 7 | import net.minecraft.item.ItemStack; 8 | 9 | /** 10 | * Crafting result slot where the result cannot be removed. 11 | * 12 | * @author King Lemming 13 | */ 14 | public class SlotCraftingLocked extends SlotCrafting { 15 | 16 | public SlotCraftingLocked(EntityPlayer player, InventoryCrafting craftMatrix, IInventory inventory, int index, int x, int y) { 17 | 18 | super(player, craftMatrix, inventory, index, x, y); 19 | } 20 | 21 | @Override 22 | public boolean isItemValid(ItemStack stack) { 23 | 24 | return false; 25 | } 26 | 27 | @Override 28 | public boolean canTakeStack(EntityPlayer player) { 29 | 30 | return false; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/TabTracker.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui; 2 | 3 | import cofh.lib.gui.element.TabBase; 4 | 5 | /** 6 | * Keeps track of which tabs should be open by default when a player opens a GUI. 7 | * 8 | * @author King Lemming 9 | */ 10 | public class TabTracker { 11 | 12 | private static Class openedLeftTab; 13 | private static Class openedRightTab; 14 | 15 | private TabTracker() { 16 | 17 | } 18 | 19 | public static Class getOpenedLeftTab() { 20 | 21 | return openedLeftTab; 22 | } 23 | 24 | public static Class getOpenedRightTab() { 25 | 26 | return openedRightTab; 27 | } 28 | 29 | public static void setOpenedLeftTab(Class tabClass) { 30 | 31 | openedLeftTab = tabClass; 32 | } 33 | 34 | public static void setOpenedRightTab(Class tabClass) { 35 | 36 | openedRightTab = tabClass; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementSimpleBox.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | 5 | public class ElementSimpleBox extends ElementBase { 6 | 7 | protected int color; 8 | 9 | public ElementSimpleBox(GuiBase gui, int posX, int posY, Number color) { 10 | 11 | this(gui, posX, posY, 16, 16, color); 12 | } 13 | 14 | public ElementSimpleBox(GuiBase gui, int posX, int posY, int width, int height, Number color) { 15 | 16 | super(gui, posX, posY, width, height); 17 | setColor(color); 18 | } 19 | 20 | public ElementSimpleBox setColor(Number color) { 21 | 22 | this.color = color.intValue(); 23 | return this; 24 | } 25 | 26 | @Override 27 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 28 | 29 | drawModalRect(posX, posY, posX + sizeX, posY + sizeY, color); 30 | } 31 | 32 | @Override 33 | public void drawForeground(int mouseX, int mouseY) { 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementSimple.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.util.helpers.RenderHelper; 5 | 6 | /** 7 | * Basic element which can render an arbitrary texture. 8 | * 9 | * @author King Lemming 10 | */ 11 | public class ElementSimple extends ElementBase { 12 | 13 | protected int texU = 0; 14 | protected int texV = 0; 15 | 16 | public ElementSimple(GuiBase gui, int posX, int posY) { 17 | 18 | super(gui, posX, posY); 19 | } 20 | 21 | public ElementSimple setTextureOffsets(int u, int v) { 22 | 23 | texU = u; 24 | texV = v; 25 | return this; 26 | } 27 | 28 | @Override 29 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 30 | 31 | RenderHelper.bindTexture(texture); 32 | drawTexturedModalRect(posX, posY, texU, texV, sizeX, sizeY); 33 | } 34 | 35 | @Override 36 | public void drawForeground(int mouseX, int mouseY) { 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | The intention of the CoFH Common Library is to establish a framework for modders 2 | to use to avoid "reinventing the wheel," as it were. This library contains a lot 3 | of basic functionality that quite a few mods end up adding at some point during 4 | their development. 5 | 6 | Ideally, using this library will allow for more rapid mod development as a lot 7 | of the "boring" yet essential code is provided here. Additionally, it has the 8 | potential to greatly reduce permgen space, and who can argue with that? 9 | 10 | Obviously, we have to maintain this library and keep it compatible with the 11 | changes and updates introduced by Minecraft and Forge, but we'll try and only 12 | add new things if at all possible. 13 | 14 | If you feel that there is anything obvious or very basic that we have missed, 15 | feel free to suggest it to the team. 16 | 17 | We look forward to seeing what the community does with this. 18 | 19 | -Team CoFH 20 | 21 | Oh, and don't be a jerk. -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/IEnergyReceiver.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | /** 6 | * Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects. 7 | * 8 | * A reference implementation is provided {@link TileEnergyHandler}. 9 | * 10 | * @author King Lemming 11 | */ 12 | public interface IEnergyReceiver extends IEnergyHandler { 13 | 14 | /** 15 | * Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver. 16 | * 17 | * @param from Orientation the energy is received from. 18 | * @param maxReceive Maximum amount of energy to receive. 19 | * @param simulate If TRUE, the charge will only be simulated. 20 | * @return Amount of energy that was (or would have been, if simulated) received. 21 | */ 22 | int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/IEnergyProvider.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | /** 6 | * Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects. 7 | * 8 | * A reference implementation is provided {@link TileEnergyHandler}. 9 | * 10 | * @author King Lemming 11 | */ 12 | public interface IEnergyProvider extends IEnergyHandler { 13 | 14 | /** 15 | * Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider. 16 | * 17 | * @param from Orientation the energy is extracted from. 18 | * @param maxExtract Maximum amount of energy to extract. 19 | * @param simulate If TRUE, the extraction will only be simulated. 20 | * @return Amount of energy that was (or would have been, if simulated) extracted. 21 | */ 22 | int extractEnergy(EnumFacing from, int maxExtract, boolean simulate); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementFluid.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.util.helpers.FluidHelper; 5 | import net.minecraftforge.fluids.Fluid; 6 | import net.minecraftforge.fluids.FluidStack; 7 | 8 | public class ElementFluid extends ElementBase { 9 | 10 | public FluidStack fluid; 11 | 12 | public ElementFluid(GuiBase gui, int posX, int posY) { 13 | 14 | super(gui, posX, posY); 15 | } 16 | 17 | public ElementFluid setFluid(FluidStack stack) { 18 | 19 | this.fluid = stack; 20 | return this; 21 | } 22 | 23 | public ElementFluid setFluid(Fluid fluid) { 24 | 25 | this.fluid = new FluidStack(fluid, FluidHelper.BUCKET_VOLUME); 26 | return this; 27 | } 28 | 29 | @Override 30 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 31 | 32 | gui.drawFluid(posX, posY, fluid, sizeX, sizeY); 33 | } 34 | 35 | @Override 36 | public void drawForeground(int mouseX, int mouseY) { 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/InventoryManagerSided.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import net.minecraft.inventory.ISidedInventory; 4 | import net.minecraft.item.ItemStack; 5 | import net.minecraft.util.EnumFacing; 6 | 7 | public class InventoryManagerSided extends InventoryManagerStandard { 8 | 9 | private final ISidedInventory _sidedInv; 10 | 11 | public InventoryManagerSided(ISidedInventory inventory, EnumFacing targetSide) { 12 | 13 | super(inventory, targetSide); 14 | _sidedInv = inventory; 15 | } 16 | 17 | @Override 18 | public boolean canAddItem(ItemStack stack, int slot) { 19 | 20 | return super.canAddItem(stack, slot) && _sidedInv.canInsertItem(slot, stack, _targetSide); 21 | } 22 | 23 | @Override 24 | public boolean canRemoveItem(ItemStack stack, int slot) { 25 | 26 | return _sidedInv.canExtractItem(slot, stack, _targetSide); 27 | } 28 | 29 | @Override 30 | public int[] getSlots() { 31 | 32 | return _sidedInv.getSlotsForFace(_targetSide); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/block/IDismantleable.java: -------------------------------------------------------------------------------- 1 | package cofh.api.block; 2 | 3 | import net.minecraft.block.state.IBlockState; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.util.math.BlockPos; 7 | import net.minecraft.world.World; 8 | 9 | import java.util.ArrayList; 10 | 11 | /** 12 | * Implemented on Blocks which have some method of being instantly dismantled. 13 | * 14 | * @author King Lemming 15 | */ 16 | public interface IDismantleable { 17 | 18 | /** 19 | * Dismantles the block. If returnDrops is true, the drop(s) should be placed into the player's inventory. 20 | */ 21 | ArrayList dismantleBlock(World world, BlockPos pos, IBlockState state, EntityPlayer player, boolean returnDrops); 22 | 23 | /** 24 | * Return true if the block can be dismantled. The criteria for this is entirely up to the block. 25 | */ 26 | boolean canDismantle(World world, BlockPos pos, IBlockState state, EntityPlayer player); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/tileentity/IReconfigurableFacing.java: -------------------------------------------------------------------------------- 1 | package cofh.api.tileentity; 2 | 3 | /** 4 | * Implement this interface on Tile Entities which allow for reconfiguration of their facing. 5 | * 6 | * Coordination with the containing block is required. 7 | * 8 | * @author King Lemming 9 | */ 10 | public interface IReconfigurableFacing { 11 | 12 | /** 13 | * Returns the current facing of the block. 14 | */ 15 | int getFacing(); 16 | 17 | /** 18 | * Returns whether or not the block's face can be aligned with the Y Axis. 19 | */ 20 | boolean allowYAxisFacing(); 21 | 22 | /** 23 | * Attempt to rotate the block. Arbitrary based on implementation. 24 | * 25 | * @return True if rotation was successful, false otherwise. 26 | */ 27 | boolean rotateBlock(); 28 | 29 | /** 30 | * Set the facing of the block. 31 | * 32 | * @param side The side to set the facing to. 33 | * @return True if the facing was set, false otherwise. 34 | */ 35 | boolean setFacing(int side); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/IGeneratorParser.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import com.typesafe.config.Config; 5 | import net.minecraft.world.gen.feature.WorldGenerator; 6 | import org.apache.logging.log4j.Logger; 7 | 8 | import java.util.List; 9 | 10 | public interface IGeneratorParser { 11 | 12 | /** 13 | * Parse a {@link Config} for usage with an {@link IFeatureGenerator}. 14 | * 15 | * @param name The name of the generator entry. 16 | * @param genObject The JsonObject to parse. 17 | * @param log The {@link Logger} to log debug/error/etc. messages to. 18 | * @param resList The processed list of resources to generate 19 | * @param matList The processed list of materials to generate in 20 | * @return The {@link WorldGenerator} to be registered with an IFeatureGenerator 21 | */ 22 | WorldGenerator parseGenerator(String name, Config genObject, Logger log, List resList, List matList); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/numbers/ConstantProvider.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.numbers; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | import net.minecraft.world.World; 5 | 6 | import java.util.Random; 7 | 8 | public class ConstantProvider implements INumberProvider { 9 | 10 | protected Number min; 11 | 12 | public ConstantProvider(Number value) { 13 | 14 | if (value == null) { 15 | throw new IllegalArgumentException("Null value not allowed"); 16 | } 17 | this.min = value; 18 | } 19 | 20 | public int intValue(World world, Random rand, BlockPos pos) { 21 | 22 | return (int) longValue(world, rand, pos); 23 | } 24 | 25 | public long longValue(World world, Random rand, BlockPos pos) { 26 | 27 | return min.longValue(); 28 | } 29 | 30 | public float floatValue(World world, Random rand, BlockPos pos) { 31 | 32 | return (float) doubleValue(world, rand, pos); 33 | } 34 | 35 | public double doubleValue(World world, Random rand, BlockPos pos) { 36 | 37 | return min.doubleValue(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/InventoryCraftingFalse.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.Container; 5 | import net.minecraft.inventory.IInventory; 6 | import net.minecraft.inventory.InventoryCrafting; 7 | 8 | /** 9 | * This class is used to get recipes (IRecipe requires it...) with a Container. 10 | * 11 | * @author King Lemming 12 | */ 13 | public final class InventoryCraftingFalse extends InventoryCrafting { 14 | 15 | private static final NullContainer nullContainer = new NullContainer(); 16 | 17 | /* NULL INNER CLASS */ 18 | public static class NullContainer extends Container { 19 | 20 | @Override 21 | public void onCraftMatrixChanged(IInventory inventory) { 22 | 23 | } 24 | 25 | @Override 26 | public boolean canInteractWith(EntityPlayer player) { 27 | 28 | return false; 29 | } 30 | 31 | } 32 | 33 | public InventoryCraftingFalse(int width, int height) { 34 | 35 | super(nullContainer, width, height); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/IdentityLinkedHashList.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import java.util.Collection; 4 | 5 | @SuppressWarnings ("unchecked") 6 | public class IdentityLinkedHashList extends LinkedHashList { 7 | 8 | private static final long serialVersionUID = 4893829808146776641L; 9 | 10 | public IdentityLinkedHashList() { 11 | 12 | super(); 13 | } 14 | 15 | public IdentityLinkedHashList(int size) { 16 | 17 | super(size); 18 | } 19 | 20 | public IdentityLinkedHashList(Collection col) { 21 | 22 | super(col); 23 | } 24 | 25 | @Override 26 | protected int hash(Object o) { 27 | 28 | return System.identityHashCode(o); 29 | } 30 | 31 | @Override 32 | protected Entry seek(Object obj, int hash) { 33 | 34 | for (Entry entry = hashTable[hash & mask]; entry != null; entry = entry.nextInBucket) { 35 | if (obj == entry.key) { 36 | return entry; 37 | } 38 | } 39 | 40 | return null; 41 | } 42 | 43 | @Override 44 | public IdentityLinkedHashList clone() { 45 | 46 | return new IdentityLinkedHashList<>(this); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/ItemWrapper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.item.Item; 4 | import net.minecraft.item.ItemStack; 5 | 6 | /** 7 | * Wrapper for an Item/Metadata combination post 1.7. Quick and dirty, allows for Integer-based Hashes without collisions. 8 | * 9 | * @author King Lemming 10 | */ 11 | public final class ItemWrapper extends ComparableItem { 12 | 13 | public static ItemWrapper fromItemStack(ItemStack stack) { 14 | 15 | return new ItemWrapper(stack); 16 | } 17 | 18 | public ItemWrapper(Item item, int metadata) { 19 | 20 | super(item, metadata); 21 | } 22 | 23 | public ItemWrapper(ItemStack stack) { 24 | 25 | super(stack); 26 | } 27 | 28 | public ItemWrapper(ItemWrapper stack) { 29 | 30 | super(stack); 31 | } 32 | 33 | @Override 34 | public ItemWrapper clone() { 35 | 36 | return new ItemWrapper(this); 37 | } 38 | 39 | @Override 40 | public boolean equals(Object o) { 41 | 42 | if (!(o instanceof ItemWrapper)) { 43 | return false; 44 | } 45 | return isEqual((ItemWrapper) o); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotAcceptInsertable.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.inventory.IInventory; 4 | import net.minecraft.inventory.ISidedInventory; 5 | import net.minecraft.item.ItemStack; 6 | 7 | /** 8 | * Slot that will only accept ItemStacks when the IInventory returns true from isItemValidForSlot. 9 | * 10 | * If an ISidedInventory, canInsertItem (from side 6 (UNKNOWN)) must also return true. 11 | */ 12 | public class SlotAcceptInsertable extends SlotAcceptValid { 13 | 14 | protected ISidedInventory sidedInv; 15 | 16 | public SlotAcceptInsertable(IInventory inventory, int index, int x, int y) { 17 | 18 | super(inventory, index, x, y); 19 | 20 | if (inventory instanceof ISidedInventory) { 21 | sidedInv = (ISidedInventory) inventory; 22 | } else { 23 | sidedInv = null; 24 | } 25 | } 26 | 27 | @Override 28 | public boolean isItemValid(ItemStack stack) { 29 | 30 | boolean valid = super.isItemValid(stack); 31 | 32 | return valid && sidedInv != null ? sidedInv.canInsertItem(slotNumber, stack, null) : valid; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotFalseCopy.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.inventory.Slot; 6 | import net.minecraft.item.ItemStack; 7 | 8 | /** 9 | * Slot which copies an ItemStack when clicked on, does not decrement the ItemStack on the cursor. 10 | * 11 | * @author King Lemming 12 | */ 13 | public class SlotFalseCopy extends Slot { 14 | 15 | public int slotIndex = 0; 16 | 17 | public SlotFalseCopy(IInventory inventory, int index, int x, int y) { 18 | 19 | super(inventory, index, x, y); 20 | slotIndex = index; 21 | } 22 | 23 | @Override 24 | public boolean canTakeStack(EntityPlayer player) { 25 | 26 | return false; 27 | } 28 | 29 | @Override 30 | public boolean isItemValid(ItemStack stack) { 31 | 32 | return true; 33 | } 34 | 35 | @Override 36 | public void putStack(ItemStack stack) { 37 | 38 | if (stack != null) { 39 | stack.stackSize = 1; 40 | } 41 | this.inventory.setInventorySlotContents(this.slotIndex, stack); 42 | this.onSlotChanged(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/core/IPortableData.java: -------------------------------------------------------------------------------- 1 | package cofh.api.core; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | 6 | /** 7 | * Implement this interface on Objects which can write a limited amount of data about themselves. 8 | * 9 | * This is typically for the purposes of being transferred to a similar object (Tile Entity/Entity). 10 | * 11 | * @author King Lemming 12 | */ 13 | public interface IPortableData { 14 | 15 | /** 16 | * Data identifier of the Object. Used for display as well as verification purposes. Objects with completely interchangeable data should return the 17 | * same type. 18 | */ 19 | String getDataType(); 20 | 21 | /** 22 | * Read the data from a tag. The player object exists because this should always be called via player interaction! 23 | */ 24 | void readPortableData(EntityPlayer player, NBTTagCompound tag); 25 | 26 | /** 27 | * Write the data to a tag. The player object exists because this should always be called via player interaction! 28 | */ 29 | void writePortableData(EntityPlayer player, NBTTagCompound tag); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/item/IAugmentItem.java: -------------------------------------------------------------------------------- 1 | package cofh.api.item; 2 | 3 | import net.minecraft.item.ItemStack; 4 | 5 | public interface IAugmentItem { 6 | 7 | /** 8 | * Enum for Augment Types. 9 | * 10 | * BASIC - Standard augment, can have multiple. 11 | * ADVANCED - Rare augment, multiples may or may not be allowed. 12 | * MODE - Changes functionality greatly. Only allow one. 13 | * ENDER - Integration with Ender Frequencies. 14 | * CREATIVE - Super-powerful augments which cannot normally be obtained. 15 | */ 16 | enum AugmentType { 17 | BASIC, ADVANCED, MODE, ENDER, CREATIVE 18 | } 19 | 20 | /** 21 | * Get the Augment Type for a given Augment. 22 | * 23 | * @param stack ItemStack representing the Augment. 24 | * @return Augment Type of the stack. 25 | */ 26 | AugmentType getAugmentType(ItemStack stack); 27 | 28 | /** 29 | * Get the Augment Identifier for a given Augment. This is simply a string with some description of what the Augment does. Individual 30 | * 31 | * @param stack ItemStack representing the Augment. 32 | * @return Augment Type of the stack. 33 | */ 34 | String getAugmentIdentifier(ItemStack stack); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/core/IAugmentable.java: -------------------------------------------------------------------------------- 1 | package cofh.api.core; 2 | 3 | import cofh.api.item.IAugmentItem; 4 | import net.minecraft.item.ItemStack; 5 | 6 | /** 7 | * Implemented on objects which support Augments - these are modular and removable items which provide boosts or alterations to functionality. 8 | * 9 | * Effects of this are determined by the object itself and should be checked vs the Augment Type denoted in {@link IAugmentItem}. 10 | * 11 | * @author King Lemming 12 | */ 13 | public interface IAugmentable { 14 | 15 | /** 16 | * Attempt to install a specific augment in the (Tile) Entity. 17 | * 18 | * Returns TRUE if augment was installed properly. 19 | */ 20 | boolean installAugment(ItemStack augment); 21 | 22 | /** 23 | * Returns TRUE if a given augment is valid for the (Tile) Entity. 24 | */ 25 | boolean isValidAugment(ItemStack augment); 26 | 27 | /** 28 | * Returns an array of the Augment slots for this (Tile) Entity. 29 | */ 30 | ItemStack[] getAugmentSlots(); 31 | 32 | /** 33 | * Updates the status of Augments in the (Tile) Entity. Should be called to reset and re-baseline. 34 | */ 35 | void updateAugmentStatus(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementTextFieldLimited.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | 5 | public class ElementTextFieldLimited extends ElementTextField { 6 | 7 | protected boolean includeVanilla = true; 8 | protected String filter; 9 | 10 | public ElementTextFieldLimited(GuiBase gui, int posX, int posY, int width, int height) { 11 | 12 | super(gui, posX, posY, width, height); 13 | } 14 | 15 | public ElementTextFieldLimited(GuiBase gui, int posX, int posY, int width, int height, short limit) { 16 | 17 | super(gui, posX, posY, width, height, limit); 18 | } 19 | 20 | /** 21 | * @param pattern String containing all characters permitted 22 | * @param includeVanilla Include vanilla disallowed characters 23 | * @return this 24 | */ 25 | public ElementTextFieldLimited setFilter(String pattern, boolean includeVanilla) { 26 | 27 | filter = pattern; 28 | this.includeVanilla = includeVanilla; 29 | return this; 30 | } 31 | 32 | @Override 33 | public boolean isAllowedCharacter(char charTyped) { 34 | 35 | return (!includeVanilla || super.isAllowedCharacter(charTyped)) && (filter == null || filter.indexOf(charTyped) >= 0); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotLocked.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.inventory.Slot; 6 | import net.minecraft.item.ItemStack; 7 | import net.minecraftforge.fml.relauncher.Side; 8 | import net.minecraftforge.fml.relauncher.SideOnly; 9 | 10 | /** 11 | * A slot that can only be used to display an item, not edited. Can optionally not highlight when moused over. 12 | */ 13 | public class SlotLocked extends Slot { 14 | 15 | protected boolean showHighlight; 16 | 17 | public SlotLocked(IInventory inventory, int index, int x, int y) { 18 | 19 | this(inventory, index, x, y, false); 20 | } 21 | 22 | public SlotLocked(IInventory inventory, int index, int x, int y, boolean highlight) { 23 | 24 | super(inventory, index, x, y); 25 | showHighlight = highlight; 26 | } 27 | 28 | @Override 29 | public boolean canTakeStack(EntityPlayer player) { 30 | 31 | return false; 32 | } 33 | 34 | @Override 35 | public boolean isItemValid(ItemStack stack) { 36 | 37 | return false; 38 | } 39 | 40 | @Override 41 | @SideOnly (Side.CLIENT) 42 | public boolean canBeHovered() { 43 | 44 | return showHighlight; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/block/IBlockInfo.java: -------------------------------------------------------------------------------- 1 | package cofh.api.block; 2 | 3 | import cofh.api.tileentity.ITileInfo; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.util.EnumFacing; 6 | import net.minecraft.util.math.BlockPos; 7 | import net.minecraft.util.text.ITextComponent; 8 | import net.minecraft.world.IBlockAccess; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * Implement this interface on blocks which can provide information about themselves. If the block contains a Tile Entity, then it is recommended that this 14 | * function serve as a passthrough for {@link ITileInfo}. 15 | * 16 | * @author King Lemming 17 | */ 18 | public interface IBlockInfo { 19 | 20 | /** 21 | * This function appends information to a list provided to it. 22 | * 23 | * @param info The list that the information should be appended to. 24 | * @param world Reference to the world. 25 | * @param pos Coordinates of the block. 26 | * @param side The side of the block that is being queried. 27 | * @param player Player doing the querying - this can be NULL. 28 | * @param debug If true, the block should return "debug" information. 29 | */ 30 | void getBlockInfo(List info, IBlockAccess world, BlockPos pos, EnumFacing side, EntityPlayer player, boolean debug); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/ComparableItemStackNBT.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import net.minecraft.item.ItemStack; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | 6 | /** 7 | * Extension of {@link ComparableItemStack} except NBT sensitive. 8 | * 9 | * It is expected that this will have limited use, so this is a child class for overhead performance reasons. 10 | * 11 | * @author King Lemming 12 | */ 13 | public class ComparableItemStackNBT extends ComparableItemStack { 14 | 15 | public NBTTagCompound tag; 16 | 17 | public ComparableItemStackNBT(ItemStack stack) { 18 | 19 | super(stack); 20 | 21 | if (stack != null && stack.getTagCompound() != null) { 22 | tag = stack.getTagCompound().copy(); 23 | } 24 | } 25 | 26 | @Override 27 | public boolean isStackEqual(ComparableItemStack other) { 28 | 29 | return super.isStackEqual(other) && isStackTagEqual((ComparableItemStackNBT) other); 30 | } 31 | 32 | private boolean isStackTagEqual(ComparableItemStackNBT other) { 33 | 34 | return tag == null ? other.tag == null : other.tag != null && tag.equals(other.tag); 35 | } 36 | 37 | @Override 38 | public ItemStack toItemStack() { 39 | 40 | ItemStack ret = super.toItemStack(); 41 | if (ret != null) { 42 | ret.setTagCompound(tag.copy()); 43 | } 44 | return ret; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotSpecificItem.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import cofh.lib.inventory.ComparableItemStack; 4 | import net.minecraft.init.Blocks; 5 | import net.minecraft.inventory.IInventory; 6 | import net.minecraft.inventory.Slot; 7 | import net.minecraft.item.ItemStack; 8 | 9 | /** 10 | * Slot which is restricted to a specific item and maximum amount. 11 | * 12 | * @author King Lemming 13 | */ 14 | public class SlotSpecificItem extends Slot { 15 | 16 | protected final ComparableItemStack stack; 17 | protected ComparableItemStack query = new ComparableItemStack(new ItemStack(Blocks.STONE)); 18 | protected int slotStackLimit = -1; 19 | 20 | public SlotSpecificItem(IInventory inventory, int index, int x, int y, ItemStack stack) { 21 | 22 | super(inventory, index, x, y); 23 | 24 | this.stack = new ComparableItemStack(stack); 25 | } 26 | 27 | @Override 28 | public boolean isItemValid(ItemStack stack) { 29 | 30 | return this.stack.isItemEqual(query.set(stack)); 31 | } 32 | 33 | public SlotSpecificItem setSlotStackLimit(int slotStackLimit) { 34 | 35 | this.slotStackLimit = slotStackLimit; 36 | return this; 37 | } 38 | 39 | @Override 40 | public int getSlotStackLimit() { 41 | 42 | return slotStackLimit <= 0 ? inventory.getInventoryStackLimit() : slotStackLimit; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/IFeatureGenerator.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import net.minecraft.world.World; 4 | import net.minecraft.world.gen.feature.WorldGenerator; 5 | 6 | import java.util.Random; 7 | 8 | /** 9 | * This interface should be implemented on classes which define a world feature to be generated in a {@link IFeatureHandler}. It is essentially a more robust 10 | * version of {@link WorldGenerator}, and may include one or more WorldGenerators should you wish. 11 | * 12 | * @author King Lemming 13 | */ 14 | public interface IFeatureGenerator { 15 | 16 | /** 17 | * Returns the name of the feature, used for unique identification in configs and retrogen. 18 | */ 19 | String getFeatureName(); 20 | 21 | /** 22 | * Generates the world feature. 23 | * 24 | * @param random Random derived from the world seed. 25 | * @param chunkX Minimum X chunk-coordinate of the chunk. (x16 for block coordinate) 26 | * @param chunkZ Minimum Z chunk-coordinate of the chunk. (x16 for block coordinate) 27 | * @param world The world to generate in. 28 | * @param hasVillage True if this chunk contains a village 29 | * @param newGen True on initial generation, false on retrogen. 30 | * @return True if generation happened, false otherwise. 31 | */ 32 | boolean generateFeature(Random random, int chunkX, int chunkZ, World world, boolean hasVillage, boolean newGen); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotViewOnly.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.inventory.Slot; 6 | import net.minecraft.item.ItemStack; 7 | import net.minecraftforge.fml.relauncher.Side; 8 | import net.minecraftforge.fml.relauncher.SideOnly; 9 | 10 | /** 11 | * A slot that can only be used to display an item, not edited. Can optionally not highlight when moused over. 12 | */ 13 | public class SlotViewOnly extends Slot { 14 | 15 | protected boolean showHighlight; 16 | 17 | public SlotViewOnly(IInventory inventory, int index, int x, int y) { 18 | 19 | this(inventory, index, x, y, false); 20 | } 21 | 22 | public SlotViewOnly(IInventory inventory, int index, int x, int y, boolean highlight) { 23 | 24 | super(inventory, index, x, y); 25 | showHighlight = highlight; 26 | } 27 | 28 | @Override 29 | public void putStack(ItemStack stack) { 30 | 31 | } 32 | 33 | @Override 34 | public ItemStack decrStackSize(int i) { 35 | 36 | return null; 37 | } 38 | 39 | @Override 40 | public boolean canTakeStack(EntityPlayer player) { 41 | 42 | return false; 43 | } 44 | 45 | @Override 46 | public boolean isItemValid(ItemStack stack) { 47 | 48 | return false; 49 | } 50 | 51 | @Override 52 | @SideOnly (Side.CLIENT) 53 | public boolean canBeHovered() { 54 | 55 | return showHighlight; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementTextFieldFiltered.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.util.CharacterSingleton; 5 | 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | public class ElementTextFieldFiltered extends ElementTextField { 10 | 11 | protected boolean includeVanilla = true; 12 | protected CharacterSingleton seq = new CharacterSingleton(); 13 | protected Matcher filter; 14 | 15 | public ElementTextFieldFiltered(GuiBase gui, int posX, int posY, int width, int height) { 16 | 17 | super(gui, posX, posY, width, height); 18 | } 19 | 20 | public ElementTextFieldFiltered(GuiBase gui, int posX, int posY, int width, int height, short limit) { 21 | 22 | super(gui, posX, posY, width, height, limit); 23 | } 24 | 25 | /** 26 | * @param pattern Regex limit what characters can be typed 27 | * @param includeVanilla Include vanilla disallowed characters 28 | * @return this 29 | */ 30 | public ElementTextFieldFiltered setFilter(Pattern pattern, boolean includeVanilla) { 31 | 32 | filter = pattern.matcher(seq); 33 | this.includeVanilla = includeVanilla; 34 | return this; 35 | } 36 | 37 | @Override 38 | public boolean isAllowedCharacter(char charTyped) { 39 | 40 | seq.character = charTyped; 41 | return (!includeVanilla || super.isAllowedCharacter(charTyped)) && (filter == null || filter.reset().matches()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementIcon.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.gui.GuiColor; 5 | import cofh.lib.util.helpers.RenderHelper; 6 | import net.minecraft.client.renderer.GlStateManager; 7 | import net.minecraft.client.renderer.texture.TextureAtlasSprite; 8 | 9 | public class ElementIcon extends ElementBase { 10 | 11 | protected TextureAtlasSprite icon; 12 | protected GuiColor color = new GuiColor(-1); 13 | 14 | public ElementIcon(GuiBase gui, int posX, int posY, TextureAtlasSprite icon) { 15 | 16 | super(gui, posX, posY); 17 | this.icon = icon; 18 | } 19 | 20 | public ElementIcon setColor(Number color) { 21 | 22 | this.color = new GuiColor(color.intValue()); 23 | return this; 24 | } 25 | 26 | public ElementIcon setIcon(TextureAtlasSprite icon) { 27 | 28 | this.icon = icon; 29 | return this; 30 | } 31 | 32 | public int getColor() { 33 | 34 | return color.getColor(); 35 | } 36 | 37 | @Override 38 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 39 | 40 | if (icon != null) { 41 | RenderHelper.setBlockTextureSheet(); 42 | GlStateManager.color(color.getFloatR(), color.getFloatG(), color.getFloatB(), color.getFloatA()); 43 | gui.drawColorIcon(icon, posX, posY); 44 | GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0F); 45 | } 46 | } 47 | 48 | @Override 49 | public void drawForeground(int mouseX, int mouseY) { 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/item/IMultiModeItem.java: -------------------------------------------------------------------------------- 1 | package cofh.api.item; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.item.ItemStack; 5 | 6 | /** 7 | * Implement this interface on Item classes which have multiple modes - what that means is completely up to you. This just provides a uniform way of dealing 8 | * with them. 9 | * 10 | * @author King Lemming 11 | */ 12 | public interface IMultiModeItem { 13 | 14 | /** 15 | * Get the current mode of an item. 16 | */ 17 | int getMode(ItemStack stack); 18 | 19 | /** 20 | * Attempt to set the empowered state of the item. 21 | * 22 | * @param stack ItemStack to set the mode on. 23 | * @param mode Desired mode. 24 | * @return TRUE if the operation was successful, FALSE if it was not. 25 | */ 26 | boolean setMode(ItemStack stack, int mode); 27 | 28 | /** 29 | * Increment the current mode of an item. 30 | */ 31 | boolean incrMode(ItemStack stack); 32 | 33 | /** 34 | * Decrement the current mode of an item. 35 | */ 36 | boolean decrMode(ItemStack stack); 37 | 38 | /** 39 | * Returns the number of possible modes. 40 | */ 41 | int getNumModes(ItemStack stack); 42 | 43 | /** 44 | * Callback method for reacting to a state change. Useful in KeyBinding handlers. 45 | * 46 | * @param player Player holding the item, if applicable. 47 | * @param stack The item being held. 48 | */ 49 | void onModeChange(EntityPlayer player, ItemStack stack); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/util/ThermalFoundationHelper.java: -------------------------------------------------------------------------------- 1 | package cofh.api.util; 2 | 3 | import net.minecraft.item.ItemStack; 4 | import net.minecraft.nbt.NBTTagCompound; 5 | import net.minecraftforge.fml.common.event.FMLInterModComms; 6 | 7 | /** 8 | * The purpose of this class is to show how to use and provide an interface for Thermal Foundation's IMC Lexicon Blacklist manipulation. 9 | * 10 | * This is really the only safe way to do this. Please do not attempt any direct Lexicon manipulation. 11 | * 12 | * @author King Lemming 13 | */ 14 | public class ThermalFoundationHelper { 15 | 16 | private ThermalFoundationHelper() { 17 | 18 | } 19 | 20 | /* Lexicon */ 21 | public static void addBlacklistEntry(ItemStack entry) { 22 | 23 | if (entry == null) { 24 | return; 25 | } 26 | NBTTagCompound toSend = new NBTTagCompound(); 27 | 28 | toSend.setTag("entry", new NBTTagCompound()); 29 | 30 | entry.writeToNBT(toSend.getCompoundTag("entry")); 31 | FMLInterModComms.sendMessage("thermalfoundation", "AddLexiconBlacklistEntry", toSend); 32 | } 33 | 34 | public static void removeBlacklistEntry(ItemStack entry) { 35 | 36 | if (entry == null) { 37 | return; 38 | } 39 | NBTTagCompound toSend = new NBTTagCompound(); 40 | 41 | toSend.setTag("entry", new NBTTagCompound()); 42 | 43 | entry.writeToNBT(toSend.getCompoundTag("entry")); 44 | FMLInterModComms.sendMessage("thermalfoundation", "RemoveLexiconBlacklistEntry", toSend); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/listbox/SliderVertical.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element.listbox; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.gui.element.ElementSlider; 5 | 6 | public class SliderVertical extends ElementSlider { 7 | 8 | public SliderVertical(GuiBase containerScreen, int x, int y, int width, int height, int maxValue) { 9 | 10 | this(containerScreen, x, y, width, height, maxValue, 0); 11 | } 12 | 13 | public SliderVertical(GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue) { 14 | 15 | super(containerScreen, x, y, width, height, maxValue, minValue); 16 | int dist = maxValue - minValue; 17 | setSliderSize(width, dist <= 0 ? height : Math.max(height / ++dist, 9)); 18 | } 19 | 20 | @Override 21 | public ElementSlider setLimits(int min, int max) { 22 | 23 | int dist = max - min; 24 | setSliderSize(getWidth(), dist <= 0 ? getHeight() : Math.max(getHeight() / ++dist, 9)); 25 | return super.setLimits(min, max); 26 | } 27 | 28 | @Override 29 | public int getSliderY() { 30 | 31 | int dist = _valueMax - _valueMin; 32 | int maxPos = sizeY - _sliderHeight; 33 | return Math.min(dist == 0 ? 0 : maxPos * (_value - _valueMin) / dist, maxPos); 34 | } 35 | 36 | @Override 37 | public void dragSlider(int x, int v) { 38 | 39 | v += Math.round(_sliderHeight * (v / (float) sizeY) + (_sliderHeight * 0.25f)); 40 | setValue(_valueMin + ((_valueMax - _valueMin) * v / sizeY)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotInvisible.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.inventory.Slot; 6 | import net.minecraft.item.ItemStack; 7 | import net.minecraftforge.fml.relauncher.Side; 8 | import net.minecraftforge.fml.relauncher.SideOnly; 9 | 10 | /** 11 | * Slot that will redirect inserts to another inventory slot (other than index), but not be visible. 12 | * 13 | * Used primarily for containers that have a larger internal inventory than external (e.g., DeepStorageUnit) 14 | */ 15 | public class SlotInvisible extends Slot { 16 | 17 | protected final int slotIndex; 18 | 19 | public SlotInvisible(IInventory inventory, int index, int x, int y, int slot) { 20 | 21 | super(inventory, index, x, y); 22 | slotIndex = slot; 23 | } 24 | 25 | @Override 26 | public void putStack(ItemStack stack) { 27 | 28 | this.inventory.setInventorySlotContents(slotIndex, stack); 29 | this.onSlotChanged(); 30 | } 31 | 32 | @Override 33 | public ItemStack getStack() { 34 | 35 | return null; 36 | } 37 | 38 | @Override 39 | public ItemStack decrStackSize(int par1) { 40 | 41 | return null; 42 | } 43 | 44 | @Override 45 | public boolean canTakeStack(EntityPlayer p) { 46 | 47 | return false; 48 | } 49 | 50 | @Override 51 | @SideOnly (Side.CLIENT) 52 | public boolean canBeHovered() { 53 | 54 | return false; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementButtonBase.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.gui.GuiProps; 5 | import net.minecraft.util.ResourceLocation; 6 | 7 | public abstract class ElementButtonBase extends ElementBase { 8 | 9 | public static final ResourceLocation HOVER = new ResourceLocation(GuiProps.PATH_ELEMENTS + "button_hover.png"); 10 | public static final ResourceLocation ENABLED = new ResourceLocation(GuiProps.PATH_ELEMENTS + "button_enabled.png"); 11 | public static final ResourceLocation DISABLED = new ResourceLocation(GuiProps.PATH_ELEMENTS + "button_disabled.png"); 12 | 13 | public ElementButtonBase(GuiBase containerScreen, int posX, int posY, int sizeX, int sizeY) { 14 | 15 | super(containerScreen, posX, posY, sizeX, sizeY); 16 | } 17 | 18 | @Override 19 | public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) { 20 | 21 | playSound(mouseButton); 22 | switch (mouseButton) { 23 | case 0: 24 | onClick(); 25 | break; 26 | case 1: 27 | onRightClick(); 28 | break; 29 | case 2: 30 | onMiddleClick(); 31 | break; 32 | } 33 | return true; 34 | } 35 | 36 | protected void playSound(int button) { 37 | 38 | if (button == 0) { 39 | GuiBase.playClickSound(1.0F, 1.0F); 40 | } 41 | } 42 | 43 | public void onClick() { 44 | 45 | } 46 | 47 | public void onRightClick() { 48 | 49 | } 50 | 51 | public void onMiddleClick() { 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/listbox/SliderHorizontal.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element.listbox; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.gui.element.ElementSlider; 5 | 6 | public class SliderHorizontal extends ElementSlider { 7 | 8 | public SliderHorizontal(GuiBase containerScreen, int x, int y, int width, int height, int maxValue) { 9 | 10 | this(containerScreen, x, y, width, height, maxValue, 0); 11 | } 12 | 13 | public SliderHorizontal(GuiBase containerScreen, int x, int y, int width, int height, int maxValue, int minValue) { 14 | 15 | super(containerScreen, x, y, width, height, maxValue, minValue); 16 | int dist = maxValue - minValue; 17 | setSliderSize(dist <= 0 ? width : Math.max(width / ++dist, 9), height); 18 | } 19 | 20 | @Override 21 | public ElementSlider setLimits(int min, int max) { 22 | 23 | int dist = max - min; 24 | setSliderSize(dist <= 0 ? getWidth() : Math.max(getWidth() / ++dist, 9), getHeight()); 25 | return super.setLimits(min, max); 26 | } 27 | 28 | @Override 29 | public int getSliderX() { 30 | 31 | int dist = _valueMax - _valueMin; 32 | int maxPos = sizeX - _sliderWidth; 33 | return Math.min(dist == 0 ? 0 : maxPos * (_value - _valueMin) / dist, maxPos); 34 | } 35 | 36 | @Override 37 | public void dragSlider(int v, int y) { 38 | 39 | v += Math.round(_sliderWidth * (v / (float) sizeX) + (_sliderWidth * 0.25f)); 40 | setValue(_valueMin + ((_valueMax - _valueMin) * v / sizeX)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/IEnergyStorage.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | /** 4 | * An energy storage is the unit of interaction with Energy inventories.
5 | * This is not to be implemented on TileEntities. This is for internal use only. 6 | * 7 | * A reference implementation can be found at {@link EnergyStorage}. 8 | * 9 | * @author King Lemming 10 | */ 11 | public interface IEnergyStorage { 12 | 13 | /** 14 | * Adds energy to the storage. Returns quantity of energy that was accepted. 15 | * 16 | * @param maxReceive Maximum amount of energy to be inserted. 17 | * @param simulate If TRUE, the insertion will only be simulated. 18 | * @return Amount of energy that was (or would have been, if simulated) accepted by the storage. 19 | */ 20 | int receiveEnergy(int maxReceive, boolean simulate); 21 | 22 | /** 23 | * Removes energy from the storage. Returns quantity of energy that was removed. 24 | * 25 | * @param maxExtract Maximum amount of energy to be extracted. 26 | * @param simulate If TRUE, the extraction will only be simulated. 27 | * @return Amount of energy that was (or would have been, if simulated) extracted from the storage. 28 | */ 29 | int extractEnergy(int maxExtract, boolean simulate); 30 | 31 | /** 32 | * Returns the amount of energy currently stored. 33 | */ 34 | int getEnergyStored(); 35 | 36 | /** 37 | * Returns the maximum amount of energy that can be stored. 38 | */ 39 | int getMaxEnergyStored(); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/helpers/SoundHelper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.helpers; 2 | 3 | import cofh.lib.audio.SoundBase; 4 | import net.minecraft.client.audio.ISound; 5 | import net.minecraft.client.audio.SoundHandler; 6 | import net.minecraft.util.SoundCategory; 7 | import net.minecraftforge.fml.client.FMLClientHandler; 8 | 9 | /** 10 | * Contains various helper functions to assist with Sound manipulation. 11 | * 12 | * @author King Lemming 13 | */ 14 | public class SoundHelper { 15 | 16 | public static final SoundHandler soundManager = FMLClientHandler.instance().getClient().getSoundHandler(); 17 | 18 | private SoundHelper() { 19 | 20 | } 21 | 22 | /** 23 | * This allows you to have some tricky functionality with Tile Entities. Just be sure you aren't dumb. 24 | */ 25 | public static void playSound(Object sound) { 26 | 27 | if (sound instanceof ISound) { 28 | soundManager.playSound((ISound) sound); 29 | } 30 | } 31 | 32 | public static void playSound(ISound sound) { 33 | 34 | soundManager.playSound(sound); 35 | } 36 | 37 | @Deprecated 38 | public static void playSound(String soundName, float x, float y, float z, float volume, float pitch) { 39 | 40 | playSound(soundName, SoundCategory.MASTER, x, y, z, volume, pitch); 41 | } 42 | 43 | public static void playSound(String soundName, SoundCategory category, float x, float y, float z, float volume, float pitch) { 44 | 45 | soundManager.playSound(new SoundBase(soundName, category, volume, pitch, x, y, z)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/biome/BiomeDictionaryArbiter.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.biome; 2 | 3 | import net.minecraft.world.biome.Biome; 4 | import net.minecraftforge.common.BiomeDictionary; 5 | import net.minecraftforge.common.BiomeDictionary.Type; 6 | import net.minecraftforge.fml.common.Loader; 7 | import net.minecraftforge.fml.common.LoaderState; 8 | 9 | import java.util.HashMap; 10 | 11 | public class BiomeDictionaryArbiter { 12 | 13 | private static HashMap types = new HashMap<>(); 14 | private static HashMap biomes = new HashMap<>(); 15 | private static boolean loaded = Loader.instance().isInState(LoaderState.AVAILABLE); 16 | 17 | public static Type[] getTypesForBiome(Biome biome) { 18 | 19 | if (loaded) { 20 | Type[] r = types.get(biome); 21 | if (r == null) { 22 | types.put(biome, r = BiomeDictionary.getTypesForBiome(biome)); 23 | } 24 | return r; 25 | } 26 | loaded = Loader.instance().isInState(LoaderState.AVAILABLE); 27 | return BiomeDictionary.getTypesForBiome(biome); 28 | } 29 | 30 | public static Biome[] getTypesForBiome(Type type) { 31 | 32 | if (loaded) { 33 | Biome[] r = biomes.get(type); 34 | if (r == null) { 35 | biomes.put(type, r = BiomeDictionary.getBiomesForType(type)); 36 | } 37 | return r; 38 | } 39 | loaded = Loader.instance().isInState(LoaderState.AVAILABLE); 40 | return BiomeDictionary.getBiomesForType(type); 41 | } 42 | 43 | private BiomeDictionaryArbiter() { 44 | 45 | throw new IllegalArgumentException(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/core/ISecurable.java: -------------------------------------------------------------------------------- 1 | package cofh.api.core; 2 | 3 | import com.mojang.authlib.GameProfile; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | 6 | /** 7 | * Implement this interface on Objects which can have access restrictions. 8 | * 9 | * @author King Lemming 10 | */ 11 | public interface ISecurable { 12 | 13 | /** 14 | * Enum for Access Modes - TeamOnly allows Team access, FriendsOnly is Friends Only, Private is Owner only. 15 | * 16 | * @author King Lemming 17 | */ 18 | enum AccessMode { 19 | PUBLIC, FRIENDS, TEAM, PRIVATE; 20 | 21 | public boolean isPublic() { 22 | 23 | return this == PUBLIC; 24 | } 25 | 26 | public boolean isPrivate() { 27 | 28 | return this == PRIVATE; 29 | } 30 | 31 | public boolean isTeamOnly() { 32 | 33 | return this == TEAM; 34 | } 35 | 36 | public boolean isFriendsOnly() { 37 | 38 | return this == FRIENDS; 39 | } 40 | 41 | public static AccessMode stepForward(AccessMode curAccess) { 42 | 43 | return curAccess == PUBLIC ? TEAM : curAccess == TEAM ? FRIENDS : curAccess == FRIENDS ? PRIVATE : PUBLIC; 44 | } 45 | 46 | public static AccessMode stepBackward(AccessMode curAccess) { 47 | 48 | return curAccess == PUBLIC ? PRIVATE : curAccess == PRIVATE ? FRIENDS : curAccess == FRIENDS ? TEAM : PUBLIC; 49 | } 50 | } 51 | 52 | boolean canPlayerAccess(EntityPlayer player); 53 | 54 | boolean setAccess(AccessMode access); 55 | 56 | boolean setOwnerName(String name); 57 | 58 | boolean setOwner(GameProfile name); 59 | 60 | AccessMode getAccess(); 61 | 62 | String getOwnerName(); 63 | 64 | GameProfile getOwner(); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementDualScaled.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.util.helpers.RenderHelper; 5 | 6 | public class ElementDualScaled extends ElementBase { 7 | 8 | public int quantity; 9 | public int mode; 10 | public boolean background = true; 11 | 12 | public ElementDualScaled(GuiBase gui, int posX, int posY) { 13 | 14 | super(gui, posX, posY); 15 | } 16 | 17 | public ElementDualScaled setBackground(boolean background) { 18 | 19 | this.background = background; 20 | return this; 21 | } 22 | 23 | public ElementDualScaled setMode(int mode) { 24 | 25 | this.mode = mode; 26 | return this; 27 | } 28 | 29 | public ElementDualScaled setQuantity(int quantity) { 30 | 31 | this.quantity = quantity; 32 | return this; 33 | } 34 | 35 | @Override 36 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 37 | 38 | RenderHelper.bindTexture(texture); 39 | 40 | if (background) { 41 | drawTexturedModalRect(posX, posY, 0, 0, sizeX, sizeY); 42 | } 43 | switch (mode) { 44 | case 0: 45 | // vertical bottom -> top 46 | drawTexturedModalRect(posX, posY + sizeY - quantity, sizeX, sizeY - quantity, sizeX, quantity); 47 | return; 48 | case 1: 49 | // horizontal left -> right 50 | drawTexturedModalRect(posX, posY, sizeX, 0, quantity, sizeY); 51 | return; 52 | case 2: 53 | // horizontal right -> left 54 | drawTexturedModalRect(posX + sizeX - quantity, posY, sizeX + sizeX - quantity, 0, quantity, sizeY); 55 | } 56 | } 57 | 58 | @Override 59 | public void drawForeground(int mouseX, int mouseY) { 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/OreDictionaryProxy.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import cofh.lib.util.helpers.ItemHelper; 4 | import com.google.common.base.Strings; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraftforge.oredict.OreDictionary; 7 | 8 | /** 9 | * Don't instantiate this or call these methods in any way. Use the methods in {@link ItemHelper}. 10 | * 11 | * @author King Lemming 12 | */ 13 | @SuppressWarnings ("deprecation") 14 | public class OreDictionaryProxy { 15 | 16 | public ItemStack getOre(String oreName) { 17 | 18 | if (!oreNameExists(oreName)) { 19 | return null; 20 | } 21 | return ItemHelper.cloneStack(OreDictionary.getOres(oreName, false).get(0), 1); 22 | } 23 | 24 | public int getOreID(ItemStack stack) { 25 | 26 | return getOreID(getOreName(stack)); 27 | } 28 | 29 | public int getOreID(String oreName) { 30 | 31 | if (Strings.isNullOrEmpty(oreName)) { 32 | return -1; 33 | } 34 | return OreDictionary.getOreID(oreName); 35 | } 36 | 37 | public String getOreName(ItemStack stack) { 38 | 39 | int[] ids = OreDictionary.getOreIDs(stack); 40 | if (ids != null && ids.length >= 1) { 41 | return OreDictionary.getOreName(ids[0]); 42 | } 43 | return ""; 44 | } 45 | 46 | public String getOreName(int oreID) { 47 | 48 | return OreDictionary.getOreName(oreID); 49 | } 50 | 51 | public boolean isOreIDEqual(ItemStack stack, int oreID) { 52 | 53 | return getOreID(stack) == oreID; 54 | } 55 | 56 | public boolean isOreNameEqual(ItemStack stack, String oreName) { 57 | 58 | return OreDictionary.getOreName(getOreID(stack)).equals(oreName); 59 | } 60 | 61 | public boolean oreNameExists(String oreName) { 62 | 63 | return OreDictionary.doesOreNameExist(oreName); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/helpers/ServerHelper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.helpers; 2 | 3 | import net.minecraft.client.network.NetHandlerPlayClient; 4 | import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock; 5 | import net.minecraft.util.EnumFacing; 6 | import net.minecraft.util.EnumHand; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.world.World; 9 | import net.minecraftforge.fml.client.FMLClientHandler; 10 | import net.minecraftforge.fml.common.FMLCommonHandler; 11 | 12 | /** 13 | * Contains various helper functions to assist with determining Server/Client status. 14 | * 15 | * @author King Lemming 16 | */ 17 | public final class ServerHelper { 18 | 19 | private ServerHelper() { 20 | 21 | } 22 | 23 | public static boolean isClientWorld(World world) { 24 | 25 | return world.isRemote; 26 | } 27 | 28 | public static boolean isServerWorld(World world) { 29 | 30 | return !world.isRemote; 31 | } 32 | 33 | public static boolean isSinglePlayerServer() { 34 | 35 | return FMLCommonHandler.instance().getMinecraftServerInstance() != null; 36 | } 37 | 38 | public static boolean isMultiPlayerServer() { 39 | 40 | return FMLCommonHandler.instance().getMinecraftServerInstance() == null; 41 | } 42 | 43 | /** 44 | * This function circumvents a miserable failing. 45 | */ 46 | public static void sendItemUsePacket(World world, BlockPos pos, EnumFacing hitSide, EnumHand hand, float hitX, float hitY, float hitZ) { 47 | 48 | if (isServerWorld(world)) { 49 | return; 50 | } 51 | NetHandlerPlayClient netClientHandler = (NetHandlerPlayClient) FMLClientHandler.instance().getClientPlayHandler(); 52 | netClientHandler.sendPacket(new CPacketPlayerTryUseItemOnBlock(pos, hitSide, hand, hitX, hitY, hitZ)); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementButtonOption.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | public abstract class ElementButtonOption extends ElementButtonManaged { 9 | 10 | private final Map _values = new HashMap<>(); 11 | private int _currentValue = 0; 12 | private int _maxValue; 13 | 14 | public ElementButtonOption(GuiBase containerScreen, int x, int y, int width, int height) { 15 | 16 | super(containerScreen, x, y, width, height, ""); 17 | } 18 | 19 | public void setValue(int value, String label) { 20 | 21 | _values.put(value, label); 22 | if (value > _maxValue) { 23 | _maxValue = value; 24 | } 25 | } 26 | 27 | @Override 28 | public void onClick() { 29 | 30 | int nextValue = _currentValue; 31 | do { 32 | nextValue++; 33 | if (nextValue > _maxValue) { 34 | nextValue = 0; 35 | } 36 | } while (_values.get(nextValue) == null); 37 | setSelectedIndex(nextValue); 38 | } 39 | 40 | @Override 41 | public void onRightClick() { 42 | 43 | int nextValue = _currentValue; 44 | 45 | do { 46 | nextValue--; 47 | if (nextValue < 0) { 48 | nextValue = _maxValue; 49 | } 50 | } while (_values.get(nextValue) == null); 51 | setSelectedIndex(nextValue); 52 | } 53 | 54 | public int getSelectedIndex() { 55 | 56 | return _currentValue; 57 | } 58 | 59 | public void setSelectedIndex(int index) { 60 | 61 | _currentValue = index; 62 | setText(_values.get(_currentValue)); 63 | onValueChanged(_currentValue, _values.get(_currentValue)); 64 | } 65 | 66 | public String getValue() { 67 | 68 | return _values.get(_currentValue); 69 | } 70 | 71 | public abstract void onValueChanged(int value, String label); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementSimpleTooltip.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.util.helpers.RenderHelper; 5 | import cofh.lib.util.helpers.StringHelper; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Basic element which can render an arbitrary texture and may have a tooltip. 11 | * 12 | * @author King Lemming 13 | */ 14 | public class ElementSimpleTooltip extends ElementBase { 15 | 16 | int texU = 0; 17 | int texV = 0; 18 | boolean tooltipLocalized = false; 19 | String tooltip; 20 | 21 | public ElementSimpleTooltip(GuiBase gui, int posX, int posY) { 22 | 23 | super(gui, posX, posY); 24 | } 25 | 26 | public ElementSimpleTooltip setTextureOffsets(int u, int v) { 27 | 28 | texU = u; 29 | texV = v; 30 | return this; 31 | } 32 | 33 | public ElementSimpleTooltip clearToolTip() { 34 | 35 | this.tooltip = null; 36 | return this; 37 | } 38 | 39 | public ElementSimpleTooltip settooltip(String tooltip) { 40 | 41 | this.tooltip = tooltip; 42 | return this; 43 | } 44 | 45 | public ElementSimpleTooltip settooltiplocalized(boolean localized) { 46 | 47 | this.tooltipLocalized = localized; 48 | return this; 49 | } 50 | 51 | @Override 52 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 53 | 54 | RenderHelper.bindTexture(texture); 55 | drawTexturedModalRect(posX, posY, texU, texV, sizeX, sizeY); 56 | } 57 | 58 | @Override 59 | public void drawForeground(int mouseX, int mouseY) { 60 | 61 | } 62 | 63 | @Override 64 | public void addTooltip(List list) { 65 | 66 | if (tooltip != null) { 67 | if (tooltipLocalized) { 68 | list.add(tooltip); 69 | } else { 70 | list.add(StringHelper.localize(tooltip)); 71 | } 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/WorldGenStalactite.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.World; 6 | 7 | import java.util.List; 8 | import java.util.Random; 9 | 10 | import static cofh.lib.world.WorldGenMinableCluster.canGenerateInBlock; 11 | import static cofh.lib.world.WorldGenMinableCluster.generateBlock; 12 | 13 | public class WorldGenStalactite extends WorldGenStalagmite { 14 | 15 | public WorldGenStalactite(List resource, List block, List gblock) { 16 | 17 | super(resource, block, gblock); 18 | } 19 | 20 | @Override 21 | public boolean generate(World world, Random rand, BlockPos pos) { 22 | 23 | int xStart = pos.getX(); 24 | int yStart = pos.getY(); 25 | int zStart = pos.getZ(); 26 | 27 | int end = world.getActualHeight(); 28 | while (world.isAirBlock(new BlockPos(xStart, yStart, zStart)) && yStart < end) { 29 | ++yStart; 30 | } 31 | 32 | if (!canGenerateInBlock(world, xStart, yStart--, zStart, baseBlock)) { 33 | return false; 34 | } 35 | 36 | int maxHeight = rand.nextInt(heightVariance) + minHeight; 37 | 38 | int size = genSize > 0 ? genSize : maxHeight / heightMod + rand.nextInt(sizeVariance); 39 | boolean r = false; 40 | for (int x = -size; x <= size; ++x) { 41 | for (int z = -size; z <= size; ++z) { 42 | if (!canGenerateInBlock(world, xStart + x, yStart + 1, zStart + z, baseBlock)) { 43 | continue; 44 | } 45 | int height = getHeight(x, z, size, rand, maxHeight); 46 | for (int y = 0; y < height; ++y) { 47 | r |= generateBlock(world, xStart + x, yStart - y, zStart + z, genBlock, cluster); 48 | } 49 | } 50 | } 51 | return r; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/numbers/UniformRandomProvider.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.numbers; 2 | 3 | import net.minecraft.util.math.BlockPos; 4 | import net.minecraft.world.World; 5 | 6 | import java.util.Random; 7 | 8 | public class UniformRandomProvider extends ConstantProvider { 9 | 10 | protected Number max; 11 | 12 | public UniformRandomProvider(Number min, Number max) { 13 | 14 | super(min); 15 | this.max = max; 16 | boolean longBad = min.longValue() >= max.longValue(); 17 | boolean doubleBad = min.doubleValue() >= max.doubleValue(); 18 | if (longBad && doubleBad) { 19 | throw new IllegalArgumentException("min >= max"); 20 | } 21 | } 22 | 23 | @Override 24 | public long longValue(World world, Random rand, BlockPos pos) { 25 | 26 | return getRandomLong(max.longValue() - min.longValue(), rand) + min.longValue(); 27 | } 28 | 29 | @Override 30 | public double doubleValue(World world, Random rand, BlockPos pos) { 31 | 32 | return getRandomDouble(max.doubleValue() - min.doubleValue(), rand) + min.doubleValue(); 33 | } 34 | 35 | public static long getRandomLong(long val, Random rand) { 36 | 37 | if (val == 0) { 38 | return 0; 39 | } 40 | int low = (int) (val & Integer.MAX_VALUE); 41 | int mid = (int) ((val >>> 31) & Integer.MAX_VALUE); 42 | int high = (int) ((val >>> 62) & Integer.MAX_VALUE); 43 | 44 | boolean mh = (mid | high) > 0; 45 | long r = mh ? rand.nextInt() & Integer.MAX_VALUE : rand.nextInt(low); 46 | if (mh) { 47 | r |= (high > 0 ? rand.nextInt() & Integer.MAX_VALUE : rand.nextInt(mid)) << 31; 48 | } 49 | if (high > 0) { 50 | r |= rand.nextInt(high) << 62; 51 | } 52 | 53 | return r; 54 | } 55 | 56 | public static double getRandomDouble(double val, Random rand) { 57 | 58 | return rand.nextDouble() * val; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/TileEnergyHandler.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | import net.minecraft.tileentity.TileEntity; 5 | import net.minecraft.util.EnumFacing; 6 | 7 | /** 8 | * Reference implementation of {@link IEnergyReceiver} and {@link IEnergyProvider}. Use/extend this or implement your own. 9 | * 10 | * This class is really meant to summarize how each interface is properly used. 11 | * 12 | * @author King Lemming 13 | */ 14 | public class TileEnergyHandler extends TileEntity implements IEnergyReceiver, IEnergyProvider { 15 | 16 | protected EnergyStorage storage = new EnergyStorage(32000); 17 | 18 | @Override 19 | public void readFromNBT(NBTTagCompound nbt) { 20 | 21 | super.readFromNBT(nbt); 22 | storage.readFromNBT(nbt); 23 | } 24 | 25 | @Override 26 | public NBTTagCompound writeToNBT(NBTTagCompound nbt) { 27 | 28 | super.writeToNBT(nbt); 29 | storage.writeToNBT(nbt); 30 | return nbt; 31 | } 32 | 33 | /* IEnergyConnection */ 34 | @Override 35 | public boolean canConnectEnergy(EnumFacing from) { 36 | 37 | return true; 38 | } 39 | 40 | /* IEnergyReceiver */ 41 | @Override 42 | public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { 43 | 44 | return storage.receiveEnergy(maxReceive, simulate); 45 | } 46 | 47 | /* IEnergyProvider */ 48 | @Override 49 | public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) { 50 | 51 | return storage.extractEnergy(maxExtract, simulate); 52 | } 53 | 54 | /* IEnergyHandler */ 55 | @Override 56 | public int getEnergyStored(EnumFacing from) { 57 | 58 | return storage.getEnergyStored(); 59 | } 60 | 61 | @Override 62 | public int getMaxEnergyStored(EnumFacing from) { 63 | 64 | return storage.getMaxEnergyStored(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/ComparableItemStackSafe.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import cofh.lib.util.helpers.ItemHelper; 4 | import net.minecraft.item.Item; 5 | import net.minecraft.item.ItemStack; 6 | 7 | /** 8 | * This is basically a default "safe" implementation of a ComparableItemStack - the OreID will only be used for the 5 "basic" conventions. 9 | * 10 | * @author King Lemming 11 | */ 12 | public class ComparableItemStackSafe extends ComparableItemStack { 13 | 14 | static final String BLOCK = "block"; 15 | static final String ORE = "ore"; 16 | static final String DUST = "dust"; 17 | static final String INGOT = "ingot"; 18 | static final String NUGGET = "nugget"; 19 | 20 | public static boolean safeOreType(String oreName) { 21 | 22 | return oreName.startsWith(BLOCK) || oreName.startsWith(ORE) || oreName.startsWith(DUST) || oreName.startsWith(INGOT) || oreName.startsWith(NUGGET); 23 | } 24 | 25 | public static int getOreID(ItemStack stack) { 26 | 27 | int id = ItemHelper.oreProxy.getOreID(stack); 28 | 29 | if (!safeOreType(ItemHelper.oreProxy.getOreName(id))) { 30 | return -1; 31 | } 32 | return id; 33 | } 34 | 35 | public static int getOreID(String oreName) { 36 | 37 | if (!safeOreType(oreName)) { 38 | return -1; 39 | } 40 | return ItemHelper.oreProxy.getOreID(oreName); 41 | } 42 | 43 | public ComparableItemStackSafe(ItemStack stack) { 44 | 45 | super(stack); 46 | oreID = getOreID(stack); 47 | } 48 | 49 | public ComparableItemStackSafe(Item item, int damage, int stackSize) { 50 | 51 | super(item, damage, stackSize); 52 | this.oreID = getOreID(this.toItemStack()); 53 | } 54 | 55 | @Override 56 | public ComparableItemStackSafe set(ItemStack stack) { 57 | 58 | super.set(stack); 59 | oreID = getOreID(stack); 60 | 61 | return this; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/IEnergyContainerItem.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.item.ItemStack; 4 | 5 | /** 6 | * Implement this interface on Item classes that support external manipulation of their internal energy storages. 7 | * 8 | * A reference implementation is provided {@link ItemEnergyContainer}. 9 | * 10 | * @author King Lemming 11 | */ 12 | public interface IEnergyContainerItem { 13 | 14 | /** 15 | * Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. 16 | * 17 | * @param container ItemStack to be charged. 18 | * @param maxReceive Maximum amount of energy to be sent into the item. 19 | * @param simulate If TRUE, the charge will only be simulated. 20 | * @return Amount of energy that was (or would have been, if simulated) received by the item. 21 | */ 22 | int receiveEnergy(ItemStack container, int maxReceive, boolean simulate); 23 | 24 | /** 25 | * Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally 26 | * discharged. 27 | * 28 | * @param container ItemStack to be discharged. 29 | * @param maxExtract Maximum amount of energy to be extracted from the item. 30 | * @param simulate If TRUE, the discharge will only be simulated. 31 | * @return Amount of energy that was (or would have been, if simulated) extracted from the item. 32 | */ 33 | int extractEnergy(ItemStack container, int maxExtract, boolean simulate); 34 | 35 | /** 36 | * Get the amount of energy currently stored in the container item. 37 | */ 38 | int getEnergyStored(ItemStack container); 39 | 40 | /** 41 | * Get the max amount of energy that can be stored in the container item. 42 | */ 43 | int getMaxEnergyStored(ItemStack container); 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/helpers/ColorHelper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.helpers; 2 | 3 | /** 4 | * Contains various helper functions to assist with colors. 5 | * 6 | * @author King Lemming 7 | */ 8 | public final class ColorHelper { 9 | 10 | private ColorHelper() { 11 | 12 | } 13 | 14 | public static final int DYE_BLACK = 0x191919; 15 | public static final int DYE_RED = 0xCC4C4C; 16 | public static final int DYE_GREEN = 0x667F33; 17 | public static final int DYE_BROWN = 0x7F664C; 18 | public static final int DYE_BLUE = 0x3366CC; 19 | public static final int DYE_PURPLE = 0xB266E5; 20 | public static final int DYE_CYAN = 0x4C99B2; 21 | public static final int DYE_LIGHT_GRAY = 0x999999; 22 | public static final int DYE_GRAY = 0x4C4C4C; 23 | public static final int DYE_PINK = 0xF2B2CC; 24 | public static final int DYE_LIME = 0x7FCC19; 25 | public static final int DYE_YELLOW = 0xE5E533; 26 | public static final int DYE_LIGHT_BLUE = 0x99B2F2; 27 | public static final int DYE_MAGENTA = 0xE57FD8; 28 | public static final int DYE_ORANGE = 0xF2B233; 29 | public static final int DYE_WHITE = 0xFFFFFF; 30 | 31 | public static final int[] DYE_COLORS = { DYE_BLACK, DYE_RED, DYE_GREEN, DYE_BROWN, DYE_BLUE, DYE_PURPLE, DYE_CYAN, DYE_LIGHT_GRAY, DYE_GRAY, DYE_PINK, DYE_LIME, DYE_YELLOW, DYE_LIGHT_BLUE, DYE_MAGENTA, DYE_ORANGE, DYE_WHITE }; 32 | 33 | // Yes, this list is pre-localized to en_US and has no spaces. There are times when this is useful, such as in a config file. Localization there is messy 34 | // and not strictly required. 35 | public static final String[] WOOL_COLOR_CONFIG = { "White", "Orange", "Magenta", "LightBlue", "Yellow", "Lime", "Pink", "Gray", "LightGray", "Cyan", "Purple", "Blue", "Brown", "Green", "Red", "Black" }; 36 | 37 | public static int getDyeColor(int color) { 38 | 39 | return color < 0 || color > 15 ? 0xFFFFFF : DYE_COLORS[color]; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/capabilities/EnergyContainerItemWrapper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.capabilities; 2 | 3 | import cofh.api.energy.IEnergyContainerItem; 4 | import net.minecraft.item.ItemStack; 5 | import net.minecraft.util.EnumFacing; 6 | import net.minecraftforge.common.capabilities.Capability; 7 | import net.minecraftforge.common.capabilities.ICapabilityProvider; 8 | import net.minecraftforge.energy.CapabilityEnergy; 9 | 10 | public class EnergyContainerItemWrapper implements ICapabilityProvider { 11 | 12 | final ItemStack stack; 13 | final IEnergyContainerItem container; 14 | 15 | public EnergyContainerItemWrapper(ItemStack stackIn, IEnergyContainerItem containerIn) { 16 | 17 | stack = stackIn; 18 | container = containerIn; 19 | } 20 | 21 | /* ICapabilityProvider */ 22 | @Override 23 | public boolean hasCapability(Capability capability, EnumFacing from) { 24 | 25 | return capability == CapabilityEnergy.ENERGY; 26 | } 27 | 28 | @Override 29 | public T getCapability(Capability capability, final EnumFacing from) { 30 | 31 | return CapabilityEnergy.ENERGY.cast(new net.minecraftforge.energy.IEnergyStorage() { 32 | @Override 33 | public int receiveEnergy(int maxReceive, boolean simulate) { 34 | 35 | return container.receiveEnergy(stack, maxReceive, simulate); 36 | } 37 | 38 | @Override 39 | public int extractEnergy(int maxExtract, boolean simulate) { 40 | 41 | return container.extractEnergy(stack, maxExtract, simulate); 42 | } 43 | 44 | @Override 45 | public int getEnergyStored() { 46 | 47 | return container.getEnergyStored(stack); 48 | } 49 | 50 | @Override 51 | public int getMaxEnergyStored() { 52 | 53 | return container.getMaxEnergyStored(stack); 54 | } 55 | 56 | @Override 57 | public boolean canExtract() { 58 | 59 | return true; 60 | } 61 | 62 | @Override 63 | public boolean canReceive() { 64 | 65 | return true; 66 | } 67 | }); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/item/IToolHammer.java: -------------------------------------------------------------------------------- 1 | package cofh.api.item; 2 | 3 | import net.minecraft.entity.Entity; 4 | import net.minecraft.entity.EntityLivingBase; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.util.math.BlockPos; 7 | 8 | /** 9 | * Implement this interface on subclasses of Item to have that item work as a tool for CoFH mods. 10 | */ 11 | public interface IToolHammer { 12 | 13 | /** 14 | * Called to ensure that the tool can be used on a block. 15 | * 16 | * @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools). 17 | * @param user The entity using the tool. 18 | * @param pos Coordinates of the block. 19 | * @return True if this tool can be used. 20 | */ 21 | boolean isUsable(ItemStack item, EntityLivingBase user, BlockPos pos); 22 | 23 | /** 24 | * Called to ensure that the tool can be used on an entity. 25 | * 26 | * @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools). 27 | * @param user The entity using the tool. 28 | * @param entity The entity the tool is being used on. 29 | * @return True if this tool can be used. 30 | */ 31 | boolean isUsable(ItemStack item, EntityLivingBase user, Entity entity); 32 | 33 | /** 34 | * Callback for when the tool has been used reactively. 35 | * 36 | * @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools). 37 | * @param user The entity using the tool. 38 | * @param pos Coordinates of the block. 39 | */ 40 | void toolUsed(ItemStack item, EntityLivingBase user, BlockPos pos); 41 | 42 | /** 43 | * Callback for when the tool has been used reactively. 44 | * 45 | * @param item The ItemStack for the tool. Not required to match equipped item (e.g., multi-tools that contain other tools). 46 | * @param user The entity using the tool. 47 | * @param entity The entity the tool is being used on. 48 | */ 49 | void toolUsed(ItemStack item, EntityLivingBase user, Entity entity); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementButtonManaged.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import net.minecraft.client.renderer.GlStateManager; 5 | 6 | public abstract class ElementButtonManaged extends ElementButtonBase { 7 | 8 | private String _text; 9 | 10 | public ElementButtonManaged(GuiBase containerScreen, int posX, int posY, int sizeX, int sizeY, String text) { 11 | 12 | super(containerScreen, posX, posY, sizeX, sizeY); 13 | _text = text; 14 | } 15 | 16 | public void setText(String text) { 17 | 18 | _text = text; 19 | } 20 | 21 | public String getText() { 22 | 23 | return _text; 24 | } 25 | 26 | protected void bindTexture(int mouseX, int mouseY) { 27 | 28 | if (!isEnabled()) { 29 | gui.bindTexture(DISABLED); 30 | } else if (intersectsWith(mouseX, mouseY)) { 31 | gui.bindTexture(HOVER); 32 | } else { 33 | gui.bindTexture(ENABLED); 34 | } 35 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); 36 | 37 | } 38 | 39 | @Override 40 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 41 | 42 | bindTexture(mouseX, mouseY); 43 | 44 | drawTexturedModalRect(posX, posY, 0, 0, sizeX / 2, sizeY / 2); 45 | drawTexturedModalRect(posX, posY + sizeY / 2, 0, 256 - sizeY / 2, sizeX / 2, sizeY / 2); 46 | drawTexturedModalRect(posX + sizeX / 2, posY, 256 - sizeX / 2, 0, sizeX / 2, sizeY / 2); 47 | drawTexturedModalRect(posX + sizeX / 2, posY + sizeY / 2, 256 - sizeX / 2, 256 - sizeY / 2, sizeX / 2, sizeY / 2); 48 | } 49 | 50 | @Override 51 | public void drawForeground(int mouseX, int mouseY) { 52 | 53 | String text = getFontRenderer().trimStringToWidth(_text, sizeX - 4); 54 | drawCenteredString(getFontRenderer(), text, posX + sizeX / 2, posY + (sizeY - 8) / 2, getTextColor(mouseX, mouseY)); 55 | } 56 | 57 | protected int getTextColor(int mouseX, int mouseY) { 58 | 59 | if (!isEnabled()) { 60 | return -6250336; 61 | } else if (intersectsWith(mouseX, mouseY)) { 62 | return 16777120; 63 | } else { 64 | return 14737632; 65 | } 66 | } 67 | 68 | @Override 69 | public abstract void onClick(); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureGenUniform.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.util.numbers.ConstantProvider; 4 | import cofh.lib.util.numbers.INumberProvider; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import net.minecraft.world.gen.feature.WorldGenerator; 8 | 9 | import java.util.Random; 10 | 11 | public class FeatureGenUniform extends FeatureBase { 12 | 13 | final WorldGenerator worldGen; 14 | final INumberProvider count; 15 | final INumberProvider minY; 16 | final INumberProvider maxY; 17 | 18 | public FeatureGenUniform(String name, WorldGenerator worldGen, int count, int minY, int maxY, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 19 | 20 | this(name, worldGen, new ConstantProvider(count), new ConstantProvider(minY), new ConstantProvider(maxY), biomeRes, regen, dimRes); 21 | } 22 | 23 | public FeatureGenUniform(String name, WorldGenerator worldGen, INumberProvider count, INumberProvider minY, INumberProvider maxY, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 24 | 25 | super(name, biomeRes, regen, dimRes); 26 | this.worldGen = worldGen; 27 | this.count = count; 28 | this.minY = minY; 29 | this.maxY = maxY; 30 | } 31 | 32 | @Override 33 | public boolean generateFeature(Random random, int blockX, int blockZ, World world) { 34 | 35 | BlockPos pos = new BlockPos(blockX, 64, blockZ); 36 | 37 | final int count = this.count.intValue(world, random, pos); 38 | final int minY = Math.max(this.minY.intValue(world, random, pos), 0), maxY = this.maxY.intValue(world, random, pos); 39 | if (minY > maxY) { 40 | return false; 41 | } 42 | 43 | boolean generated = false; 44 | for (int i = 0; i < count; i++) { 45 | int x = blockX + random.nextInt(16); 46 | int y = minY + (minY != maxY ? random.nextInt(maxY - minY) : 0); 47 | int z = blockZ + random.nextInt(16); 48 | if (!canGenerateInBiome(world, x, z, random)) { 49 | continue; 50 | } 51 | generated |= worldGen.generate(world, random, new BlockPos(x, y, z)); 52 | } 53 | return generated; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/Rectangle4i.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | /** 4 | * Generic rectangle class. 5 | * 6 | * @author Chicken Bones 7 | */ 8 | public class Rectangle4i { 9 | 10 | public int x; 11 | public int y; 12 | public int w; 13 | public int h; 14 | 15 | public Rectangle4i() { 16 | 17 | } 18 | 19 | public Rectangle4i(int x, int y, int w, int h) { 20 | 21 | this.x = x; 22 | this.y = y; 23 | this.w = w; 24 | this.h = h; 25 | } 26 | 27 | public int x1() { 28 | 29 | return x; 30 | } 31 | 32 | public int y1() { 33 | 34 | return y; 35 | } 36 | 37 | public int x2() { 38 | 39 | return x + w - 1; 40 | } 41 | 42 | public int y2() { 43 | 44 | return y + h - 1; 45 | } 46 | 47 | public void set(int x, int y, int w, int h) { 48 | 49 | this.x = x; 50 | this.y = y; 51 | this.w = w; 52 | this.h = h; 53 | } 54 | 55 | public Rectangle4i offset(int dx, int dy) { 56 | 57 | x += dx; 58 | y += dy; 59 | return this; 60 | } 61 | 62 | public Rectangle4i include(int px, int py) { 63 | 64 | if (px < x) { 65 | expand(px - x, 0); 66 | } 67 | if (px >= x + w) { 68 | expand(px - x - w + 1, 0); 69 | } 70 | if (py < y) { 71 | expand(0, py - y); 72 | } 73 | if (py >= y + h) { 74 | expand(0, py - y - h + 1); 75 | } 76 | return this; 77 | } 78 | 79 | public Rectangle4i include(Rectangle4i r) { 80 | 81 | include(r.x, r.y); 82 | return include(r.x2(), r.y2()); 83 | } 84 | 85 | public Rectangle4i expand(int px, int py) { 86 | 87 | if (px > 0) { 88 | w += px; 89 | } else { 90 | x += px; 91 | w -= px; 92 | } 93 | if (py > 0) { 94 | h += py; 95 | } else { 96 | y += py; 97 | h -= py; 98 | } 99 | return this; 100 | } 101 | 102 | public boolean contains(int px, int py) { 103 | 104 | return x <= px && px < x + w && y <= py && py < y + h; 105 | } 106 | 107 | public boolean intersects(Rectangle4i r) { 108 | 109 | return r.x + r.w > x && r.x < x + w && r.y + r.h > y && r.y < y + h; 110 | } 111 | 112 | public int area() { 113 | 114 | return w * h; 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/slot/SlotCustomInventory.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.slot; 2 | 3 | import cofh.lib.gui.container.ICustomInventory; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.inventory.IInventory; 6 | import net.minecraft.inventory.Slot; 7 | import net.minecraft.item.ItemStack; 8 | 9 | public class SlotCustomInventory extends Slot { 10 | 11 | ICustomInventory customInv; 12 | int inventoryIndex = 0; 13 | boolean canTake = true; 14 | 15 | public SlotCustomInventory(ICustomInventory tile, int invIndex, IInventory inventory, int slotIndex, int x, int y, boolean lootable) { 16 | 17 | super(inventory, slotIndex, x, y); 18 | customInv = tile; 19 | inventoryIndex = invIndex; 20 | canTake = lootable; 21 | } 22 | 23 | @Override 24 | public ItemStack getStack() { 25 | 26 | return customInv.getInventorySlots(inventoryIndex)[getSlotIndex()]; 27 | } 28 | 29 | @Override 30 | public void putStack(ItemStack stack) { 31 | 32 | customInv.getInventorySlots(inventoryIndex)[getSlotIndex()] = stack; 33 | onSlotChanged(); 34 | } 35 | 36 | @Override 37 | public void onSlotChanged() { 38 | 39 | customInv.onSlotUpdate(); 40 | } 41 | 42 | @Override 43 | public int getSlotStackLimit() { 44 | 45 | return customInv.getSlotStackLimit(getSlotIndex()); 46 | } 47 | 48 | @Override 49 | public ItemStack decrStackSize(int amount) { 50 | 51 | if (customInv.getInventorySlots(inventoryIndex)[getSlotIndex()] == null) { 52 | return null; 53 | } 54 | if (customInv.getInventorySlots(inventoryIndex)[getSlotIndex()].stackSize <= amount) { 55 | amount = customInv.getInventorySlots(inventoryIndex)[getSlotIndex()].stackSize; 56 | } 57 | ItemStack stack = customInv.getInventorySlots(inventoryIndex)[getSlotIndex()].splitStack(amount); 58 | 59 | if (customInv.getInventorySlots(inventoryIndex)[getSlotIndex()].stackSize <= 0) { 60 | customInv.getInventorySlots(inventoryIndex)[getSlotIndex()] = null; 61 | } 62 | return stack; 63 | } 64 | 65 | @Override 66 | public boolean isHere(IInventory inventory, int slot) { 67 | 68 | return false; 69 | } 70 | 71 | @Override 72 | public boolean canTakeStack(EntityPlayer par1EntityPlayer) { 73 | 74 | return canTake; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/BlockWrapper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.block.state.IBlockState; 5 | 6 | import javax.annotation.Nonnull; 7 | 8 | /** 9 | * Wrapper for a Block/Metadata combination post 1.7. Quick and dirty, allows for Integer-based Hashes without collisions. 10 | * 11 | * @author King Lemming 12 | */ 13 | public final class BlockWrapper { 14 | 15 | public Block block; 16 | public int metadata; 17 | 18 | public BlockWrapper(IBlockState state) { 19 | 20 | this(state.getBlock(), state.getBlock().getMetaFromState(state)); 21 | } 22 | 23 | public BlockWrapper(Block block, int metadata) { 24 | 25 | this.block = block; 26 | this.metadata = metadata; 27 | } 28 | 29 | public BlockWrapper set(Block block, int metadata) { 30 | 31 | if (block != null) { 32 | this.block = block; 33 | this.metadata = metadata; 34 | } else { 35 | this.block = null; 36 | this.metadata = 0; 37 | } 38 | return this; 39 | } 40 | 41 | public boolean isEqual(@Nonnull IBlockState state) { 42 | 43 | return block == state.getBlock() && metadata == block.getMetaFromState(state); 44 | } 45 | 46 | public boolean isEqual(BlockWrapper other) { 47 | 48 | if (other == null) { 49 | return false; 50 | } 51 | if (metadata == other.metadata) { 52 | if (block == other.block) { 53 | return true; 54 | } 55 | if (block != null && other.block != null) { 56 | return block.delegate.get() == other.block.delegate.get(); 57 | } 58 | } 59 | return false; 60 | } 61 | 62 | final int getId() { 63 | 64 | return Block.getIdFromBlock(block); 65 | } 66 | 67 | @Override 68 | public boolean equals(Object o) { 69 | 70 | if (!(o instanceof BlockWrapper)) { 71 | return false; 72 | } 73 | return isEqual((BlockWrapper) o); 74 | } 75 | 76 | @Override 77 | public int hashCode() { 78 | 79 | return metadata | getId() << 16; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | 85 | String b = getClass().getName() + '@' + System.identityHashCode(this) + '{' + "m:" + metadata + ", i:" + (block == null ? null : block.getClass().getName()) + '@' + System.identityHashCode(block) + ", v:" + getId() + '}'; 86 | return b; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/biome/BiomeInfo.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.biome; 2 | 3 | import net.minecraft.util.ResourceLocation; 4 | import net.minecraft.world.biome.Biome; 5 | import net.minecraft.world.biome.Biome.TempCategory; 6 | import net.minecraftforge.common.BiomeDictionary; 7 | import net.minecraftforge.common.BiomeDictionary.Type; 8 | 9 | import java.util.Collection; 10 | import java.util.Random; 11 | 12 | public class BiomeInfo { 13 | 14 | private final Object data; 15 | private final boolean whitelist; 16 | private final int type; 17 | private final int hash; 18 | 19 | public BiomeInfo(String name) { 20 | 21 | data = name; 22 | hash = name.hashCode(); 23 | whitelist = true; 24 | type = 0; 25 | } 26 | 27 | public BiomeInfo(Object d, int t, boolean wl) { 28 | 29 | data = d; 30 | hash = 0; 31 | whitelist = wl; 32 | type = t; 33 | } 34 | 35 | @SuppressWarnings ("unchecked") 36 | public boolean isBiomeEqual(Biome biome, Random rand) { 37 | 38 | boolean r = false; 39 | if (biome != null) { 40 | switch (type) { 41 | default: 42 | break; 43 | case 0: 44 | String name = biome.getBiomeName(); 45 | r = name.hashCode() == hash && name.equals(data); 46 | break; 47 | case 1: 48 | r = biome.getTempCategory() == data; 49 | break; 50 | case 2: 51 | r = BiomeDictionary.isBiomeOfType(biome, (Type) data); 52 | break; 53 | case 4: 54 | r = ((Collection) data).contains(biome.getBiomeName()); 55 | break; 56 | case 5: 57 | r = ((Collection) data).contains(biome.getTempCategory()); 58 | break; 59 | case 6: 60 | Type[] d = (Type[]) data; 61 | int c = 0, e = d.length; 62 | for (int i = 0; i < e; ++i) { 63 | if (BiomeDictionary.isBiomeOfType(biome, d[i])) { 64 | ++c; 65 | } 66 | } 67 | r = c == e; 68 | break; 69 | case 7: 70 | ResourceLocation registry = Biome.REGISTRY.getNameForObject(biome); 71 | r = registry.hashCode() == hash && registry.equals(data); 72 | break; 73 | case 8: 74 | r = ((Collection) data).contains(Biome.REGISTRY.getNameForObject(biome)); 75 | break; 76 | } 77 | } 78 | return r == whitelist; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/WeightedRandomBlock.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.block.Block; 4 | import net.minecraft.block.state.IBlockState; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.util.WeightedRandom; 7 | 8 | import java.util.Collection; 9 | 10 | /** 11 | * This class essentially allows for ores to be generated in clusters, with Features randomly choosing one or more blocks from a weighted list. 12 | * 13 | * @author King Lemming 14 | */ 15 | public final class WeightedRandomBlock extends WeightedRandom.Item { 16 | 17 | public final Block block; 18 | public final int metadata; 19 | public final IBlockState state; 20 | 21 | public WeightedRandomBlock(ItemStack ore) { 22 | 23 | this(ore, 100); 24 | } 25 | 26 | public WeightedRandomBlock(ItemStack ore, int weight) { 27 | 28 | this(Block.getBlockFromItem(ore.getItem()), ore.getItemDamage(), weight); 29 | } 30 | 31 | public WeightedRandomBlock(Block ore) { 32 | 33 | this(ore, 0, 100); // some blocks do not have associated items 34 | } 35 | 36 | public WeightedRandomBlock(Block ore, int metadata) { 37 | 38 | this(ore, metadata, 100); 39 | } 40 | 41 | public WeightedRandomBlock(Block ore, int metadata, int weight) { 42 | 43 | super(weight); 44 | this.block = ore; 45 | this.metadata = metadata; 46 | this.state = null; 47 | } 48 | 49 | public WeightedRandomBlock(IBlockState ore, int weight) { 50 | 51 | super(weight); 52 | this.block = ore.getBlock(); 53 | this.metadata = block.getMetaFromState(ore); 54 | this.state = ore; 55 | } 56 | 57 | public static boolean isBlockContained(Block block, int metadata, Collection list) { 58 | 59 | for (WeightedRandomBlock rb : list) { 60 | if (block.equals(rb.block) && (metadata == -1 || rb.metadata == -1 || rb.metadata == metadata)) { 61 | return true; 62 | } 63 | } 64 | return false; 65 | } 66 | 67 | public static boolean isBlockContained(Block block, int metadata, WeightedRandomBlock[] list) { 68 | 69 | for (WeightedRandomBlock rb : list) { 70 | if (block.equals(rb.block) && (metadata == -1 || rb.metadata == -1 || rb.metadata == metadata)) { 71 | return true; 72 | } 73 | } 74 | return false; 75 | } 76 | 77 | public IBlockState getState() { 78 | 79 | return state == null ? block.getStateFromMeta(metadata) : state; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/capabilities/FluidContainerItemWrapper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.capabilities; 2 | 3 | import cofh.lib.util.helpers.FluidHelper; 4 | import net.minecraft.item.ItemStack; 5 | import net.minecraft.util.EnumFacing; 6 | import net.minecraftforge.common.capabilities.Capability; 7 | import net.minecraftforge.common.capabilities.ICapabilityProvider; 8 | import net.minecraftforge.fluids.FluidStack; 9 | import net.minecraftforge.fluids.IFluidContainerItem; 10 | import net.minecraftforge.fluids.capability.CapabilityFluidHandler; 11 | import net.minecraftforge.fluids.capability.FluidTankProperties; 12 | import net.minecraftforge.fluids.capability.IFluidHandler; 13 | import net.minecraftforge.fluids.capability.IFluidTankProperties; 14 | 15 | import javax.annotation.Nullable; 16 | 17 | public class FluidContainerItemWrapper implements ICapabilityProvider { 18 | 19 | final ItemStack stack; 20 | final IFluidContainerItem container; 21 | 22 | public FluidContainerItemWrapper(ItemStack stackIn, IFluidContainerItem containerIn) { 23 | 24 | stack = stackIn; 25 | container = containerIn; 26 | } 27 | 28 | @Override 29 | public boolean hasCapability(Capability capability, EnumFacing from) { 30 | 31 | return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY; 32 | } 33 | 34 | @Override 35 | public T getCapability(Capability capability, final EnumFacing from) { 36 | 37 | return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(new IFluidHandler() { 38 | @Override 39 | public IFluidTankProperties[] getTankProperties() { 40 | 41 | return new IFluidTankProperties[] { new FluidTankProperties(container.getFluid(stack), container.getCapacity(stack), true, false) }; 42 | } 43 | 44 | @Override 45 | public int fill(FluidStack resource, boolean doFill) { 46 | 47 | return container.fill(stack, resource, doFill); 48 | } 49 | 50 | @Nullable 51 | @Override 52 | public FluidStack drain(FluidStack resource, boolean doDrain) { 53 | 54 | if (FluidHelper.isFluidEqual(resource, container.getFluid(stack))) { 55 | return container.drain(stack, resource.amount, doDrain); 56 | } 57 | return null; 58 | } 59 | 60 | @Nullable 61 | @Override 62 | public FluidStack drain(int maxDrain, boolean doDrain) { 63 | 64 | return container.drain(stack, maxDrain, doDrain); 65 | } 66 | }); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureGenSurface.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import cofh.lib.util.helpers.BlockHelper; 5 | import cofh.lib.util.numbers.ConstantProvider; 6 | import cofh.lib.util.numbers.INumberProvider; 7 | import net.minecraft.block.state.IBlockState; 8 | import net.minecraft.util.math.BlockPos; 9 | import net.minecraft.world.World; 10 | import net.minecraft.world.gen.feature.WorldGenerator; 11 | 12 | import java.util.List; 13 | import java.util.Random; 14 | 15 | import static cofh.lib.world.WorldGenMinableCluster.canGenerateInBlock; 16 | 17 | public class FeatureGenSurface extends FeatureBase { 18 | 19 | final WorldGenerator worldGen; 20 | final INumberProvider count; 21 | final WeightedRandomBlock[] matList; 22 | 23 | public FeatureGenSurface(String name, WorldGenerator worldGen, List matList, int count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 24 | 25 | this(name, worldGen, matList, new ConstantProvider(count), biomeRes, regen, dimRes); 26 | } 27 | 28 | public FeatureGenSurface(String name, WorldGenerator worldGen, List matList, INumberProvider count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 29 | 30 | super(name, biomeRes, regen, dimRes); 31 | this.worldGen = worldGen; 32 | this.count = count; 33 | this.matList = matList.toArray(new WeightedRandomBlock[matList.size()]); 34 | } 35 | 36 | @Override 37 | public boolean generateFeature(Random random, int blockX, int blockZ, World world) { 38 | 39 | BlockPos pos = new BlockPos(blockX, 64, blockZ); 40 | 41 | final int count = this.count.intValue(world, random, pos); 42 | 43 | boolean generated = false; 44 | for (int i = 0; i < count; i++) { 45 | int x = blockX + random.nextInt(16); 46 | int z = blockZ + random.nextInt(16); 47 | if (!canGenerateInBiome(world, x, z, random)) { 48 | continue; 49 | } 50 | 51 | int y = BlockHelper.getSurfaceBlockY(world, x, z); 52 | l: 53 | { 54 | IBlockState state = world.getBlockState(new BlockPos(x, y, z)); 55 | if (!state.getBlock().isAir(state, world, new BlockPos(x, y, z)) && canGenerateInBlock(world, x, y, z, matList)) { 56 | break l; 57 | } 58 | continue; 59 | } 60 | 61 | generated |= worldGen.generate(world, random, new BlockPos(x, y + 1, z)); 62 | } 63 | return generated; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureGenTopBlock.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import cofh.lib.util.helpers.BlockHelper; 5 | import cofh.lib.util.numbers.ConstantProvider; 6 | import cofh.lib.util.numbers.INumberProvider; 7 | import net.minecraft.block.state.IBlockState; 8 | import net.minecraft.util.math.BlockPos; 9 | import net.minecraft.world.World; 10 | import net.minecraft.world.gen.feature.WorldGenerator; 11 | 12 | import java.util.List; 13 | import java.util.Random; 14 | 15 | import static cofh.lib.world.WorldGenMinableCluster.canGenerateInBlock; 16 | 17 | public class FeatureGenTopBlock extends FeatureBase { 18 | 19 | final WorldGenerator worldGen; 20 | final INumberProvider count; 21 | final WeightedRandomBlock[] matList; 22 | 23 | public FeatureGenTopBlock(String name, WorldGenerator worldGen, List matList, int count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 24 | 25 | this(name, worldGen, matList, new ConstantProvider(count), biomeRes, regen, dimRes); 26 | } 27 | 28 | public FeatureGenTopBlock(String name, WorldGenerator worldGen, List matList, INumberProvider count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 29 | 30 | super(name, biomeRes, regen, dimRes); 31 | this.worldGen = worldGen; 32 | this.count = count; 33 | this.matList = matList.toArray(new WeightedRandomBlock[matList.size()]); 34 | } 35 | 36 | @Override 37 | public boolean generateFeature(Random random, int blockX, int blockZ, World world) { 38 | 39 | BlockPos pos = new BlockPos(blockX, 64, blockZ); 40 | 41 | final int count = this.count.intValue(world, random, pos); 42 | 43 | boolean generated = false; 44 | for (int i = 0; i < count; i++) { 45 | int x = blockX + random.nextInt(16); 46 | int z = blockZ + random.nextInt(16); 47 | if (!canGenerateInBiome(world, x, z, random)) { 48 | continue; 49 | } 50 | 51 | int y = BlockHelper.getTopBlockY(world, x, z); 52 | l: 53 | { 54 | IBlockState state = world.getBlockState(new BlockPos(x, y, z)); 55 | if (!state.getBlock().isAir(state, world, new BlockPos(x, y, z)) && canGenerateInBlock(world, x, y, z, matList)) { 56 | break l; 57 | } 58 | continue; 59 | } 60 | 61 | generated |= worldGen.generate(world, random, new BlockPos(x, y + 1, z)); 62 | } 63 | return generated; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureGenGaussian.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.util.numbers.ConstantProvider; 4 | import cofh.lib.util.numbers.INumberProvider; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import net.minecraft.world.gen.feature.WorldGenerator; 8 | 9 | import java.util.Random; 10 | 11 | public class FeatureGenGaussian extends FeatureBase { 12 | 13 | final WorldGenerator worldGen; 14 | final INumberProvider count; 15 | final INumberProvider rolls; 16 | final INumberProvider meanY; 17 | final INumberProvider maxVar; 18 | 19 | public FeatureGenGaussian(String name, WorldGenerator worldGen, int count, int smoothness, int meanY, int maxVar, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 20 | 21 | this(name, worldGen, new ConstantProvider(count), new ConstantProvider(smoothness), new ConstantProvider(meanY), new ConstantProvider(maxVar), biomeRes, regen, dimRes); 22 | } 23 | 24 | public FeatureGenGaussian(String name, WorldGenerator worldGen, INumberProvider count, INumberProvider smoothness, INumberProvider meanY, INumberProvider maxVar, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 25 | 26 | super(name, biomeRes, regen, dimRes); 27 | this.worldGen = worldGen; 28 | this.count = count; 29 | this.rolls = smoothness; 30 | this.meanY = meanY; 31 | this.maxVar = maxVar; 32 | } 33 | 34 | @Override 35 | public boolean generateFeature(Random random, int blockX, int blockZ, World world) { 36 | 37 | BlockPos pos = new BlockPos(blockX, 64, blockZ); 38 | 39 | final int count = this.count.intValue(world, random, pos); 40 | final int meanY = this.meanY.intValue(world, random, pos); 41 | 42 | boolean generated = false; 43 | for (int i = 0; i < count; i++) { 44 | int x = blockX + random.nextInt(16); 45 | int y = meanY; 46 | final int maxVar = this.maxVar.intValue(world, random, pos); 47 | if (maxVar > 1) { 48 | final int rolls = this.rolls.intValue(world, random, pos); 49 | for (int v = 0; v < rolls; ++v) { 50 | y += random.nextInt(maxVar); 51 | } 52 | y = Math.round(y - (maxVar * (rolls * .5f))); 53 | } 54 | int z = blockZ + random.nextInt(16); 55 | if (!canGenerateInBiome(world, x, z, random)) { 56 | continue; 57 | } 58 | 59 | generated |= worldGen.generate(world, random, new BlockPos(x, y, z)); 60 | } 61 | return generated; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementEnergyStored.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.api.energy.IEnergyStorage; 4 | import cofh.lib.gui.GuiBase; 5 | import cofh.lib.gui.GuiProps; 6 | import cofh.lib.util.helpers.MathHelper; 7 | import cofh.lib.util.helpers.RenderHelper; 8 | import cofh.lib.util.helpers.StringHelper; 9 | import net.minecraft.util.ResourceLocation; 10 | 11 | import java.util.List; 12 | 13 | public class ElementEnergyStored extends ElementBase { 14 | 15 | public static final ResourceLocation DEFAULT_TEXTURE = new ResourceLocation(GuiProps.PATH_ELEMENTS + "energy.png"); 16 | public static final int DEFAULT_SCALE = 42; 17 | 18 | protected IEnergyStorage storage; 19 | 20 | // If this is enabled, 1 pixel of energy will always show in the bar as long as it is non-zero. 21 | protected boolean alwaysShowMinimum = false; 22 | 23 | public ElementEnergyStored(GuiBase gui, int posX, int posY, IEnergyStorage storage) { 24 | 25 | super(gui, posX, posY); 26 | this.storage = storage; 27 | 28 | this.texture = DEFAULT_TEXTURE; 29 | this.sizeX = 16; 30 | this.sizeY = DEFAULT_SCALE; 31 | 32 | this.texW = 32; 33 | this.texH = 64; 34 | } 35 | 36 | public ElementEnergyStored setAlwaysShow(boolean show) { 37 | 38 | alwaysShowMinimum = show; 39 | return this; 40 | } 41 | 42 | @Override 43 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 44 | 45 | int amount = getScaled(); 46 | RenderHelper.bindTexture(texture); 47 | drawTexturedModalRect(posX, posY, 0, 0, sizeX, sizeY); 48 | drawTexturedModalRect(posX, posY + DEFAULT_SCALE - amount, 16, DEFAULT_SCALE - amount, sizeX, amount); 49 | } 50 | 51 | @Override 52 | public void drawForeground(int mouseX, int mouseY) { 53 | 54 | } 55 | 56 | @Override 57 | public void addTooltip(List list) { 58 | 59 | if (storage.getMaxEnergyStored() < 0) { 60 | list.add("Infinite RF"); 61 | } else { 62 | list.add(StringHelper.formatNumber(storage.getEnergyStored()) + " / " + StringHelper.formatNumber(storage.getMaxEnergyStored()) + " RF"); 63 | } 64 | } 65 | 66 | protected int getScaled() { 67 | 68 | if (storage.getMaxEnergyStored() <= 0) { 69 | return sizeY; 70 | } 71 | long fraction = (long) storage.getEnergyStored() * sizeY / storage.getMaxEnergyStored(); 72 | 73 | return alwaysShowMinimum && storage.getEnergyStored() > 0 ? Math.max(1, MathHelper.round(fraction)) : MathHelper.round(fraction); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/helpers/WrenchHelper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.helpers; 2 | 3 | import cofh.api.item.IToolHammer; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.util.EnumHand; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.util.math.RayTraceResult; 9 | 10 | // TODO: Update for 1.8.9 APIs. 11 | public final class WrenchHelper { 12 | 13 | private WrenchHelper() { 14 | 15 | } 16 | 17 | public static boolean isHoldingUsableWrench(EntityPlayer player, RayTraceResult traceResult) { 18 | 19 | EnumHand hand = EnumHand.MAIN_HAND; 20 | ItemStack stack = player.getHeldItem(hand); 21 | if (stack == null) { 22 | hand = EnumHand.OFF_HAND; 23 | stack = player.getHeldItem(hand); 24 | } 25 | if (stack == null) { 26 | return false; 27 | } 28 | if (stack.getItem() instanceof IToolHammer) { 29 | BlockPos pos = traceResult.getBlockPos(); 30 | return ((IToolHammer) stack.getItem()).isUsable(stack, player, pos); 31 | } else if (bcWrenchExists) { 32 | //return canHandleBCWrench(player, hand, stack, traceResult); 33 | } 34 | return false; 35 | } 36 | 37 | public static void usedWrench(EntityPlayer player, RayTraceResult traceResult) { 38 | 39 | EnumHand hand = EnumHand.MAIN_HAND; 40 | ItemStack stack = player.getHeldItem(hand); 41 | if (stack == null) { 42 | hand = EnumHand.OFF_HAND; 43 | stack = player.getHeldItem(hand); 44 | } 45 | if (stack == null) { 46 | return; 47 | } 48 | if (stack.getItem() instanceof IToolHammer) { 49 | BlockPos pos = traceResult.getBlockPos(); 50 | ((IToolHammer) stack.getItem()).toolUsed(stack, player, pos); 51 | } else if (bcWrenchExists) { 52 | //bcWrenchUsed(player, hand, stack, traceResult); 53 | } 54 | } 55 | 56 | /* HELPERS */ 57 | private static boolean bcWrenchExists = false; 58 | 59 | static { 60 | try { 61 | Class.forName("buildcraft.api.tools.IToolWrench"); 62 | bcWrenchExists = true; 63 | } catch (Throwable t) { 64 | // pokemon! 65 | } 66 | } 67 | 68 | // private static boolean canHandleBCWrench(Item item, EntityPlayer player, BlockPos pos) { 69 | // 70 | // return item instanceof IToolWrench && ((IToolWrench) item).canWrench(player, pos); 71 | // } 72 | // 73 | // private static void bcWrenchUsed(Item item, EntityPlayer player, BlockPos pos) { 74 | // 75 | // if (item instanceof IToolWrench) { 76 | // ((IToolWrench) item).wrenchUsed(player, pos); 77 | // } 78 | // } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/audio/SoundTile.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.audio; 2 | 3 | import net.minecraft.client.audio.ITickableSound; 4 | import net.minecraft.client.audio.PositionedSound; 5 | import net.minecraft.util.SoundCategory; 6 | import net.minecraft.util.SoundEvent; 7 | import net.minecraft.util.math.Vec3d; 8 | 9 | public class SoundTile extends PositionedSound implements ITickableSound { 10 | 11 | ISoundSource source; 12 | boolean beginFadeOut; 13 | boolean donePlaying; 14 | int ticks = 0; 15 | int fadeIn = 50; 16 | int fadeOut = 50; 17 | float baseVolume = 1.0F; 18 | 19 | public SoundTile(ISoundSource source, SoundEvent sound, float volume, float pitch, boolean repeat, int repeatDelay, Vec3d pos) { 20 | 21 | this(source, sound, volume, pitch, repeat, repeatDelay, pos, AttenuationType.LINEAR); 22 | } 23 | 24 | public SoundTile(ISoundSource source, SoundEvent sound, float volume, float pitch, boolean repeat, int repeatDelay, Vec3d pos, AttenuationType attenuation) { 25 | 26 | super(sound, SoundCategory.AMBIENT); 27 | this.xPosF = (float) pos.xCoord; 28 | this.yPosF = (float) pos.yCoord; 29 | this.zPosF = (float) pos.zCoord; 30 | this.volume = volume; 31 | this.pitch = pitch; 32 | this.repeat = repeat; 33 | this.repeatDelay = repeatDelay; 34 | this.attenuationType = attenuation; 35 | this.source = source; 36 | this.baseVolume = volume; 37 | } 38 | 39 | public SoundTile setFadeIn(int fadeIn) { 40 | 41 | this.fadeIn = Math.min(0, fadeIn); 42 | return this; 43 | } 44 | 45 | public SoundTile setFadeOut(int fadeOut) { 46 | 47 | this.fadeOut = Math.min(0, fadeOut); 48 | return this; 49 | } 50 | 51 | public float getFadeInMultiplier() { 52 | 53 | return ticks >= fadeIn ? 1 : ticks / (float) fadeIn; 54 | } 55 | 56 | public float getFadeOutMultiplier() { 57 | 58 | return ticks >= fadeOut ? 0 : (fadeOut - ticks) / (float) fadeOut; 59 | } 60 | 61 | /* ITickableSound */ 62 | @Override 63 | public void update() { 64 | 65 | if (!beginFadeOut) { 66 | if (ticks < fadeIn) { 67 | ticks++; 68 | } 69 | if (!source.shouldPlaySound()) { 70 | beginFadeOut = true; 71 | ticks = 0; 72 | } 73 | } else { 74 | ticks++; 75 | } 76 | float multiplier = beginFadeOut ? getFadeOutMultiplier() : getFadeInMultiplier(); 77 | volume = baseVolume * multiplier; 78 | 79 | if (multiplier <= 0) { 80 | donePlaying = true; 81 | } 82 | } 83 | 84 | @Override 85 | public boolean isDonePlaying() { 86 | 87 | return donePlaying; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/helpers/DamageHelper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util.helpers; 2 | 3 | import net.minecraft.entity.Entity; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.util.DamageSource; 6 | import net.minecraft.util.EntityDamageSource; 7 | 8 | /** 9 | * This class contains helper functions related to Damage types that CoFH mods add. 10 | * 11 | * @author King Lemming 12 | */ 13 | public class DamageHelper { 14 | 15 | private DamageHelper() { 16 | 17 | } 18 | 19 | /* DAMAGE SOURCES */ 20 | public static final DamageSourcePyrotheum pyrotheum = new DamageSourcePyrotheum(); 21 | public static final DamageSourceCryotheum cryotheum = new DamageSourceCryotheum(); 22 | public static final DamageSourcePetrotheum petrotheum = new DamageSourcePetrotheum(); 23 | public static final DamageSourceMana mana = new DamageSourceMana(); 24 | public static final DamageSourceFlux flux = new DamageSourceFlux(); 25 | 26 | /* DAMAGE SOURCE CLASSES */ 27 | public static class DamageSourcePyrotheum extends DamageSource { 28 | 29 | protected DamageSourcePyrotheum() { 30 | 31 | super("pyrotheum"); 32 | this.setDamageBypassesArmor(); 33 | this.isFireDamage(); 34 | } 35 | } 36 | 37 | public static class DamageSourceCryotheum extends DamageSource { 38 | 39 | protected DamageSourceCryotheum() { 40 | 41 | super("cryotheum"); 42 | this.setDamageBypassesArmor(); 43 | } 44 | } 45 | 46 | public static class DamageSourcePetrotheum extends DamageSource { 47 | 48 | protected DamageSourcePetrotheum() { 49 | 50 | super("petrotheum"); 51 | this.setDamageBypassesArmor(); 52 | } 53 | } 54 | 55 | public static class DamageSourceMana extends DamageSource { 56 | 57 | protected DamageSourceMana() { 58 | 59 | super("mana"); 60 | this.setDamageBypassesArmor(); 61 | this.isMagicDamage(); 62 | } 63 | } 64 | 65 | public static class DamageSourceFlux extends DamageSource { 66 | 67 | protected DamageSourceFlux() { 68 | 69 | super("flux"); 70 | this.setDamageBypassesArmor(); 71 | } 72 | } 73 | 74 | /* ENTITY DAMAGE SOURCES */ 75 | public static class EntityDamageSourceFlux extends EntityDamageSource { 76 | 77 | public EntityDamageSourceFlux(String type, Entity entity) { 78 | 79 | super(type, entity); 80 | this.setDamageBypassesArmor(); 81 | } 82 | } 83 | 84 | /* HELPERS */ 85 | public static DamageSource causePlayerFluxDamage(EntityPlayer entityPlayer) { 86 | 87 | return new EntityDamageSourceFlux("player", entityPlayer); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/ChunkCoord.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import cofh.lib.util.helpers.BlockHelper; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.chunk.Chunk; 6 | 7 | import java.io.Serializable; 8 | 9 | /** 10 | * Standardized implementation for representing and manipulating Chunk Coordinates. Provides standard Java Collection interaction. 11 | * 12 | * @author King Lemming 13 | */ 14 | public final class ChunkCoord implements Comparable, Serializable { 15 | 16 | private static final long serialVersionUID = -9154178151445196959L; 17 | 18 | public int chunkX; 19 | public int chunkZ; 20 | 21 | public ChunkCoord(Chunk chunk) { 22 | 23 | this.chunkX = chunk.xPosition; 24 | this.chunkZ = chunk.zPosition; 25 | } 26 | 27 | public ChunkCoord(BlockPos pos) { 28 | 29 | this(pos.getX() >> 4, pos.getZ() >> 4); 30 | } 31 | 32 | public ChunkCoord(int x, int z) { 33 | 34 | this.chunkX = x; 35 | this.chunkZ = z; 36 | } 37 | 38 | public int getCenterX() { 39 | 40 | return (this.chunkX << 4) + 8; 41 | } 42 | 43 | public int getCenterZ() { 44 | 45 | return (this.chunkZ << 4) + 8; 46 | } 47 | 48 | public void step(int dir) { 49 | 50 | chunkX += BlockHelper.SIDE_COORD_MOD[dir][0]; 51 | chunkZ += BlockHelper.SIDE_COORD_MOD[dir][2]; 52 | } 53 | 54 | public void step(int dir, int dist) { 55 | 56 | switch (dir) { 57 | case 2: 58 | this.chunkZ -= dist; 59 | break; 60 | case 3: 61 | this.chunkZ += dist; 62 | break; 63 | case 4: 64 | this.chunkX -= dist; 65 | break; 66 | case 5: 67 | this.chunkX += dist; 68 | break; 69 | default: 70 | } 71 | } 72 | 73 | public ChunkCoord copy() { 74 | 75 | return new ChunkCoord(chunkX, chunkZ); 76 | } 77 | 78 | @Override 79 | public boolean equals(Object obj) { 80 | 81 | if (!(obj instanceof ChunkCoord)) { 82 | return false; 83 | } 84 | ChunkCoord other = (ChunkCoord) obj; 85 | return this.chunkX == other.chunkX && this.chunkZ == other.chunkZ; 86 | } 87 | 88 | @Override 89 | public int hashCode() { 90 | 91 | int hash = chunkX; 92 | hash *= 31 + this.chunkZ; 93 | return hash; 94 | } 95 | 96 | @Override 97 | public String toString() { 98 | 99 | return "[" + this.chunkX + ", " + this.chunkZ + "]"; 100 | } 101 | 102 | /* Comparable */ 103 | @Override 104 | public int compareTo(ChunkCoord other) { 105 | 106 | return this.chunkX == other.chunkX ? this.chunkZ - other.chunkZ : this.chunkX - other.chunkX; 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/WorldGenMinablePlate.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import cofh.lib.util.numbers.ConstantProvider; 5 | import cofh.lib.util.numbers.INumberProvider; 6 | import cofh.lib.util.numbers.UniformRandomProvider; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.world.World; 9 | import net.minecraft.world.gen.feature.WorldGenerator; 10 | 11 | import java.util.List; 12 | import java.util.Random; 13 | 14 | import static cofh.lib.world.WorldGenMinableCluster.generateBlock; 15 | 16 | public class WorldGenMinablePlate extends WorldGenerator { 17 | 18 | private final List cluster; 19 | private final WeightedRandomBlock[] genBlock; 20 | private final INumberProvider radius; 21 | private INumberProvider height; 22 | private boolean slim; 23 | 24 | public WorldGenMinablePlate(List resource, int clusterSize, List block) { 25 | 26 | this(resource, new UniformRandomProvider(clusterSize, clusterSize + 2), block); 27 | } 28 | 29 | public WorldGenMinablePlate(List resource, INumberProvider clusterSize, List block) { 30 | 31 | cluster = resource; 32 | radius = clusterSize; 33 | genBlock = block.toArray(new WeightedRandomBlock[block.size()]); 34 | setHeight(1).setSlim(false); 35 | } 36 | 37 | @Override 38 | public boolean generate(World world, Random rand, BlockPos pos) { 39 | 40 | int x = pos.getX(); 41 | int y = pos.getY(); 42 | int z = pos.getZ(); 43 | 44 | ++y; 45 | int size = radius.intValue(world, rand, pos); 46 | final int dist = size * size; 47 | int height = this.height.intValue(world, rand, pos); 48 | 49 | boolean r = false; 50 | for (int posX = x - size; posX <= x + size; ++posX) { 51 | int xDist = posX - x; 52 | xDist *= xDist; 53 | for (int posZ = z - size; posZ <= z + size; ++posZ) { 54 | int zSize = posZ - z; 55 | 56 | if (zSize * zSize + xDist <= dist) { 57 | for (int posY = y - height; slim ? posY < y + height : posY <= y + height; ++posY) { 58 | r |= generateBlock(world, posX, posY, posZ, genBlock, cluster); 59 | } 60 | } 61 | } 62 | } 63 | 64 | return r; 65 | } 66 | 67 | public WorldGenMinablePlate setSlim(boolean slim) { 68 | 69 | this.slim = slim; 70 | return this; 71 | } 72 | 73 | public WorldGenMinablePlate setHeight(int height) { 74 | 75 | this.height = new ConstantProvider(height); 76 | return this; 77 | } 78 | 79 | public WorldGenMinablePlate setHeight(INumberProvider height) { 80 | 81 | this.height = height; 82 | return this; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/ComparableItem.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import cofh.lib.util.helpers.ItemHelper; 4 | import net.minecraft.item.Item; 5 | import net.minecraft.item.ItemStack; 6 | 7 | /** 8 | * Wrapper for an Item/Metadata combination post 1.7. Quick and dirty, allows for Integer-based Hashes without collisions. 9 | * 10 | * @author King Lemming 11 | */ 12 | public class ComparableItem { 13 | 14 | public Item item; 15 | public int metadata; 16 | 17 | public static ComparableItem fromItemStack(ItemStack stack) { 18 | 19 | return new ComparableItem(stack); 20 | } 21 | 22 | protected ComparableItem() { 23 | 24 | item = null; 25 | metadata = 0; 26 | } 27 | 28 | public ComparableItem(Item item, int metadata) { 29 | 30 | this.item = item; 31 | this.metadata = metadata; 32 | } 33 | 34 | public ComparableItem(ItemStack stack) { 35 | 36 | if (stack != null) { 37 | this.item = stack.getItem(); 38 | this.metadata = ItemHelper.getItemDamage(stack); 39 | } else { 40 | this.item = null; 41 | this.metadata = 0; 42 | } 43 | } 44 | 45 | public ComparableItem(ComparableItem stack) { 46 | 47 | this.item = stack.item; 48 | this.metadata = stack.metadata; 49 | } 50 | 51 | public ComparableItem set(ItemStack stack) { 52 | 53 | if (stack != null) { 54 | this.item = stack.getItem(); 55 | this.metadata = ItemHelper.getItemDamage(stack); 56 | } else { 57 | this.item = null; 58 | this.metadata = 0; 59 | } 60 | return this; 61 | } 62 | 63 | // '0' is null. '-1' is an unmapped item (missing in this World) 64 | protected final int getId() { 65 | 66 | return Item.getIdFromItem(item); 67 | } 68 | 69 | public boolean isEqual(ComparableItem other) { 70 | 71 | if (other == null) { 72 | return false; 73 | } 74 | if (metadata == other.metadata) { 75 | if (item == other.item) { 76 | return true; 77 | } 78 | if (item != null && other.item != null) { 79 | return item.delegate.get() == other.item.delegate.get(); 80 | } 81 | } 82 | return false; 83 | } 84 | 85 | @Override 86 | public ComparableItem clone() { 87 | 88 | return new ComparableItem(this); 89 | } 90 | 91 | @Override 92 | public boolean equals(Object o) { 93 | 94 | if (!(o instanceof ComparableItem)) { 95 | return false; 96 | } 97 | return isEqual((ComparableItem) o); 98 | } 99 | 100 | @Override 101 | public int hashCode() { 102 | 103 | // TODO: this hash conflicts a lot 104 | return (metadata & 65535) | getId() << 16; 105 | } 106 | 107 | @Override 108 | public String toString() { 109 | 110 | String b = getClass().getName() + '@' + System.identityHashCode(this) + '{' + "m:" + metadata + ", i:" + (item == null ? null : item.getClass().getName()) + '@' + System.identityHashCode(item) + ", v:" + getId() + '}'; 111 | return b; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/container/CustomInventoryWrapper.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.container; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.IInventory; 5 | import net.minecraft.item.ItemStack; 6 | import net.minecraft.util.text.ITextComponent; 7 | import net.minecraft.util.text.TextComponentString; 8 | 9 | public class CustomInventoryWrapper implements IInventory { 10 | 11 | private final ItemStack[] inventory; 12 | 13 | public CustomInventoryWrapper(ICustomInventory customInv, int inventoryIndex) { 14 | 15 | inventory = customInv.getInventorySlots(0); 16 | } 17 | 18 | @Override 19 | public int getSizeInventory() { 20 | 21 | return inventory.length; 22 | } 23 | 24 | @Override 25 | public ItemStack getStackInSlot(int slot) { 26 | 27 | return inventory[slot]; 28 | } 29 | 30 | @Override 31 | public ItemStack decrStackSize(int slot, int amount) { 32 | 33 | if (inventory[slot] == null) { 34 | return null; 35 | } 36 | if (inventory[slot].stackSize <= amount) { 37 | amount = inventory[slot].stackSize; 38 | } 39 | ItemStack stack = inventory[slot].splitStack(amount); 40 | 41 | if (inventory[slot].stackSize <= 0) { 42 | inventory[slot] = null; 43 | } 44 | return stack; 45 | } 46 | 47 | @Override 48 | public ItemStack removeStackFromSlot(int slot) { 49 | 50 | if (inventory[slot] == null) { 51 | return null; 52 | } 53 | ItemStack stack = inventory[slot]; 54 | inventory[slot] = null; 55 | return stack; 56 | } 57 | 58 | @Override 59 | public void setInventorySlotContents(int slot, ItemStack stack) { 60 | 61 | inventory[slot] = stack; 62 | 63 | if (stack != null && stack.stackSize > getInventoryStackLimit()) { 64 | stack.stackSize = getInventoryStackLimit(); 65 | } 66 | } 67 | 68 | @Override 69 | public String getName() { 70 | 71 | return "container.crafting"; 72 | } 73 | 74 | @Override 75 | public boolean hasCustomName() { 76 | 77 | return false; 78 | } 79 | 80 | @Override 81 | public ITextComponent getDisplayName() { 82 | 83 | return new TextComponentString(""); 84 | } 85 | 86 | @Override 87 | public int getInventoryStackLimit() { 88 | 89 | return 64; 90 | } 91 | 92 | @Override 93 | public void markDirty() { 94 | 95 | } 96 | 97 | @Override 98 | public boolean isUseableByPlayer(EntityPlayer player) { 99 | 100 | return true; 101 | } 102 | 103 | @Override 104 | public void openInventory(EntityPlayer player) { 105 | 106 | } 107 | 108 | @Override 109 | public void closeInventory(EntityPlayer player) { 110 | 111 | } 112 | 113 | @Override 114 | public boolean isItemValidForSlot(int slot, ItemStack stack) { 115 | 116 | return true; 117 | } 118 | 119 | @Override 120 | public int getField(int id) { 121 | 122 | return 0; 123 | } 124 | 125 | @Override 126 | public void setField(int id, int value) { 127 | 128 | } 129 | 130 | @Override 131 | public int getFieldCount() { 132 | 133 | return 0; 134 | } 135 | 136 | @Override 137 | public void clear() { 138 | 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/WorldGenBoulder.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.World; 6 | import net.minecraft.world.gen.feature.WorldGenerator; 7 | 8 | import java.util.List; 9 | import java.util.Random; 10 | 11 | import static cofh.lib.world.WorldGenMinableCluster.canGenerateInBlock; 12 | import static cofh.lib.world.WorldGenMinableCluster.generateBlock; 13 | 14 | public class WorldGenBoulder extends WorldGenerator { 15 | 16 | private final List cluster; 17 | private final WeightedRandomBlock[] genBlock; 18 | private final int size; 19 | public int sizeVariance = 2; 20 | public int clusters = 3; 21 | public int clusterVariance = 0; 22 | public boolean hollow = false; 23 | public float hollowAmt = 0.1665f; 24 | public float hollowVar = 0; 25 | 26 | public WorldGenBoulder(List resource, int minSize, List block) { 27 | 28 | cluster = resource; 29 | size = minSize; 30 | genBlock = block.toArray(new WeightedRandomBlock[block.size()]); 31 | } 32 | 33 | @Override 34 | public boolean generate(World world, Random rand, BlockPos pos) { 35 | 36 | int xCenter = pos.getX(); 37 | int yCenter = pos.getY(); 38 | int zCenter = pos.getZ(); 39 | final int minSize = size, var = sizeVariance; 40 | boolean r = false; 41 | int i = clusterVariance > 0 ? clusters + rand.nextInt(clusterVariance + 1) : clusters; 42 | while (i-- > 0) { 43 | 44 | while (yCenter > minSize && world.isAirBlock(new BlockPos(xCenter, yCenter - 1, zCenter))) { 45 | --yCenter; 46 | } 47 | if (yCenter <= (minSize + var + 1)) { 48 | return false; 49 | } 50 | 51 | if (canGenerateInBlock(world, xCenter, yCenter - 1, zCenter, genBlock)) { 52 | 53 | int xWidth = minSize + (var > 1 ? rand.nextInt(var) : 0); 54 | int yWidth = minSize + (var > 1 ? rand.nextInt(var) : 0); 55 | int zWidth = minSize + (var > 1 ? rand.nextInt(var) : 0); 56 | float maxDist = (xWidth + yWidth + zWidth) * 0.333F + 0.5F; 57 | maxDist *= maxDist; 58 | float minDist = hollow ? (xWidth + yWidth + zWidth) * (hollowAmt * (1 - rand.nextFloat() * hollowVar)) : 0; 59 | minDist *= minDist; 60 | 61 | for (int x = -xWidth; x <= xWidth; ++x) { 62 | final int xDist = x * x; 63 | 64 | for (int z = -zWidth; z <= zWidth; ++z) { 65 | final int xzDist = xDist + z * z; 66 | 67 | for (int y = -yWidth; y <= yWidth; ++y) { 68 | final int dist = xzDist + y * y; 69 | 70 | if (dist <= maxDist) { 71 | if (dist >= minDist) { 72 | r |= generateBlock(world, xCenter + x, yCenter + y, zCenter + z, cluster); 73 | } else { 74 | r |= world.setBlockToAir(new BlockPos(xCenter + x, yCenter + y, zCenter + z)); 75 | } 76 | } 77 | } 78 | } 79 | } 80 | } 81 | 82 | xCenter += rand.nextInt(var + minSize * 2) - (minSize + var / 2); 83 | zCenter += rand.nextInt(var + minSize * 2) - (minSize + var / 2); 84 | yCenter += rand.nextInt((var + 1) * 3) - (var + 1); 85 | } 86 | 87 | return r; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/util/RayTracer.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.util; 2 | 3 | import net.minecraft.client.Minecraft; 4 | import net.minecraft.entity.player.EntityPlayer; 5 | import net.minecraft.entity.player.EntityPlayerMP; 6 | import net.minecraft.util.math.BlockPos; 7 | import net.minecraft.util.math.RayTraceResult; 8 | import net.minecraft.util.math.Vec3d; 9 | import net.minecraft.world.World; 10 | import net.minecraftforge.fml.relauncher.Side; 11 | import net.minecraftforge.fml.relauncher.SideOnly; 12 | 13 | public class RayTracer { 14 | 15 | public static RayTraceResult retrace(EntityPlayer player) { 16 | 17 | return retrace(player, getBlockReachDistance(player)); 18 | } 19 | 20 | public static RayTraceResult retrace(EntityPlayer player, double reach) { 21 | 22 | return retrace(player, reach, true); 23 | } 24 | 25 | public static RayTraceResult retrace(EntityPlayer player, boolean stopOnFluid) { 26 | 27 | Vec3d startVec = getStartVec(player); 28 | Vec3d endVec = getEndVec(player); 29 | return player.worldObj.rayTraceBlocks(startVec, endVec, stopOnFluid, false, true); 30 | } 31 | 32 | public static RayTraceResult retrace(EntityPlayer player, double reach, boolean stopOnFluids) { 33 | 34 | Vec3d startVec = getStartVec(player); 35 | Vec3d endVec = getEndVec(player, reach); 36 | return player.worldObj.rayTraceBlocks(startVec, endVec, stopOnFluids, false, true); 37 | } 38 | 39 | public static RayTraceResult retraceBlock(World world, EntityPlayer player, BlockPos pos) { 40 | 41 | Vec3d startVec = getStartVec(player); 42 | Vec3d endVec = getEndVec(player); 43 | return world.getBlockState(pos).collisionRayTrace(world, pos, startVec, endVec); 44 | } 45 | 46 | public static Vec3d getStartVec(EntityPlayer player) { 47 | 48 | return getCorrectedHeadVec(player); 49 | } 50 | 51 | public static Vec3d getEndVec(EntityPlayer player) { 52 | 53 | Vec3d headVec = getCorrectedHeadVec(player); 54 | Vec3d lookVec = player.getLook(1.0F); 55 | double reach = getBlockReachDistance(player); 56 | return headVec.addVector(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach); 57 | } 58 | 59 | public static Vec3d getEndVec(EntityPlayer player, double reach) { 60 | 61 | Vec3d headVec = getCorrectedHeadVec(player); 62 | Vec3d lookVec = player.getLook(1.0F); 63 | return headVec.addVector(lookVec.xCoord * reach, lookVec.yCoord * reach, lookVec.zCoord * reach); 64 | } 65 | 66 | public static Vec3d getCorrectedHeadVec(EntityPlayer player) { 67 | 68 | return new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ); 69 | } 70 | 71 | public static double getBlockReachDistance(EntityPlayer player) { 72 | 73 | return player.worldObj.isRemote ? getBlockReachDistanceClient() : player instanceof EntityPlayerMP ? getBlockReachDistanceServer((EntityPlayerMP) player) : 5D; 74 | } 75 | 76 | private static double getBlockReachDistanceServer(EntityPlayerMP player) { 77 | 78 | return player.interactionManager.getBlockReachDistance(); 79 | } 80 | 81 | @SideOnly (Side.CLIENT) 82 | private static double getBlockReachDistanceClient() { 83 | 84 | return Minecraft.getMinecraft().playerController.getBlockReachDistance(); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureGenCave.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.util.numbers.ConstantProvider; 4 | import cofh.lib.util.numbers.INumberProvider; 5 | import net.minecraft.block.state.IBlockState; 6 | import net.minecraft.util.math.BlockPos; 7 | import net.minecraft.world.World; 8 | import net.minecraft.world.gen.feature.WorldGenerator; 9 | 10 | import java.util.Random; 11 | 12 | public class FeatureGenCave extends FeatureBase { 13 | 14 | final WorldGenerator worldGen; 15 | final INumberProvider count; 16 | final boolean ceiling; 17 | 18 | public FeatureGenCave(String name, WorldGenerator worldGen, boolean ceiling, int count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 19 | 20 | this(name, worldGen, ceiling, new ConstantProvider(count), biomeRes, regen, dimRes); 21 | } 22 | 23 | public FeatureGenCave(String name, WorldGenerator worldGen, boolean ceiling, INumberProvider count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 24 | 25 | super(name, biomeRes, regen, dimRes); 26 | this.worldGen = worldGen; 27 | this.count = count; 28 | this.ceiling = ceiling; 29 | } 30 | 31 | @Override 32 | protected boolean generateFeature(Random random, int blockX, int blockZ, World world) { 33 | 34 | int averageSeaLevel = world.provider.getAverageGroundLevel() + 1; 35 | 36 | BlockPos pos = new BlockPos(blockX, 64, blockZ); 37 | 38 | final int count = this.count.intValue(world, random, pos); 39 | 40 | boolean generated = false; 41 | for (int i = 0; i < count; i++) { 42 | int x = blockX + random.nextInt(16); 43 | int z = blockZ + random.nextInt(16); 44 | if (!canGenerateInBiome(world, x, z, random)) { 45 | continue; 46 | } 47 | int seaLevel = averageSeaLevel; 48 | if (seaLevel < 20) { 49 | seaLevel = world.getHeightmapHeight(x, z); 50 | } 51 | 52 | int stopY = random.nextInt(1 + seaLevel / 2); 53 | int y = stopY; 54 | IBlockState state; 55 | do { 56 | state = world.getBlockState(new BlockPos(x, y, z)); 57 | } while (!state.getBlock().isAir(state, world, new BlockPos(x, y, z)) && ++y < seaLevel); 58 | 59 | if (y == seaLevel) { 60 | y = 0; 61 | do { 62 | state = world.getBlockState(new BlockPos(x, y, z)); 63 | } while (!state.getBlock().isAir(state, world, new BlockPos(x, y, z)) && ++y < stopY); 64 | if (y == stopY) { 65 | continue; 66 | } 67 | } 68 | 69 | if (ceiling) { 70 | if (y < stopY) { 71 | seaLevel = stopY + 1; 72 | } 73 | do { 74 | ++y; 75 | state = world.getBlockState(new BlockPos(x, y, z)); 76 | } while (y < seaLevel && state.getBlock().isAir(state, world, new BlockPos(x, y, z))); 77 | if (y == seaLevel) { 78 | continue; 79 | } 80 | } else if (state.getBlock().isAir(state, world, new BlockPos(x, y - 1, z))) { 81 | --y; 82 | do { 83 | state = world.getBlockState(new BlockPos(x, y, z)); 84 | } while (state.getBlock().isAir(state, world, new BlockPos(x, y, z)) && y-- > 0); 85 | if (y == -1) { 86 | continue; 87 | } 88 | } 89 | 90 | generated |= worldGen.generate(world, random, new BlockPos(x, y, z)); 91 | } 92 | return generated; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .gradle/ 7 | .project 8 | .metadata 9 | bin/ 10 | eclipse/ 11 | tmp/ 12 | *.tmp 13 | *.bak 14 | *.swp 15 | *~.nib 16 | local.properties 17 | .classpath 18 | .settings/ 19 | .loadpath 20 | crash-reports/ 21 | logs/ 22 | mods/ 23 | resourcepacks/ 24 | saves/ 25 | /options.txt 26 | 27 | # External tool builders 28 | .externalToolBuilders/ 29 | 30 | # Locally stored "Eclipse launch configurations" 31 | *.launch 32 | 33 | # CDT-specific 34 | .cproject 35 | 36 | # PDT-specific 37 | .buildpath 38 | 39 | 40 | ################# 41 | ## Visual Studio 42 | ################# 43 | 44 | ## Ignore Visual Studio temporary files, build results, and 45 | ## files generated by popular Visual Studio add-ons. 46 | 47 | # User-specific files 48 | *.suo 49 | *.user 50 | *.sln.docstates 51 | 52 | # Build results 53 | [Dd]ebug/ 54 | [Rr]elease/ 55 | *_i.c 56 | *_p.c 57 | *.ilk 58 | *.meta 59 | *.pch 60 | *.pdb 61 | *.pgc 62 | *.pgd 63 | *.rsp 64 | *.sbr 65 | *.tlb 66 | *.tli 67 | *.tlh 68 | *.tmp 69 | *.vspscc 70 | .builds 71 | *.dotCover 72 | 73 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 74 | #packages/ 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opensdf 81 | *.sdf 82 | 83 | # Visual Studio profiler 84 | *.psess 85 | *.vsp 86 | 87 | # ReSharper is a .NET coding add-in 88 | _ReSharper* 89 | 90 | # Installshield output folder 91 | [Ee]xpress 92 | 93 | # DocProject is a documentation generator add-in 94 | DocProject/buildhelp/ 95 | DocProject/Help/*.HxT 96 | DocProject/Help/*.HxC 97 | DocProject/Help/*.hhc 98 | DocProject/Help/*.hhk 99 | DocProject/Help/*.hhp 100 | DocProject/Help/Html2 101 | DocProject/Help/html 102 | 103 | # Click-Once directory 104 | publish 105 | 106 | # Others 107 | [Bb]in 108 | [Oo]bj 109 | sql 110 | TestResults 111 | *.Cache 112 | ClientBin 113 | stylecop.* 114 | ~$* 115 | *.dbmdl 116 | Generated_Code #added for RIA/Silverlight projects 117 | 118 | # Backup & report files from converting an old project file to a newer 119 | # Visual Studio version. Backup files are not needed, because we have git ;-) 120 | _UpgradeReport_Files/ 121 | Backup*/ 122 | UpgradeLog*.XML 123 | 124 | 125 | 126 | ############ 127 | ## Windows 128 | ############ 129 | 130 | # Windows image file caches 131 | Thumbs.db 132 | 133 | # Folder config file 134 | Desktop.ini 135 | 136 | 137 | ############# 138 | ## Python 139 | ############# 140 | 141 | *.py[co] 142 | 143 | # Packages 144 | *.egg 145 | *.egg-info 146 | dist 147 | build 148 | eggs 149 | parts 150 | bin 151 | var 152 | sdist 153 | develop-eggs 154 | .installed.cfg 155 | 156 | # Installer logs 157 | pip-log.txt 158 | 159 | # Unit test / coverage reports 160 | .coverage 161 | .tox 162 | 163 | #Translations 164 | *.mo 165 | 166 | #Mr Developer 167 | .mr.developer.cfg 168 | 169 | # Mac crap 170 | .DS_Store 171 | 172 | ########### 173 | 174 | downloads 175 | screenshots 176 | techne 177 | .idea/ 178 | 179 | ############# 180 | ## denoflions 181 | ############# 182 | 183 | MFR-Forestry 184 | nbproject 185 | .idea/ 186 | *.iml 187 | *.eml 188 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/WorldGenSpike.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.util.math.MathHelper; 6 | import net.minecraft.world.World; 7 | import net.minecraft.world.gen.feature.WorldGenerator; 8 | 9 | import java.util.List; 10 | import java.util.Random; 11 | 12 | import static cofh.lib.world.WorldGenMinableCluster.canGenerateInBlock; 13 | import static cofh.lib.world.WorldGenMinableCluster.generateBlock; 14 | 15 | public class WorldGenSpike extends WorldGenerator { 16 | 17 | private final List cluster; 18 | private final WeightedRandomBlock[] genBlock; 19 | public boolean largeSpikes = true; 20 | public int largeSpikeChance = 60; 21 | public int minHeight = 7; 22 | public int heightVariance = 4; 23 | public int sizeVariance = 2; 24 | public int positionVariance = 3; 25 | public int minLargeSpikeHeightGain = 10; 26 | public int largeSpikeHeightVariance = 30; 27 | public int largeSpikeFillerSize = 1; 28 | 29 | public WorldGenSpike(List resource, List block) { 30 | 31 | cluster = resource; 32 | genBlock = block.toArray(new WeightedRandomBlock[block.size()]); 33 | } 34 | 35 | @Override 36 | public boolean generate(World world, Random rand, BlockPos pos) { 37 | 38 | int xStart = pos.getX(); 39 | int yStart = pos.getY(); 40 | int zStart = pos.getZ(); 41 | 42 | while (world.isAirBlock(new BlockPos(xStart, yStart, zStart)) && yStart > 2) { 43 | --yStart; 44 | } 45 | 46 | if (!canGenerateInBlock(world, xStart, yStart, zStart, genBlock)) { 47 | return false; 48 | } 49 | 50 | int height = rand.nextInt(heightVariance) + minHeight, originalHeight = height; 51 | int size = height / (minHeight / 2) + rand.nextInt(sizeVariance); 52 | if (size > 1 && positionVariance > 0) { 53 | yStart += rand.nextInt(positionVariance + 1) - 1; 54 | } 55 | 56 | if (largeSpikes && size > 1 && (largeSpikeChance <= 0 || rand.nextInt(largeSpikeChance) == 0)) { 57 | height += minLargeSpikeHeightGain + rand.nextInt(largeSpikeHeightVariance); 58 | } 59 | 60 | int offsetHeight = height - originalHeight; 61 | 62 | for (int y = 0; y < height; ++y) { 63 | float layerSize; 64 | if (y >= offsetHeight) { 65 | layerSize = (1.0F - (float) (y - offsetHeight) / (float) originalHeight) * size; 66 | } else { 67 | layerSize = largeSpikeFillerSize; 68 | } 69 | int width = MathHelper.ceiling_float_int(layerSize); 70 | 71 | for (int x = -width; x <= width; ++x) { 72 | float xDist = MathHelper.abs_int(x) - 0.25F; 73 | 74 | for (int z = -width; z <= width; ++z) { 75 | float zDist = MathHelper.abs_int(z) - 0.25F; 76 | 77 | if ((x == 0 && z == 0 || xDist * xDist + zDist * zDist <= layerSize * layerSize) && (x != -width && x != width && z != -width && z != width || rand.nextFloat() <= 0.75F)) { 78 | 79 | generateBlock(world, xStart + x, yStart + y, zStart + z, genBlock, cluster); 80 | 81 | if (y != 0 && width > 1) { 82 | generateBlock(world, xStart + x, yStart - y + offsetHeight, zStart + z, genBlock, cluster); 83 | } 84 | } 85 | } 86 | } 87 | } 88 | 89 | return true; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/ItemEnergyContainer.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.item.Item; 4 | import net.minecraft.item.ItemStack; 5 | import net.minecraft.nbt.NBTTagCompound; 6 | 7 | /** 8 | * Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own. 9 | * 10 | * @author King Lemming 11 | */ 12 | public class ItemEnergyContainer extends Item implements IEnergyContainerItem { 13 | 14 | protected int capacity; 15 | protected int maxReceive; 16 | protected int maxExtract; 17 | 18 | public ItemEnergyContainer() { 19 | 20 | } 21 | 22 | public ItemEnergyContainer(int capacity) { 23 | 24 | this(capacity, capacity, capacity); 25 | } 26 | 27 | public ItemEnergyContainer(int capacity, int maxTransfer) { 28 | 29 | this(capacity, maxTransfer, maxTransfer); 30 | } 31 | 32 | public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) { 33 | 34 | this.capacity = capacity; 35 | this.maxReceive = maxReceive; 36 | this.maxExtract = maxExtract; 37 | } 38 | 39 | public ItemEnergyContainer setCapacity(int capacity) { 40 | 41 | this.capacity = capacity; 42 | return this; 43 | } 44 | 45 | public ItemEnergyContainer setMaxTransfer(int maxTransfer) { 46 | 47 | setMaxReceive(maxTransfer); 48 | setMaxExtract(maxTransfer); 49 | return this; 50 | } 51 | 52 | public ItemEnergyContainer setMaxReceive(int maxReceive) { 53 | 54 | this.maxReceive = maxReceive; 55 | return this; 56 | } 57 | 58 | public ItemEnergyContainer setMaxExtract(int maxExtract) { 59 | 60 | this.maxExtract = maxExtract; 61 | return this; 62 | } 63 | 64 | /* IEnergyContainerItem */ 65 | @Override 66 | public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { 67 | 68 | if (!container.hasTagCompound()) { 69 | container.setTagCompound(new NBTTagCompound()); 70 | } 71 | int energy = container.getTagCompound().getInteger("Energy"); 72 | int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); 73 | 74 | if (!simulate) { 75 | energy += energyReceived; 76 | container.getTagCompound().setInteger("Energy", energy); 77 | } 78 | return energyReceived; 79 | } 80 | 81 | @Override 82 | public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) { 83 | 84 | if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) { 85 | return 0; 86 | } 87 | int energy = container.getTagCompound().getInteger("Energy"); 88 | int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); 89 | 90 | if (!simulate) { 91 | energy -= energyExtracted; 92 | container.getTagCompound().setInteger("Energy", energy); 93 | } 94 | return energyExtracted; 95 | } 96 | 97 | @Override 98 | public int getEnergyStored(ItemStack container) { 99 | 100 | if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) { 101 | return 0; 102 | } 103 | return container.getTagCompound().getInteger("Energy"); 104 | } 105 | 106 | @Override 107 | public int getMaxEnergyStored(ItemStack container) { 108 | 109 | return capacity; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureGenLargeVein.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.util.numbers.ConstantProvider; 4 | import cofh.lib.util.numbers.INumberProvider; 5 | import net.minecraft.util.math.BlockPos; 6 | import net.minecraft.world.World; 7 | import net.minecraft.world.gen.feature.WorldGenerator; 8 | 9 | import java.util.Random; 10 | 11 | public class FeatureGenLargeVein extends FeatureBase { 12 | 13 | final WorldGenerator worldGen; 14 | final INumberProvider count; 15 | final INumberProvider minY; 16 | private INumberProvider veinHeight, veinDiameter; 17 | private INumberProvider verticalDensity; 18 | private INumberProvider horizontalDensity; 19 | 20 | public FeatureGenLargeVein(String name, WorldGenerator worldGen, int count, int minY, GenRestriction biomeRes, boolean regen, GenRestriction dimRes, int height, int diameter, int vDensity, int hDensity) { 21 | 22 | this(name, worldGen, new ConstantProvider(count), new ConstantProvider(minY), biomeRes, regen, dimRes, new ConstantProvider(height), new ConstantProvider(diameter), new ConstantProvider(vDensity), new ConstantProvider(hDensity)); 23 | } 24 | 25 | public FeatureGenLargeVein(String name, WorldGenerator worldGen, INumberProvider count, INumberProvider minY, GenRestriction biomeRes, boolean regen, GenRestriction dimRes, INumberProvider height, INumberProvider diameter, INumberProvider vDensity, INumberProvider hDensity) { 26 | 27 | super(name, biomeRes, regen, dimRes); 28 | this.worldGen = worldGen; 29 | this.count = count; 30 | this.minY = minY; 31 | this.veinHeight = height; 32 | this.veinDiameter = diameter; 33 | this.verticalDensity = vDensity; 34 | this.horizontalDensity = hDensity; 35 | } 36 | 37 | public int getDensity(Random rand, int oreDistance, float oreDensity) { 38 | 39 | oreDensity = oreDensity * 0.01f * (oreDistance >> 1); 40 | int i = (int) oreDensity; 41 | if (i == 0) { 42 | ++i; 43 | } 44 | int rnd = oreDistance / i; 45 | int r = 0; 46 | for (; i > 0; --i) { 47 | r += rand.nextInt(rnd); 48 | } 49 | return r; 50 | } 51 | 52 | @Override 53 | public boolean generateFeature(Random random, int blockX, int blockZ, World world) { 54 | 55 | BlockPos pos = new BlockPos(blockX, 64, blockZ); 56 | 57 | final int count = this.count.intValue(world, random, pos); 58 | final int blockY = minY.intValue(world, random, pos); 59 | final int veinDiameter = this.veinDiameter.intValue(world, random, pos); 60 | final int horizontalDensity = this.horizontalDensity.intValue(world, random, pos); 61 | final int veinHeight = this.veinHeight.intValue(world, random, pos); 62 | final int verticalDensity = this.verticalDensity.intValue(world, random, pos); 63 | 64 | Random dRand = new Random(world.getSeed()); 65 | long l = (dRand.nextLong() / 2L) * 2L + 1L; 66 | long l1 = (dRand.nextLong() / 2L) * 2L + 1L; 67 | dRand.setSeed((blockX >> 4) * l + (blockZ >> 4) * l1 ^ world.getSeed()); 68 | 69 | boolean generated = false; 70 | for (int i = count; i-- > 0; ) { 71 | 72 | int x = blockX + getDensity(dRand, veinDiameter, horizontalDensity); 73 | int y = blockY + getDensity(dRand, veinHeight, verticalDensity); 74 | int z = blockZ + getDensity(dRand, veinDiameter, horizontalDensity); 75 | if (!canGenerateInBiome(world, x, z, random)) { 76 | continue; 77 | } 78 | 79 | generated |= worldGen.generate(world, random, new BlockPos(x, y, z)); 80 | } 81 | return generated; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/GuiColor.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui; 2 | 3 | public class GuiColor extends Number { 4 | 5 | private static final long serialVersionUID = 7024827242888861187L; 6 | private final int _color; 7 | 8 | public GuiColor(int argb) { 9 | 10 | _color = argb; 11 | } 12 | 13 | public GuiColor(int rgba, Void dummy) { 14 | 15 | this(rgba >>> 24, rgba >> 16, rgba >> 8, rgba); 16 | } 17 | 18 | public GuiColor(byte alpha, int argb) { 19 | 20 | this(argb >> 16, argb >> 8, argb, alpha); 21 | } 22 | 23 | public GuiColor(int rgba, byte alpha) { 24 | 25 | this(rgba >>> 24, rgba >> 16, rgba >> 8, alpha); 26 | } 27 | 28 | public GuiColor(int r, int g, int b) { 29 | 30 | this(r, g, b, 255); 31 | } 32 | 33 | public GuiColor(int r, int g, int b, int a) { 34 | 35 | _color = (b & 0xFF) | (g & 0xFF) << 8 | (r & 0xFF) << 16 | (a & 0xFF) << 24; 36 | } 37 | 38 | public int getColor() { 39 | 40 | return _color; 41 | } 42 | 43 | public int getIntR() { 44 | 45 | return (_color >> 16) & 0xFF; 46 | } 47 | 48 | public int getIntG() { 49 | 50 | return (_color >> 8) & 0xFF; 51 | } 52 | 53 | public int getIntB() { 54 | 55 | return _color & 0xFF; 56 | } 57 | 58 | public int getIntA() { 59 | 60 | return (_color >> 24) & 0xFF; 61 | } 62 | 63 | public float getFloatR() { 64 | 65 | return getIntR() / 255f; 66 | } 67 | 68 | public float getFloatG() { 69 | 70 | return getIntG() / 255f; 71 | } 72 | 73 | public float getFloatB() { 74 | 75 | return getIntB() / 255f; 76 | } 77 | 78 | public float getFloatA() { 79 | 80 | return getIntA() / 255f; 81 | } 82 | 83 | // ///////////////////////////////////////////////////////// Math Methods //////////////////////////////////////////// 84 | public GuiColor multiply(float amount) { 85 | 86 | return multiply(amount, amount, amount, amount); 87 | } 88 | 89 | public GuiColor multiply(float rgb, float a) { 90 | 91 | return multiply(rgb, rgb, rgb, a); 92 | } 93 | 94 | public GuiColor multiply(float r, float g, float b) { 95 | 96 | return multiply(r, g, b, 1); 97 | } 98 | 99 | public GuiColor multiply(float r, float g, float b, float a) { 100 | 101 | return new GuiColor(Math.min((int) (getIntR() * r), 255), Math.min((int) (getIntG() * g), 255), Math.min((int) (getIntB() * b), 255)); 102 | } 103 | 104 | public GuiColor add(int amount) { 105 | 106 | return new GuiColor(Math.max(Math.min(getIntR() + amount, 255), 0), Math.max(Math.min(getIntG() + amount, 255), 0), Math.max(Math.min(getIntB() + amount, 255), 0), Math.max(Math.min(getIntA() + amount, 255), 0)); 107 | } 108 | 109 | public GuiColor add(GuiColor color) { 110 | 111 | return new GuiColor(Math.max(Math.min(getIntR() + color.getIntR(), 255), 0), Math.max(Math.min(getIntG() + color.getIntG(), 255), 0), Math.max(Math.min(getIntB() + color.getIntB(), 255), 0), Math.max(Math.min(getIntA() + color.getIntA(), 255), 0)); 112 | } 113 | 114 | // /////////////////////////////////////////////////////////////////////////////////////////////// 115 | 116 | @Override 117 | public int intValue() { 118 | 119 | return getColor(); 120 | } 121 | 122 | @Override 123 | public long longValue() { 124 | 125 | return getColor(); 126 | } 127 | 128 | @Override 129 | public float floatValue() { 130 | 131 | return getColor(); 132 | } 133 | 134 | @Override 135 | public double doubleValue() { 136 | 137 | return getColor(); 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/ComparableItemStack.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import cofh.lib.util.ComparableItem; 4 | import cofh.lib.util.helpers.ItemHelper; 5 | import net.minecraft.item.Item; 6 | import net.minecraft.item.ItemStack; 7 | 8 | /** 9 | * This class allows for OreDictionary-compatible ItemStack comparisons and Integer-based Hashes without collisions. 10 | * 11 | * The intended purpose of this is for things such as Recipe Handlers or HashMaps of ItemStacks. 12 | * 13 | * @author King Lemming 14 | */ 15 | public class ComparableItemStack extends ComparableItem { 16 | 17 | public static ComparableItemStack fromItemStack(ItemStack stack) { 18 | 19 | return new ComparableItemStack(stack); 20 | } 21 | 22 | public int stackSize = -1; 23 | public int oreID = -1; 24 | 25 | protected static ItemStack getOre(String oreName) { 26 | 27 | if (ItemHelper.oreNameExists(oreName)) { 28 | return ItemHelper.oreProxy.getOre(oreName); 29 | } 30 | return null; 31 | } 32 | 33 | public ComparableItemStack(String oreName) { 34 | 35 | this(getOre(oreName)); 36 | } 37 | 38 | public ComparableItemStack(ItemStack stack) { 39 | 40 | super(stack); 41 | if (stack != null) { 42 | stackSize = stack.stackSize; 43 | oreID = ItemHelper.oreProxy.getOreID(stack); 44 | } 45 | } 46 | 47 | public ComparableItemStack(Item item, int damage, int stackSize) { 48 | 49 | super(item, damage); 50 | this.stackSize = stackSize; 51 | this.oreID = ItemHelper.oreProxy.getOreID(this.toItemStack()); 52 | } 53 | 54 | public ComparableItemStack(ComparableItemStack stack) { 55 | 56 | super(stack.item, stack.metadata); 57 | this.stackSize = stack.stackSize; 58 | this.oreID = stack.oreID; 59 | } 60 | 61 | @Override 62 | public ComparableItemStack set(ItemStack stack) { 63 | 64 | if (stack != null) { 65 | item = stack.getItem(); 66 | metadata = ItemHelper.getItemDamage(stack); 67 | stackSize = stack.stackSize; 68 | oreID = ItemHelper.oreProxy.getOreID(stack); 69 | } else { 70 | item = null; 71 | metadata = -1; 72 | stackSize = -1; 73 | oreID = -1; 74 | } 75 | return this; 76 | } 77 | 78 | public ComparableItemStack set(ComparableItemStack stack) { 79 | 80 | if (stack != null) { 81 | item = stack.item; 82 | metadata = stack.metadata; 83 | stackSize = stack.stackSize; 84 | oreID = stack.oreID; 85 | } else { 86 | item = null; 87 | metadata = -1; 88 | stackSize = -1; 89 | oreID = -1; 90 | } 91 | return this; 92 | } 93 | 94 | public boolean isItemEqual(ComparableItemStack other) { 95 | 96 | return other != null && (oreID != -1 && oreID == other.oreID || isEqual(other)); 97 | } 98 | 99 | public boolean isStackEqual(ComparableItemStack other) { 100 | 101 | return isItemEqual(other) && stackSize == other.stackSize; 102 | } 103 | 104 | public boolean isStackValid() { 105 | 106 | return item != null; 107 | } 108 | 109 | public ItemStack toItemStack() { 110 | 111 | return item != null ? new ItemStack(item, stackSize, metadata) : null; 112 | } 113 | 114 | @Override 115 | public ComparableItemStack clone() { 116 | 117 | return new ComparableItemStack(this); 118 | } 119 | 120 | @Override 121 | public int hashCode() { 122 | 123 | return oreID != -1 ? oreID : super.hashCode(); 124 | } 125 | 126 | @Override 127 | public boolean equals(Object o) { 128 | 129 | return o instanceof ComparableItemStack && isItemEqual((ComparableItemStack) o); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/WorldGenStalagmite.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import net.minecraft.util.math.BlockPos; 5 | import net.minecraft.world.World; 6 | import net.minecraft.world.gen.feature.WorldGenerator; 7 | 8 | import java.util.List; 9 | import java.util.Random; 10 | 11 | import static cofh.lib.world.WorldGenMinableCluster.canGenerateInBlock; 12 | import static cofh.lib.world.WorldGenMinableCluster.generateBlock; 13 | 14 | public class WorldGenStalagmite extends WorldGenerator { 15 | 16 | protected final List cluster; 17 | protected final WeightedRandomBlock[] baseBlock; 18 | protected final WeightedRandomBlock[] genBlock; 19 | public int minHeight = 7; 20 | public int heightVariance = 4; 21 | public int sizeVariance = 2; 22 | public int heightMod = 5; 23 | public int genSize = 0; 24 | public boolean smooth = false; 25 | public boolean fat = true; 26 | public boolean altSinc = false; 27 | 28 | public WorldGenStalagmite(List resource, List block, List gblock) { 29 | 30 | cluster = resource; 31 | baseBlock = block.toArray(new WeightedRandomBlock[block.size()]); 32 | genBlock = gblock.toArray(new WeightedRandomBlock[gblock.size()]); 33 | } 34 | 35 | protected int getHeight(int x, int z, int size, Random rand, int height) { 36 | 37 | if (smooth) { 38 | if ((x * x + z * z) * 4 >= size * size * 5) { 39 | return 0; 40 | } 41 | 42 | final double lim = (altSinc ? 600f : (fat ? 1f : .5f) * 400f) / size; 43 | final double pi = Math.PI; 44 | double r; 45 | r = Math.sqrt((r = ((x * lim) / pi)) * r + (r = ((z * lim) / pi)) * r) * pi / 180; 46 | if (altSinc && r < 1) { 47 | r = Math.sqrt((size * 2 * lim) / pi) * pi / 180; 48 | } 49 | if (r == 0) { 50 | return height; 51 | } 52 | if (!altSinc) { 53 | return (int) Math.round(height * (fat ? Math.sin(r) / r : Math.sin(r = r * pi) / r)); 54 | } 55 | double sinc = (Math.sin(r) / r); 56 | return (int) Math.round(height * (sinc * 2 + (Math.sin(r = r * (pi * 4)) / r)) / 2 + rand.nextGaussian() * .75); 57 | } else { 58 | int absx = x < 0 ? -x : x, absz = (z < 0 ? -z : z); 59 | int dist = fat ? (absx < absz ? absz + absx / 2 : absx + absz / 2) : absx + absz; 60 | if (dist == 0) { 61 | return height; 62 | } 63 | int v = 1 + height / dist; 64 | return v > 1 ? rand.nextInt(v) : 0; 65 | } 66 | } 67 | 68 | @Override 69 | public boolean generate(World world, Random rand, BlockPos pos) { 70 | 71 | int xStart = pos.getX(); 72 | int yStart = pos.getY(); 73 | int zStart = pos.getZ(); 74 | while (world.isAirBlock(new BlockPos(xStart, yStart, zStart)) && yStart > 0) { 75 | --yStart; 76 | } 77 | 78 | if (!canGenerateInBlock(world, xStart, yStart++, zStart, baseBlock)) { 79 | return false; 80 | } 81 | 82 | int maxHeight = (heightVariance > 0 ? rand.nextInt(heightVariance) : 0) + minHeight; 83 | 84 | int size = (genSize > 0 ? genSize : maxHeight / heightMod); 85 | if (sizeVariance > 0) { 86 | size += rand.nextInt(sizeVariance); 87 | } 88 | boolean r = false; 89 | for (int x = -size; x <= size; ++x) { 90 | for (int z = -size; z <= size; ++z) { 91 | if (!canGenerateInBlock(world, xStart + x, yStart - 1, zStart + z, baseBlock)) { 92 | continue; 93 | } 94 | int height = getHeight(x, z, size, rand, maxHeight); 95 | for (int y = 0; y < height; ++y) { 96 | r |= generateBlock(world, xStart + x, yStart + y, zStart + z, genBlock, cluster); 97 | } 98 | } 99 | } 100 | return r; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/inventory/InventoryCraftingCustom.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.inventory; 2 | 3 | import net.minecraft.entity.player.EntityPlayer; 4 | import net.minecraft.inventory.Container; 5 | import net.minecraft.inventory.IInventory; 6 | import net.minecraft.inventory.InventoryCrafting; 7 | import net.minecraft.item.ItemStack; 8 | 9 | public class InventoryCraftingCustom extends InventoryCrafting { 10 | 11 | public IInventory masterInv; 12 | public int invOffset = 0; 13 | public int invSize = 0; 14 | /** 15 | * the width of the crafting inventory 16 | */ 17 | public final int inventoryWidth; 18 | 19 | /** 20 | * Class containing the callbacks for the events onGUIClosed and onCraftMatrixChanged. 21 | */ 22 | public final Container eventHandler; 23 | 24 | public InventoryCraftingCustom(Container container, int rows, int columns, IInventory master, int startingInventoryIndex) { 25 | 26 | super(container, rows, columns); 27 | invSize = rows * columns; 28 | this.eventHandler = container; 29 | this.inventoryWidth = rows; 30 | invOffset = startingInventoryIndex; 31 | masterInv = master; 32 | } 33 | 34 | @Override 35 | public int getSizeInventory() { 36 | 37 | return invSize; 38 | } 39 | 40 | @Override 41 | public ItemStack getStackInSlot(int slot) { 42 | 43 | return slot >= this.getSizeInventory() ? null : masterInv.getStackInSlot(invOffset + slot); 44 | } 45 | 46 | @Override 47 | public ItemStack getStackInRowAndColumn(int row, int column) { 48 | 49 | if (row >= 0 && row < this.inventoryWidth) { 50 | int k = row + column * this.inventoryWidth; 51 | return this.getStackInSlot(k); 52 | } 53 | return null; 54 | } 55 | 56 | @Override 57 | public ItemStack removeStackFromSlot(int slot) { 58 | 59 | if (masterInv.getStackInSlot(invOffset + slot) != null) { 60 | ItemStack stack = masterInv.getStackInSlot(invOffset + slot); 61 | masterInv.setInventorySlotContents(invOffset + slot, null); 62 | return stack; 63 | } 64 | return null; 65 | } 66 | 67 | @Override 68 | public ItemStack decrStackSize(int slot, int amount) { 69 | 70 | if (masterInv.getStackInSlot(invOffset + slot) != null) { 71 | ItemStack stack; 72 | 73 | if (masterInv.getStackInSlot(invOffset + slot).stackSize <= amount) { 74 | stack = masterInv.getStackInSlot(invOffset + slot); 75 | masterInv.setInventorySlotContents(invOffset + slot, null); 76 | this.eventHandler.onCraftMatrixChanged(this); 77 | return stack; 78 | } else { 79 | stack = masterInv.getStackInSlot(invOffset + slot).splitStack(amount); 80 | 81 | if (masterInv.getStackInSlot(invOffset + slot).stackSize <= 0) { 82 | masterInv.setInventorySlotContents(invOffset + slot, null); 83 | } 84 | this.eventHandler.onCraftMatrixChanged(this); 85 | return stack; 86 | } 87 | } 88 | return null; 89 | } 90 | 91 | @Override 92 | public void setInventorySlotContents(int slot, ItemStack stack) { 93 | 94 | masterInv.setInventorySlotContents(invOffset + slot, stack); 95 | this.eventHandler.onCraftMatrixChanged(this); 96 | } 97 | 98 | @Override 99 | public int getInventoryStackLimit() { 100 | 101 | return 64; 102 | } 103 | 104 | @Override 105 | public void markDirty() { 106 | 107 | } 108 | 109 | @Override 110 | public boolean isUseableByPlayer(EntityPlayer player) { 111 | 112 | return true; 113 | } 114 | 115 | @Override 116 | public void openInventory(EntityPlayer player) { 117 | 118 | } 119 | 120 | @Override 121 | public void closeInventory(EntityPlayer player) { 122 | 123 | } 124 | 125 | @Override 126 | public boolean isItemValidForSlot(int slot, ItemStack stack) { 127 | 128 | return true; 129 | } 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/gui/element/ElementFluidTank.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.gui.element; 2 | 3 | import cofh.lib.gui.GuiBase; 4 | import cofh.lib.gui.GuiProps; 5 | import cofh.lib.util.helpers.MathHelper; 6 | import cofh.lib.util.helpers.RenderHelper; 7 | import cofh.lib.util.helpers.StringHelper; 8 | import net.minecraft.util.ResourceLocation; 9 | import net.minecraftforge.fluids.IFluidTank; 10 | 11 | import java.util.List; 12 | 13 | public class ElementFluidTank extends ElementBase { 14 | 15 | public static final ResourceLocation DEFAULT_TEXTURE = new ResourceLocation(GuiProps.PATH_ELEMENTS + "fluid_tank.png"); 16 | public static final ResourceLocation SHORT_TEXTURE = new ResourceLocation(GuiProps.PATH_ELEMENTS + "fluid_tank_short.png"); 17 | public static final ResourceLocation THIN_TEXTURE = new ResourceLocation(GuiProps.PATH_ELEMENTS + "fluid_tank_thin.png"); 18 | 19 | protected IFluidTank tank; 20 | protected int gaugeType; 21 | protected boolean drawTank; 22 | 23 | // If this is enabled, 1 pixel of fluid will always show in the tank as long as fluid is present. 24 | protected boolean alwaysShowMinimum = false; 25 | 26 | public ElementFluidTank(GuiBase gui, int posX, int posY, IFluidTank tank) { 27 | 28 | this(gui, posX, posY, tank, DEFAULT_TEXTURE); 29 | } 30 | 31 | public ElementFluidTank(GuiBase gui, int posX, int posY, IFluidTank tank, ResourceLocation texture) { 32 | 33 | super(gui, posX, posY); 34 | this.tank = tank; 35 | 36 | this.texture = texture; 37 | this.texW = 64; 38 | this.texH = 64; 39 | 40 | this.sizeX = 16; 41 | this.sizeY = 60; 42 | } 43 | 44 | public ElementFluidTank setGauge(int gaugeType) { 45 | 46 | this.gaugeType = gaugeType; 47 | return this; 48 | } 49 | 50 | public ElementFluidTank setDefault() { 51 | 52 | this.texture = DEFAULT_TEXTURE; 53 | this.sizeX = 16; 54 | this.sizeY = 60; 55 | return this; 56 | } 57 | 58 | public ElementFluidTank setThin() { 59 | 60 | this.texture = THIN_TEXTURE; 61 | this.sizeX = 7; 62 | return this; 63 | } 64 | 65 | public ElementFluidTank setShort() { 66 | 67 | this.texture = SHORT_TEXTURE; 68 | this.sizeY = 30; 69 | return this; 70 | } 71 | 72 | public ElementFluidTank drawTank(boolean drawTank) { 73 | 74 | this.drawTank = drawTank; 75 | return this; 76 | } 77 | 78 | public ElementFluidTank setAlwaysShow(boolean show) { 79 | 80 | alwaysShowMinimum = show; 81 | return this; 82 | } 83 | 84 | @Override 85 | public void drawBackground(int mouseX, int mouseY, float gameTicks) { 86 | 87 | if (drawTank) { 88 | RenderHelper.bindTexture(texture); 89 | drawTexturedModalRect(posX - 1, posY - 1, 0, 0, sizeX + 2, sizeY + 2); 90 | } 91 | int amount = getScaled(); 92 | gui.drawFluid(posX, posY + sizeY - amount, tank.getFluid(), sizeX, amount); 93 | RenderHelper.bindTexture(texture); 94 | drawTexturedModalRect(posX, posY, 32 + gaugeType * 16, 1, sizeX, sizeY); 95 | } 96 | 97 | @Override 98 | public void drawForeground(int mouseX, int mouseY) { 99 | 100 | } 101 | 102 | @Override 103 | public void addTooltip(List list) { 104 | 105 | if (tank.getFluid() != null && tank.getFluidAmount() > 0) { 106 | list.add(StringHelper.getFluidName(tank.getFluid())); 107 | } 108 | if (tank.getCapacity() < 0) { 109 | list.add("Infinite Fluid"); 110 | } else { 111 | list.add(StringHelper.formatNumber(tank.getFluidAmount()) + " / " + StringHelper.formatNumber(tank.getCapacity()) + " mB"); 112 | } 113 | } 114 | 115 | protected int getScaled() { 116 | 117 | if (tank.getCapacity() < 0) { 118 | return sizeY; 119 | } 120 | long fraction = (long) tank.getFluidAmount() * sizeY / tank.getCapacity(); 121 | 122 | return alwaysShowMinimum && tank.getFluidAmount() > 0 ? Math.max(1, MathHelper.ceil(fraction)) : MathHelper.ceil(fraction); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/EnergyStorage.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.nbt.NBTTagCompound; 4 | 5 | /** 6 | * Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own. 7 | * 8 | * @author King Lemming 9 | */ 10 | public class EnergyStorage implements IEnergyStorage { 11 | 12 | protected int energy; 13 | protected int capacity; 14 | protected int maxReceive; 15 | protected int maxExtract; 16 | 17 | public EnergyStorage(int capacity) { 18 | 19 | this(capacity, capacity, capacity); 20 | } 21 | 22 | public EnergyStorage(int capacity, int maxTransfer) { 23 | 24 | this(capacity, maxTransfer, maxTransfer); 25 | } 26 | 27 | public EnergyStorage(int capacity, int maxReceive, int maxExtract) { 28 | 29 | this.capacity = capacity; 30 | this.maxReceive = maxReceive; 31 | this.maxExtract = maxExtract; 32 | } 33 | 34 | public EnergyStorage readFromNBT(NBTTagCompound nbt) { 35 | 36 | this.energy = nbt.getInteger("Energy"); 37 | 38 | if (energy > capacity) { 39 | energy = capacity; 40 | } 41 | return this; 42 | } 43 | 44 | public NBTTagCompound writeToNBT(NBTTagCompound nbt) { 45 | 46 | if (energy < 0) { 47 | energy = 0; 48 | } 49 | nbt.setInteger("Energy", energy); 50 | return nbt; 51 | } 52 | 53 | public EnergyStorage setCapacity(int capacity) { 54 | 55 | this.capacity = capacity; 56 | 57 | if (energy > capacity) { 58 | energy = capacity; 59 | } 60 | return this; 61 | } 62 | 63 | public EnergyStorage setMaxTransfer(int maxTransfer) { 64 | 65 | setMaxReceive(maxTransfer); 66 | setMaxExtract(maxTransfer); 67 | return this; 68 | } 69 | 70 | public EnergyStorage setMaxReceive(int maxReceive) { 71 | 72 | this.maxReceive = maxReceive; 73 | return this; 74 | } 75 | 76 | public EnergyStorage setMaxExtract(int maxExtract) { 77 | 78 | this.maxExtract = maxExtract; 79 | return this; 80 | } 81 | 82 | public int getMaxReceive() { 83 | 84 | return maxReceive; 85 | } 86 | 87 | public int getMaxExtract() { 88 | 89 | return maxExtract; 90 | } 91 | 92 | /** 93 | * This function is included to allow for server to client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are guaranteed to have it. 94 | */ 95 | public void setEnergyStored(int energy) { 96 | 97 | this.energy = energy; 98 | 99 | if (this.energy > capacity) { 100 | this.energy = capacity; 101 | } else if (this.energy < 0) { 102 | this.energy = 0; 103 | } 104 | } 105 | 106 | /** 107 | * This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this externally, as not all IEnergyHandlers are guaranteed to have it. 108 | */ 109 | public void modifyEnergyStored(int energy) { 110 | 111 | this.energy += energy; 112 | 113 | if (this.energy > capacity) { 114 | this.energy = capacity; 115 | } else if (this.energy < 0) { 116 | this.energy = 0; 117 | } 118 | } 119 | 120 | /* IEnergyStorage */ 121 | @Override 122 | public int receiveEnergy(int maxReceive, boolean simulate) { 123 | 124 | int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); 125 | 126 | if (!simulate) { 127 | energy += energyReceived; 128 | } 129 | return energyReceived; 130 | } 131 | 132 | @Override 133 | public int extractEnergy(int maxExtract, boolean simulate) { 134 | 135 | int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); 136 | 137 | if (!simulate) { 138 | energy -= energyExtracted; 139 | } 140 | return energyExtracted; 141 | } 142 | 143 | @Override 144 | public int getEnergyStored() { 145 | 146 | return energy; 147 | } 148 | 149 | @Override 150 | public int getMaxEnergyStored() { 151 | 152 | return capacity; 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureBase.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.world.IFeatureGenerator; 4 | import cofh.lib.world.biome.BiomeInfo; 5 | import cofh.lib.world.biome.BiomeInfoSet; 6 | import gnu.trove.set.hash.THashSet; 7 | import net.minecraft.util.math.BlockPos; 8 | import net.minecraft.world.World; 9 | import net.minecraft.world.biome.Biome; 10 | 11 | import java.util.Random; 12 | import java.util.Set; 13 | 14 | public abstract class FeatureBase implements IFeatureGenerator { 15 | 16 | public enum GenRestriction { 17 | NONE, BLACKLIST, WHITELIST; 18 | 19 | public static GenRestriction get(String restriction) { 20 | 21 | if (restriction.equalsIgnoreCase("blacklist")) { 22 | return BLACKLIST; 23 | } 24 | if (restriction.equalsIgnoreCase("whitelist")) { 25 | return WHITELIST; 26 | } 27 | return NONE; 28 | } 29 | } 30 | 31 | public final String name; 32 | 33 | public final GenRestriction biomeRestriction; 34 | public final GenRestriction dimensionRestriction; 35 | 36 | public final boolean regen; 37 | 38 | public boolean withVillage = true; 39 | 40 | protected int rarity; 41 | 42 | protected final BiomeInfoSet biomes = new BiomeInfoSet(1); 43 | protected final Set dimensions = new THashSet<>(); 44 | 45 | /** 46 | * Shortcut to add a Feature with no biome or dimension restriction. 47 | */ 48 | public FeatureBase(String name, boolean regen) { 49 | 50 | this(name, GenRestriction.NONE, regen, GenRestriction.NONE); 51 | } 52 | 53 | /** 54 | * Shortcut to add a Feature with a dimension restriction but no biome restriction. 55 | */ 56 | public FeatureBase(String name, boolean regen, GenRestriction dimRes) { 57 | 58 | this(name, GenRestriction.NONE, regen, dimRes); 59 | } 60 | 61 | /** 62 | * Shortcut to add a Feature with a biome restriction but no dimension restriction. 63 | */ 64 | public FeatureBase(String name, GenRestriction biomeRes, boolean regen) { 65 | 66 | this(name, biomeRes, regen, GenRestriction.NONE); 67 | } 68 | 69 | public FeatureBase(String name, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 70 | 71 | this.name = name; 72 | this.biomeRestriction = biomeRes; 73 | this.dimensionRestriction = dimRes; 74 | this.regen = regen; 75 | } 76 | 77 | public void setRarity(int rarity) { 78 | 79 | this.rarity = rarity; 80 | } 81 | 82 | public FeatureBase addBiome(BiomeInfo biome) { 83 | 84 | biomes.add(biome); 85 | return this; 86 | } 87 | 88 | public FeatureBase addBiomes(BiomeInfoSet biomes) { 89 | 90 | this.biomes.addAll(biomes); 91 | return this; 92 | } 93 | 94 | public FeatureBase addDimension(int dimID) { 95 | 96 | dimensions.add(dimID); 97 | return this; 98 | } 99 | 100 | /* IFeatureGenerator */ 101 | @Override 102 | public final String getFeatureName() { 103 | 104 | return name; 105 | } 106 | 107 | @Override 108 | public boolean generateFeature(Random random, int chunkX, int chunkZ, World world, boolean hasVillage, boolean newGen) { 109 | 110 | if (!newGen && !regen) { 111 | return false; 112 | } 113 | if (hasVillage && !withVillage) { 114 | return false; 115 | } 116 | if (dimensionRestriction != GenRestriction.NONE && dimensionRestriction == GenRestriction.BLACKLIST == dimensions.contains(world.provider.getDimension())) { 117 | return false; 118 | } 119 | if (rarity > 1 && random.nextInt(rarity) != 0) { 120 | return false; 121 | } 122 | 123 | return generateFeature(random, chunkX * 16 + 8, chunkZ * 16 + 8, world); 124 | } 125 | 126 | protected abstract boolean generateFeature(Random random, int blockX, int blockZ, World world); 127 | 128 | protected boolean canGenerateInBiome(World world, int x, int z, Random rand) { 129 | 130 | if (biomeRestriction != GenRestriction.NONE) { 131 | Biome biome = world.getBiome(new BlockPos(x, 0, z)); 132 | return !(biomeRestriction == GenRestriction.BLACKLIST == biomes.contains(biome, rand)); 133 | } 134 | return true; 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/cofh/lib/world/feature/FeatureGenUnderfluid.java: -------------------------------------------------------------------------------- 1 | package cofh.lib.world.feature; 2 | 3 | import cofh.lib.util.WeightedRandomBlock; 4 | import cofh.lib.util.helpers.BlockHelper; 5 | import cofh.lib.util.helpers.FluidHelper; 6 | import cofh.lib.util.numbers.ConstantProvider; 7 | import cofh.lib.util.numbers.INumberProvider; 8 | import net.minecraft.block.material.Material; 9 | import net.minecraft.block.state.IBlockState; 10 | import net.minecraft.block.state.pattern.BlockMatcher; 11 | import net.minecraft.util.math.BlockPos; 12 | import net.minecraft.world.World; 13 | import net.minecraft.world.gen.feature.WorldGenerator; 14 | import net.minecraftforge.fluids.Fluid; 15 | import net.minecraftforge.fluids.FluidRegistry; 16 | 17 | import java.util.Arrays; 18 | import java.util.List; 19 | import java.util.Random; 20 | 21 | public class FeatureGenUnderfluid extends FeatureBase { 22 | 23 | final boolean water; 24 | final WorldGenerator worldGen; 25 | final INumberProvider count; 26 | final List matList; 27 | @Deprecated 28 | final int[] fluidList; 29 | 30 | public FeatureGenUnderfluid(String name, WorldGenerator worldGen, List matList, int count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 31 | 32 | this(name, worldGen, matList, new ConstantProvider(count), biomeRes, regen, dimRes); 33 | } 34 | 35 | public FeatureGenUnderfluid(String name, WorldGenerator worldGen, List matList, int[] fluidList, int count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 36 | 37 | this(name, worldGen, matList, fluidList, new ConstantProvider(count), biomeRes, regen, dimRes); 38 | } 39 | 40 | public FeatureGenUnderfluid(String name, WorldGenerator worldGen, List matList, INumberProvider count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 41 | 42 | super(name, biomeRes, regen, dimRes); 43 | this.worldGen = worldGen; 44 | this.count = count; 45 | this.matList = matList; 46 | water = true; 47 | fluidList = null; 48 | } 49 | 50 | public FeatureGenUnderfluid(String name, WorldGenerator worldGen, List matList, int[] fluidList, INumberProvider count, GenRestriction biomeRes, boolean regen, GenRestriction dimRes) { 51 | 52 | super(name, biomeRes, regen, dimRes); 53 | this.worldGen = worldGen; 54 | this.count = count; 55 | this.matList = matList; 56 | water = false; 57 | Arrays.sort(fluidList); 58 | this.fluidList = fluidList; 59 | } 60 | 61 | @Override 62 | public boolean generateFeature(Random random, int blockX, int blockZ, World world) { 63 | 64 | BlockPos pos = new BlockPos(blockX, 64, blockZ); 65 | 66 | final int count = this.count.intValue(world, random, pos); 67 | 68 | boolean generated = false; 69 | for (int i = 0; i < count; i++) { 70 | int x = blockX + random.nextInt(16); 71 | int z = blockZ + random.nextInt(16); 72 | if (!canGenerateInBiome(world, x, z, random)) { 73 | continue; 74 | } 75 | 76 | int y = BlockHelper.getSurfaceBlockY(world, x, z); 77 | l: 78 | do { 79 | IBlockState state = world.getBlockState(new BlockPos(x, y, z)); 80 | if (water) { 81 | if (state.getMaterial() == Material.WATER) { 82 | continue; 83 | } 84 | if (world.getBlockState(new BlockPos(x, y + 1, z)).getMaterial() != Material.WATER) { 85 | continue; 86 | } 87 | } else { 88 | Fluid fluid = FluidHelper.lookupFluidForBlock(state.getBlock()); 89 | if (fluid != null && Arrays.binarySearch(fluidList, FluidRegistry.getFluidID(fluid)) >= 0) { 90 | continue; 91 | } 92 | 93 | fluid = FluidHelper.lookupFluidForBlock(world.getBlockState(new BlockPos(x, y + 1, z)).getBlock()); 94 | if (fluid == null || Arrays.binarySearch(fluidList, FluidRegistry.getFluidID(fluid)) < 0) { 95 | continue; 96 | } 97 | } 98 | for (WeightedRandomBlock mat : matList) { 99 | if (state.getBlock().isReplaceableOreGen(state, world, new BlockPos(x, y, z), BlockMatcher.forBlock(mat.block))) { 100 | break l; 101 | } 102 | } 103 | } while (y-- > 1); 104 | 105 | if (y > 0) { 106 | generated |= worldGen.generate(world, random, new BlockPos(x, y, z)); 107 | } 108 | } 109 | return generated; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/cofh/api/energy/IEnergyTransport.java: -------------------------------------------------------------------------------- 1 | package cofh.api.energy; 2 | 3 | import net.minecraft.util.EnumFacing; 4 | 5 | /** 6 | * Implement this interface on Tile Entities which transport energy. 7 | * 8 | * This is used to "negotiate" connection types between two separate IEnergyTransports, allowing users to set flow direction and allowing for networks Of 9 | * IEnergyTransports to intelligently transfer energy to other networks. 10 | */ 11 | public interface IEnergyTransport extends IEnergyProvider, IEnergyReceiver { 12 | 13 | /** 14 | * The type of interface for a given side of a {@link IEnergyTransport}. 15 | * 16 | * Values are: 17 | * {@link #SEND} for sending only 18 | * {@link #RECEIVE} for receiving only 19 | * {@link #BALANCE} for sending and receiving, and the default state 20 | */ 21 | enum InterfaceType { 22 | /** 23 | * Indicates that this {@link IEnergyTransport} is only sending power on this side. 24 | */ 25 | SEND, /** 26 | * Indicates that this {@link IEnergyTransport} is only receiving power on this side. 27 | */ 28 | RECEIVE, /** 29 | * Indicates that this {@link IEnergyTransport} wants to balance power between itself and the 30 | * senders/receivers on this side. This is the default state. 31 | * To block any connection, use {@link IEnergyConnection#canConnectEnergy} 32 | * 33 | * IEnergyTransport based senders should check that the total power in the destination IEnergyTransport is less than the power in themselves before sending. 34 | * 35 | * Active IEnergyTransport receivers (i.e., those that call {@link IEnergyProvider#extractEnergy}) should check that they contain less power than the 36 | * source IEnergyTransport. 37 | */ 38 | BALANCE; 39 | 40 | /** 41 | * Returns the opposite state to this InterfaceType. 42 | * 43 | * {@link #BALANCE} is considered its own opposite. 44 | * {@link #SEND} is the opposite of {@link #RECEIVE} and visa versa. 45 | */ 46 | public InterfaceType getOpposite() { 47 | 48 | return this == BALANCE ? BALANCE : this == SEND ? RECEIVE : SEND; 49 | } 50 | 51 | /** 52 | * Returns the next InterfaceType as described in {@link IEnergyTransport#getTransportState} 53 | */ 54 | public InterfaceType rotate() { 55 | 56 | return rotate(true); 57 | } 58 | 59 | /** 60 | * Returns the next InterfaceType as described in {@link IEnergyTransport#getTransportState} 61 | * 62 | * @param forward Whether to step in the order specified by {@link IEnergyTransport#getTransportState} (true) or to step in the opposite direction 63 | */ 64 | public InterfaceType rotate(boolean forward) { 65 | 66 | if (forward) { 67 | return this == BALANCE ? RECEIVE : this == RECEIVE ? SEND : BALANCE; 68 | } else { 69 | return this == BALANCE ? SEND : this == SEND ? RECEIVE : BALANCE; 70 | } 71 | } 72 | } 73 | 74 | /** 75 | * {@inheritDoc} 76 | * This method cannot be a no-op for IEnergyTransport. 77 | */ 78 | @Override 79 | int getEnergyStored(EnumFacing from); 80 | 81 | /** 82 | * Indicates to other IEnergyTransports the state of the given side. See {@link InterfaceType} for details. 83 | * 84 | * For clarity of state tracking, on a tile update from another IEnergyTransport, if its mode has changed from the opposite of your own mode on that side, you 85 | * should change your mode to the opposite of its mode. 86 | * 87 | * When the user alters your mode and your state is: 88 | * BALANCE, your mode should change to {@link InterfaceType#RECEIVE}. 89 | * RECEIVE, your mode should change to {@link InterfaceType#SEND}. 90 | * SEND, your mode should change to {@link InterfaceType#BALANCE}. 91 | * This is not required, but will be easier for users. 92 | * 93 | * @return The type of connection to establish on this side. null is NOT a valid value. 94 | */ 95 | InterfaceType getTransportState(EnumFacing from); 96 | 97 | /** 98 | * This method is provided primarily for the purposes of automation tools, and should not need to be called by another IEnergyTransport. 99 | * 100 | * Calls to this method may fail if this IEnergyTransport has been secured by a user. 101 | * 102 | * @return Whether or not state was successfully altered. 103 | */ 104 | boolean setTransportState(InterfaceType state, EnumFacing from); 105 | 106 | } 107 | --------------------------------------------------------------------------------