aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r--src/main/java/gregtech/api/util/GT_BaseCrop.java89
-rw-r--r--src/main/java/gregtech/api/util/GT_ModHandler.java3
-rw-r--r--src/main/java/gregtech/api/util/GT_OreDictUnificator.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_Recipe.java4
-rw-r--r--src/main/java/gregtech/api/util/GT_RecipeRegistrator.java2
-rw-r--r--src/main/java/gregtech/api/util/GT_Utility.java66
6 files changed, 153 insertions, 13 deletions
diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java
index 4b0e4a5526..794b560166 100644
--- a/src/main/java/gregtech/api/util/GT_BaseCrop.java
+++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java
@@ -1,12 +1,20 @@
package gregtech.api.util;
+import gregtech.api.GregTech_API;
import gregtech.api.enums.ConfigCategories;
+import gregtech.api.enums.Materials;
+import gregtech.api.enums.OrePrefixes;
+import gregtech.api.objects.ItemData;
+import gregtech.common.blocks.GT_Block_Ores;
+import gregtech.common.blocks.GT_TileEntity_Ores;
import ic2.api.crops.CropCard;
import ic2.api.crops.Crops;
import ic2.api.crops.ICropTile;
+import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
+import net.minecraft.tileentity.TileEntity;
import java.util.ArrayList;
import java.util.Random;
@@ -16,8 +24,9 @@ import static gregtech.api.enums.GT_Values.E;
public class GT_BaseCrop extends CropCard {
public static ArrayList<GT_BaseCrop> sCropList = new ArrayList<GT_BaseCrop>();
private String mName = E, mDiscoveredBy = "Gregorius Techneticies", mAttributes[];
- private int mTier = 0, mMaxSize = 0, mAfterHarvestSize = 0, mHarvestSize = 0, mStats[] = new int[5];
+ private int mTier = 0, mMaxSize = 0, mAfterHarvestSize = 0, mHarvestSize = 0, mStats[] = new int[5], mGrowthSpeed = 0;
private ItemStack mDrop = null, mSpecialDrops[] = null;
+ private Materials mBlock = null;
/**
* To create new Crops
@@ -33,6 +42,25 @@ public class GT_BaseCrop extends CropCard {
* @param aHarvestSize the size the Crop needs to be harvested. forced to be between 2 and max size
*/
public GT_BaseCrop(int aID, String aCropName, String aDiscoveredBy, ItemStack aDrop, ItemStack[] aSpecialDrops, ItemStack aBaseSeed, int aTier, int aMaxSize, int aGrowthSpeed, int aAfterHarvestSize, int aHarvestSize, int aStatChemical, int aStatFood, int aStatDefensive, int aStatColor, int aStatWeed, String[] aAttributes) {
+ new GT_BaseCrop(aID, aCropName, aDiscoveredBy, aDrop, aSpecialDrops, aBaseSeed, aTier, aMaxSize, aGrowthSpeed, aAfterHarvestSize, aHarvestSize, aStatChemical, aStatFood, aStatDefensive, aStatColor, aStatWeed, aAttributes, null);
+ }
+
+ /**
+ * To create new Crops
+ *
+ * @param aID Default ID
+ * @param aCropName Name of the Crop
+ * @param aDiscoveredBy The one who discovered the Crop
+ * @param aDrop The Item which is dropped by the Crop. must be != null
+ * @param aBaseSeed Baseseed to plant this Crop. null == crossbreed only
+ * @param aTier tier of the Crop. forced to be >= 1
+ * @param aMaxSize maximum Size of the Crop. forced to be >= 3
+ * @param aGrowthSpeed how fast the Crop grows. if < 0 then its set to Tier*300
+ * @param aHarvestSize the size the Crop needs to be harvested. forced to be between 2 and max size
+ * @param aBlock the block below needed for crop to grow. If null no block needed
+ * @param aMeta meta of the block below(-1 if no meta)
+ */
+ public GT_BaseCrop(int aID, String aCropName, String aDiscoveredBy, ItemStack aDrop, ItemStack[] aSpecialDrops, ItemStack aBaseSeed, int aTier, int aMaxSize, int aGrowthSpeed, int aAfterHarvestSize, int aHarvestSize, int aStatChemical, int aStatFood, int aStatDefensive, int aStatColor, int aStatWeed, String[] aAttributes, Materials aBlock) {
mName = aCropName;
aID = GT_Config.addIDConfig(ConfigCategories.IDs.crops, mName.replaceAll(" ", "_"), aID);
if (aDiscoveredBy != null && !aDiscoveredBy.equals(E)) mDiscoveredBy = aDiscoveredBy;
@@ -41,7 +69,6 @@ public class GT_BaseCrop extends CropCard {
mSpecialDrops = aSpecialDrops;
mTier = Math.max(1, aTier);
mMaxSize = Math.max(3, aMaxSize);
-// mGrowthSpeed = aGrowthSpeed>0?aGrowthSpeed:mTier*300;
mHarvestSize = Math.min(Math.max(aHarvestSize, 2), mMaxSize);
mAfterHarvestSize = Math.min(Math.max(aAfterHarvestSize, 1), mMaxSize - 1);
mStats[0] = aStatChemical;
@@ -50,9 +77,10 @@ public class GT_BaseCrop extends CropCard {
mStats[3] = aStatColor;
mStats[4] = aStatWeed;
mAttributes = aAttributes;
+ mBlock = aBlock;
if (!Crops.instance.registerCrop(this, aID))
throw new GT_ItsNotMyFaultException("Make sure the Crop ID is valid!");
- if (aBaseSeed != null) Crops.instance.registerBaseSeed(aBaseSeed, aID, 1, 1, 1, 1);
+ if (aBaseSeed != null) Crops.instance.registerBaseSeed(aBaseSeed, this, 1, 1, 1, 1);
sCropList.add(this);
}
}
@@ -63,6 +91,16 @@ public class GT_BaseCrop extends CropCard {
}
@Override
+ public int growthDuration(ICropTile aCrop) {
+ if (mGrowthSpeed < 200) return super.growthDuration(aCrop);
+ return tier() * mGrowthSpeed;
+ }
+
+ public int getrootslength(ICropTile crop) {
+ return 3;
+ }
+
+ @Override
public String[] attributes() {
return mAttributes;
}
@@ -74,6 +112,9 @@ public class GT_BaseCrop extends CropCard {
@Override
public final boolean canGrow(ICropTile aCrop) {
+ if (mBlock != null && aCrop.getSize() == mMaxSize - 1) {
+ return isBlockBelow(aCrop);
+ }
return aCrop.getSize() < maxSize();
}
@@ -127,4 +168,46 @@ public class GT_BaseCrop extends CropCard {
public int getOptimalHavestSize(ICropTile crop) {
return maxSize();
}
+
+ public boolean isBlockBelow(ICropTile aCrop) {
+ if (aCrop == null) {
+ return false;
+ }
+ for (int i = 1; i < this.getrootslength(aCrop); i++) {
+ Block tBlock = aCrop.getWorld().getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ);
+ if ((tBlock instanceof GT_Block_Ores)) {
+ TileEntity tTileEntity = aCrop.getWorld().getTileEntity(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ);
+ if ((tTileEntity instanceof GT_TileEntity_Ores)) {
+ Materials tMaterial = GregTech_API.sGeneratedMaterials[(((GT_TileEntity_Ores) tTileEntity).mMetaData % 1000)];
+ if ((tMaterial != null) && (tMaterial != Materials._NULL)) {
+ if (tMaterial == mBlock) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ }
+ } else {
+ int tMetaID = aCrop.getWorld().getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ);
+ ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID));
+ if ((tAssotiation != null) && (tAssotiation.mPrefix.toString().startsWith("ore")) && (tAssotiation.mMaterial.mMaterial == mBlock)) {
+ return true;
+ }
+ if ((tAssotiation != null) && (tAssotiation.mPrefix == OrePrefixes.block) && (tAssotiation.mMaterial.mMaterial == mBlock)) {
+ return true;
+ }
+ }
+// Block block = aCrop.getWorld().getBlock(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ);
+// if (block.isAir(aCrop.getWorld(), aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ)) {
+// return false;
+// }
+// if (block == mBlock) {
+// int tMeta = aCrop.getWorld().getBlockMetadata(aCrop.getLocation().posX, aCrop.getLocation().posY - i, aCrop.getLocation().posZ);
+// if(mMeta < 0 || tMeta == mMeta){
+// return true;}
+// }
+ }
+ return false;
+ }
+
}
diff --git a/src/main/java/gregtech/api/util/GT_ModHandler.java b/src/main/java/gregtech/api/util/GT_ModHandler.java
index 809a5219ce..cfe264d843 100644
--- a/src/main/java/gregtech/api/util/GT_ModHandler.java
+++ b/src/main/java/gregtech/api/util/GT_ModHandler.java
@@ -53,7 +53,7 @@ public class GT_ModHandler {
public static final List<IRecipe> sSingleNonBlockDamagableRecipeList = new ArrayList<IRecipe>(1000);
private static final Map<String, ItemStack> sIC2ItemMap = new HashMap<String, ItemStack>();
private static final List<IRecipe> sAllRecipeList = Collections.synchronizedList(new ArrayList<IRecipe>(5000)), sBufferRecipeList = new ArrayList<IRecipe>(1000);
- public static volatile int VERSION = 508;
+ public static volatile int VERSION = 509;
public static Collection<String> sNativeRecipeClasses = new HashSet<String>(), sSpecialRecipeClasses = new HashSet<String>();
public static GT_HashSet<GT_ItemStack> sNonReplaceableItems = new GT_HashSet<GT_ItemStack>();
public static Object sBoxableWrapper = GT_Utility.callConstructor("gregtechmod.api.util.GT_IBoxableWrapper", 0, null, false);
@@ -1591,7 +1591,6 @@ public class GT_ModHandler {
} else {
tPlayer.inventory.mainInventory[i].stackSize--;
}
-
if (tPlayer.inventoryContainer != null) tPlayer.inventoryContainer.detectAndSendChanges();
if (canUseElectricItem(aStack, 10000)) {
return GT_ModHandler.useElectricItem(aStack, 10000, (EntityPlayer) aPlayer);
diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
index 39eabad202..b404299fad 100644
--- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
+++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java
@@ -32,7 +32,7 @@ public class GT_OreDictUnificator {
private static final HashMap<String, ItemStack> sName2StackMap = new HashMap<String, ItemStack>();
private static final HashMap<GT_ItemStack, ItemData> sItemStack2DataMap = new HashMap<GT_ItemStack, ItemData>();
private static final GT_HashSet<GT_ItemStack> sNoUnificationList = new GT_HashSet<GT_ItemStack>();
- public static volatile int VERSION = 508;
+ public static volatile int VERSION = 509;
private static int isRegisteringOre = 0, isAddingOre = 0;
private static boolean mRunThroughTheList = true;
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java
index 61b6fde2f1..96ab461c43 100644
--- a/src/main/java/gregtech/api/util/GT_Recipe.java
+++ b/src/main/java/gregtech/api/util/GT_Recipe.java
@@ -34,7 +34,7 @@ import static gregtech.api.enums.GT_Values.*;
* I know this File causes some Errors, because of missing Main Functions, but if you just need to compile Stuff, then remove said erroreous Functions.
*/
public class GT_Recipe {
- public static volatile int VERSION = 508;
+ public static volatile int VERSION = 509;
/**
* If you want to change the Output, feel free to modify or even replace the whole ItemStack Array, for Inputs, please add a new Recipe, because of the HashMaps.
*/
@@ -416,6 +416,8 @@ public class GT_Recipe {
public static final GT_Recipe_Map sVacuumRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(100), "gt.recipe.vacuumfreezer", "Vacuum Freezer", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sChemicalRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(100), "gt.recipe.chemicalreactor", "Chemical Reactor", null, RES_PATH_GUI + "basicmachines/ChemicalReactor", 2, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sDistillationRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(50), "gt.recipe.distillationtower", "Distillation Tower", null, RES_PATH_GUI + "basicmachines/Default", 2, 4, 0, 0, 1, E, 1, E, true, true);
+ public static final GT_Recipe_Map sCrakingRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(50), "gt.recipe.craker", "Oil Cracker", null, RES_PATH_GUI + "basicmachines/Default", 1, 1, 0, 1, 1, E, 1, E, true, true);
+ public static final GT_Recipe_Map sPyrolyseRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(50), "gt.recipe.pyro", "Pyrolyse Oven", null, RES_PATH_GUI + "basicmachines/Default", 2, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sWiremillRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(50), "gt.recipe.wiremill", "Wiremill", null, RES_PATH_GUI + "basicmachines/Wiremill", 1, 1, 1, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sBenderRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(400), "gt.recipe.metalbender", "Metal Bender", null, RES_PATH_GUI + "basicmachines/Bender", 2, 1, 2, 0, 1, E, 1, E, true, true);
public static final GT_Recipe_Map sAlloySmelterRecipes = new GT_Recipe_Map(new HashSet<GT_Recipe>(3000), "gt.recipe.alloysmelter", "Alloy Smelter", null, RES_PATH_GUI + "basicmachines/AlloySmelter", 2, 1, 2, 0, 1, E, 1, E, true, true);
diff --git a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
index ab35b292f1..5be4101e5f 100644
--- a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
+++ b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java
@@ -119,7 +119,7 @@ public class GT_RecipeRegistrator {
{"Scythe", s_I + s_P + s_H, s_R + s_F + s_P, s_R + " " + " "},
{"Scythe", s_H + s_P + s_I, s_P + s_F + s_R, " " + " " + s_R}
};
- public static volatile int VERSION = 508;
+ public static volatile int VERSION = 509;
public static void registerMaterialRecycling(ItemStack aStack, Materials aMaterial, long aMaterialAmount, MaterialStack aByproduct) {
if (GT_Utility.isStackInvalid(aStack)) return;
diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java
index 06615a681b..a208042f24 100644
--- a/src/main/java/gregtech/api/util/GT_Utility.java
+++ b/src/main/java/gregtech/api/util/GT_Utility.java
@@ -6,6 +6,7 @@ import gregtech.api.GregTech_API;
import gregtech.api.damagesources.GT_DamageSources;
import gregtech.api.enchants.Enchantment_Radioactivity;
import gregtech.api.enums.ItemList;
+import gregtech.api.enums.Materials;
import gregtech.api.enums.SubTag;
import gregtech.api.events.BlockScanningEvent;
import gregtech.api.interfaces.IDebugableBlock;
@@ -80,7 +81,7 @@ public class GT_Utility {
private static final List<FluidContainerData> sFluidContainerList = new ArrayList<FluidContainerData>();
private static final Map<GT_ItemStack, FluidContainerData> sFilledContainerToData = new HashMap<GT_ItemStack, FluidContainerData>();
private static final Map<GT_ItemStack, Map<Fluid, FluidContainerData>> sEmptyContainerToFluidToData = new HashMap<GT_ItemStack, Map<Fluid, FluidContainerData>>();
- public static volatile int VERSION = 508;
+ public static volatile int VERSION = 509;
public static boolean TE_CHECK = false, BC_CHECK = false, CHECK_ALL = true;
public static Map<GT_PlayedSound, Integer> sPlayedSoundMap = new HashMap<GT_PlayedSound, Integer>();
private static int sBookCount = 0;
@@ -1292,9 +1293,6 @@ public class GT_Utility {
return loadItem(aNBT.getCompoundTag(aTagName));
}
- /**
- * Loads an ItemStack properly.
- */
public static FluidStack loadFluid(NBTTagCompound aNBT, String aTagName) {
return loadFluid(aNBT.getCompoundTag(aTagName));
}
@@ -1316,7 +1314,7 @@ public class GT_Utility {
}
/**
- * Loads an ItemStack properly.
+ * Loads an FluidStack properly.
*/
public static FluidStack loadFluid(NBTTagCompound aNBT) {
if (aNBT == null) return null;
@@ -1477,6 +1475,32 @@ public class GT_Utility {
return false;
}
+ public static FluidStack getUndergroundOil(World aWorld, int aX, int aZ) {
+ Random tRandom = new Random((aWorld.getSeed() + (aX / 96) + (7 * (aZ / 96))));
+ int oil = tRandom.nextInt(3);
+ double amount = tRandom.nextInt(50) + tRandom.nextDouble();
+// System.out.println("Oil: "+(aX/96)+" "+(aZ/96)+" "+oil+" "+amount);
+// amount = 40;
+ Fluid tFluid = null;
+ switch (oil) {
+ case 0:
+ tFluid = Materials.NatruralGas.mGas;
+ break;
+ case 1:
+ tFluid = Materials.OilLight.mFluid;
+ break;
+ case 2:
+ tFluid = Materials.OilMedium.mFluid;
+ break;
+ case 3:
+ tFluid = Materials.OilHeavy.mFluid;
+ break;
+ default:
+ tFluid = Materials.Oil.mFluid;
+ }
+ return new FluidStack(tFluid, (int) (Math.pow(amount, 5) / 100));
+ }
+
public static int getCoordinateScan(ArrayList<String> aList, EntityPlayer aPlayer, World aWorld, int aScanLevel, int aX, int aY, int aZ, int aSide, float aClickX, float aClickY, float aClickZ) {
if (aList == null) return 0;
@@ -1664,6 +1688,11 @@ public class GT_Utility {
if (D1) e.printStackTrace(GT_Log.err);
}
}
+ if (aPlayer.capabilities.isCreativeMode) {
+ FluidStack tFluid = getUndergroundOil(aWorld, aX, aZ);
+ tList.add("Oil in Chunk: " + tFluid.amount + " " + tFluid.getLocalizedName());
+ }
+
try {
if (tBlock instanceof IDebugableBlock) {
rEUAmount += 500;
@@ -1843,6 +1872,33 @@ public class GT_Utility {
return tNBT.getString("author");
}
+ public static void setProspectionData(ItemStack aStack, int aX, int aY, int aZ, int aDim, FluidStack aFluid, String[] aOres) {
+ NBTTagCompound tNBT = getNBT(aStack);
+ String tData = aX + "," + aY + "," + aZ + "," + aDim + "," + (aFluid.amount / 5000) + "," + aFluid.getLocalizedName() + ",";
+ for (String tString : aOres) {
+ tData += tString + ",";
+ }
+ tNBT.setString("prospection", tData);
+ setNBT(aStack, tNBT);
+ }
+
+ public static void convertProspectionData(ItemStack aStack) {
+ NBTTagCompound tNBT = getNBT(aStack);
+ String tData = tNBT.getString("prospection");
+ String[] tDataArray = tData.split(",");
+ if (tDataArray.length > 6) {
+ tNBT.setString("author", "X: " + tDataArray[0] + " Y: " + tDataArray[1] + " Z: " + tDataArray[2] + " Dim: " + tDataArray[3]);
+ NBTTagList tNBTList = new NBTTagList();
+ String tOres = " Prospected Ores: ";
+ for (int i = 6; tDataArray.length > i; i++) {
+ tOres += (tDataArray[i] + " ");
+ }
+ tNBTList.appendTag(new NBTTagString("Prospection Data From: X" + tDataArray[0] + " Z:" + tDataArray[2] + " Dim:" + tDataArray[3] + " Produces " + tDataArray[4] + "L " + tDataArray[5] + " " + tOres));
+ tNBT.setTag("pages", tNBTList);
+ }
+ setNBT(aStack, tNBT);
+ }
+
public static void addEnchantment(ItemStack aStack, Enchantment aEnchantment, int aLevel) {
NBTTagCompound tNBT = getNBT(aStack), tEnchantmentTag;
if (!tNBT.hasKey("ench", 9)) tNBT.setTag("ench", new NBTTagList());