diff options
Diffstat (limited to 'src/main/java/gregtech/api/util')
6 files changed, 161 insertions, 20 deletions
diff --git a/src/main/java/gregtech/api/util/GT_BaseCrop.java b/src/main/java/gregtech/api/util/GT_BaseCrop.java index e7cef2c598..fe1055c2c8 100644 --- a/src/main/java/gregtech/api/util/GT_BaseCrop.java +++ b/src/main/java/gregtech/api/util/GT_BaseCrop.java @@ -1,7 +1,13 @@ package gregtech.api.util; import static gregtech.api.enums.GT_Values.E; +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; @@ -9,14 +15,18 @@ import ic2.api.crops.ICropTile; import java.util.ArrayList; import java.util.Random; +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; public class GT_BaseCrop extends CropCard { 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; + public static ArrayList<GT_BaseCrop> sCropList = new ArrayList<GT_BaseCrop>(); @@ -33,6 +43,24 @@ 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,8 +77,9 @@ 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); } } @@ -62,6 +90,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; } @@ -73,6 +111,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(); } @@ -126,4 +167,51 @@ 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 22759cd057..8722247a38 100644 --- a/src/main/java/gregtech/api/util/GT_ModHandler.java +++ b/src/main/java/gregtech/api/util/GT_ModHandler.java @@ -52,7 +52,7 @@ import cpw.mods.fml.common.registry.GameRegistry; * Due to the many imports, this File can cause compile Problems if not all the APIs are installed */ public class GT_ModHandler { - public static volatile int VERSION = 508; + public static volatile int VERSION = 509; /** * Returns if that Liquid is Water or Distilled Water @@ -1501,17 +1501,19 @@ public class GT_ModHandler { EntityPlayer tPlayer = (EntityPlayer)aPlayer; if (tPlayer.capabilities.isCreativeMode) return T; if(isElectricItem(aStack)&&ic2.api.item.ElectricItem.manager.getCharge(aStack)>1000.0d){ - for (int i = 0; i < tPlayer.inventory.mainInventory.length; i++) { + for (int i = 0; i < tPlayer.inventory.mainInventory.length; i++) { if (GT_Utility.isStackInList(tPlayer.inventory.mainInventory[i], GregTech_API.sSolderingMetalList)) { - tPlayer.inventory.mainInventory[i].stackSize--; + if(tPlayer.inventory.mainInventory[i].stackSize<1)return false; + if(tPlayer.inventory.mainInventory[i].stackSize==1){tPlayer.inventory.mainInventory[i]=null;}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); } GT_ModHandler.useElectricItem(aStack, (int) ic2.api.item.ElectricItem.manager.getCharge(aStack), (EntityPlayer)aPlayer); - return false; - } - } + return false; + } + } } } else { damageOrDechargeItem(aStack, 1, 1000, aPlayer); diff --git a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java index 6425e5b89d..1c0a9e53bc 100644 --- a/src/main/java/gregtech/api/util/GT_OreDictUnificator.java +++ b/src/main/java/gregtech/api/util/GT_OreDictUnificator.java @@ -31,7 +31,7 @@ import net.minecraftforge.oredict.OreDictionary; * P.S. It is intended to be named "Unificator" and not "Unifier", because that sounds more awesome. */ public class GT_OreDictUnificator { - public static volatile int VERSION = 508; + public static volatile int VERSION = 509; private static final HashMap<String, ItemStack> sName2StackMap = new HashMap<String, ItemStack>(); private static final HashMap<GT_ItemStack, ItemData> sItemStack2DataMap = new HashMap<GT_ItemStack, ItemData>(); diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 130a63d7b6..1941ceef24 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 net.minecraftforge.fluids.IFluidContainerItem; * 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; public static class GT_Recipe_Map { /** Contains all Recipe Maps */ @@ -52,7 +52,7 @@ public class GT_Recipe { public static final GT_Recipe_Map sRockBreakerFakeRecipes = new GT_Recipe_Map (new HashSet<GT_Recipe>( 3), "gt.recipe.rockbreaker" , "Rock Breaker" , null , RES_PATH_GUI+"basicmachines/RockBreaker" , 1, 1, 0, 0, 1, E , 1, E , T, T); public static final GT_Recipe_Map sByProductList = new GT_Recipe_Map (new HashSet<GT_Recipe>( 1000), "gt.recipe.byproductlist" , "Ore Byproduct List" , null , RES_PATH_GUI+"basicmachines/Default" , 1, 6, 1, 0, 1, E , 1, E , T, T); public static final GT_Recipe_Map sRepicatorFakeRecipes = new GT_Recipe_Map (new HashSet<GT_Recipe>( 100), "gt.recipe.replicator" , "Replicator" , null , RES_PATH_GUI+"basicmachines/Replicator" , 0, 1, 0, 1, 1, E , 1, E , T, T); - + public static final GT_Recipe_Map sPlasmaArcFurnaceRecipes = new GT_Recipe_Map (new HashSet<GT_Recipe>(10000), "gt.recipe.plasmaarcfurnace" , "Plasma Arc Furnace" , null , RES_PATH_GUI+"basicmachines/PlasmaArcFurnace" , 1, 4, 1, 1, 1, E , 1, E , T, T); public static final GT_Recipe_Map sArcFurnaceRecipes = new GT_Recipe_Map (new HashSet<GT_Recipe>(10000), "gt.recipe.arcfurnace" , "Arc Furnace" , null , RES_PATH_GUI+"basicmachines/ArcFurnace" , 1, 4, 1, 1, 3, E , 1, E , T, T); public static final GT_Recipe_Map sPrinterRecipes = new GT_Recipe_Map_Printer (new HashSet<GT_Recipe>( 100), "gt.recipe.printer" , "Printer" , null , RES_PATH_GUI+"basicmachines/Printer" , 1, 1, 1, 1, 1, E , 1, E , T, T); @@ -82,6 +82,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 , T, T); 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 , T, T); 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 , T, T); + 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 , T, T); + 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 , T, T); 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 , T, T); 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 , T, T); 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 , T, T); diff --git a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java index ee9f080c8e..ffd2e43754 100644 --- a/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java +++ b/src/main/java/gregtech/api/util/GT_RecipeRegistrator.java @@ -22,7 +22,7 @@ import net.minecraft.item.ItemStack; * Class for Automatic Recipe registering. */ public class GT_RecipeRegistrator { - public static volatile int VERSION = 508; + public static volatile int VERSION = 509; /** List of Materials, which are used in the Creation of Sticks. All Rod Materials are automatically added to this List. */ public static final List<Materials> sRodMaterialList = new ArrayList<Materials>(); diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 0ae3da3909..1fca6f1099 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -1,11 +1,13 @@ package gregtech.api.util; import static gregtech.api.enums.GT_Values.*; +import forestry.core.fluids.Fluids; import gregtech.api.GregTech_API; import gregtech.api.damagesources.GT_DamageSources; import gregtech.api.enchants.Enchantment_Radioactivity; import gregtech.api.enums.GT_Values; 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; @@ -72,7 +74,7 @@ import cofh.api.transport.*; * Just a few Utility Functions I use. */ public class GT_Utility { - public static volatile int VERSION = 508; + public static volatile int VERSION = 509; public static class ItemNBT { public static void setNBT(ItemStack aStack, NBTTagCompound aNBT) { @@ -142,6 +144,31 @@ 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()); @@ -1408,9 +1435,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)); } @@ -1432,8 +1456,8 @@ public class GT_Utility { } /** - * Loads an ItemStack properly. - */ + * Loads an FluidStack properly. + */ public static FluidStack loadFluid(NBTTagCompound aNBT) { if (aNBT == null) return null; return FluidStack.loadFluidStackFromNBT(aNBT); @@ -1580,6 +1604,27 @@ public class GT_Utility { return F; } + 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; @@ -1700,12 +1745,16 @@ public class GT_Utility { } }} catch(Throwable e) {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; ArrayList<String> temp = ((IDebugableBlock)tBlock).getDebugInfo(aPlayer, aX, aY, aZ, 3); if (temp != null) tList.addAll(temp); }} catch(Throwable e) {if (D1) e.printStackTrace(GT_Log.err);} - + BlockScanningEvent tEvent = new BlockScanningEvent(aWorld, aPlayer, aX, aY, aZ, (byte)aSide, aScanLevel, tBlock, tTileEntity, tList, aClickX, aClickY, aClickZ); tEvent.mEUCost = rEUAmount; MinecraftForge.EVENT_BUS.post(tEvent); |