From e3c9a249860a2df6ed2f1fa53bdf2ee0b215334b Mon Sep 17 00:00:00 2001 From: TheDarkDnKTv Date: Sat, 13 Mar 2021 09:25:55 +0200 Subject: [PATCH] More crop fixes --- .../java/gregtechmod/api/util/GT_Utility.java | 79 +++++++++++++------ .../loaders/load/GT_ItemIterator.java | 1 + .../loaders/postload/GT_CropLoader.java | 37 ++++++++- 3 files changed, 89 insertions(+), 28 deletions(-) diff --git a/src/main/java/gregtechmod/api/util/GT_Utility.java b/src/main/java/gregtechmod/api/util/GT_Utility.java index 2952b07..8e3ddf3 100644 --- a/src/main/java/gregtechmod/api/util/GT_Utility.java +++ b/src/main/java/gregtechmod/api/util/GT_Utility.java @@ -11,6 +11,8 @@ import gregtechmod.api.metatileentity.implementations.GT_MetaPipeEntity_Item; import gregtechmod.common.network.GT_PacketHandler; import gregtechmod.common.network.packet.GT_Packet; import gregtechmod.common.network.packet.GT_SoundPacket; +import ic2.api.crops.CropCard; +import ic2.api.crops.ICropTile; import ic2.api.recipe.IRecipeInput; import ic2.api.recipe.RecipeInputItemStack; import ic2.api.recipe.RecipeInputOreDict; @@ -34,8 +36,10 @@ import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; +import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; +import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -56,6 +60,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.*; import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.ObfuscationReflectionHelper; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -71,6 +76,23 @@ public class GT_Utility { public static final DecimalFormat sFormat = new DecimalFormat("###,###.##", new DecimalFormatSymbols(Locale.ENGLISH)); + public static InventoryCrafting getInventoryFromArray(ItemStack...stacks) { + InventoryCrafting crafting = new InventoryCrafting(new Container() { + @Override + public boolean canInteractWith(EntityPlayer p_75145_1_) { + return false; + } + }, 3, 3); + + try { + ObfuscationReflectionHelper.setPrivateValue(InventoryCrafting.class, crafting, stacks, new String[]{"field_70466_a", "stackList"}); + } catch (Throwable e) { + GT_Log.log.catching(e); + } + + return crafting; + } + public static int hashFluidStack(FluidStack stack) { int code = 1; code = 31*code + hashFluid(stack.getFluid()); @@ -736,13 +758,15 @@ public class GT_Utility { public static boolean addSimpleIC2MachineRecipe(ItemStack aInput, Map aRecipeList, NBTTagCompound aNBT, Object... aOutput) { if (isStackInvalid(aInput) || aOutput.length == 0 || aRecipeList == null) return false; String tOreName = GT_OreDictUnificator.getAssociation(aInput); - RecipeOutput out = new RecipeOutput(aNBT, GT_OreDictUnificator.getStackArray(true, aOutput)); - if (isStringValid(tOreName)) { - aRecipeList.put(new RecipeInputOreDict(tOreName, aInput.stackSize), out); - } else { - aRecipeList.put(new RecipeInputItemStack(copy(aInput), aInput.stackSize), out); - } - return true; + IRecipeInput in = isStringValid(tOreName) ? + new RecipeInputOreDict(tOreName, aInput.stackSize) : + new RecipeInputItemStack(copy(aInput), aInput.stackSize); + return addSimpleIC2MachineRecipe(in, aRecipeList, aNBT, GT_OreDictUnificator.getStackArray(true, aOutput)); + } + + public static boolean addSimpleIC2MachineRecipe(IRecipeInput input, Map aRecipeList, NBTTagCompound meta, ItemStack...outputs) { + if (input == null || outputs.length == 0 || aRecipeList == null) return false; + return aRecipeList.put(input, new RecipeOutput(meta, outputs)) != null; } private static int sBookCount = 0; @@ -1270,9 +1294,8 @@ public class GT_Utility { return false; } - @SuppressWarnings("deprecation") public static int getCoordinateScan(ArrayList 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; + if (aList == null) return 0; ArrayList tList = new ArrayList(); int rEUAmount = 0; @@ -1357,32 +1380,36 @@ if (aList == null) return 0; tList.add("Owned by: " + ((IGregTechTileEntity)tTileEntity).getOwnerName()); }} catch(Throwable e) {if (GregTech_API.DEBUG_MODE) GT_Log.log.catching(e);} try {if (tTileEntity instanceof ic2.api.crops.ICropTile) { - if (((ic2.api.crops.ICropTile)tTileEntity).getScanLevel() < 4) { + ICropTile crop = (ICropTile) tTileEntity; + CropCard card = crop.getCrop(); + + if (crop.getScanLevel() < 4) { rEUAmount+=10000; - ((ic2.api.crops.ICropTile)tTileEntity).setScanLevel((byte)4); + crop.setScanLevel((byte)4); } - if (((ic2.api.crops.ICropTile)tTileEntity).getID() >= 0 && ((ic2.api.crops.ICropTile)tTileEntity).getID() < ic2.api.crops.Crops.instance.getCropList().length && ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile)tTileEntity).getID()] != null) { + if (card != null) { rEUAmount+=1000; - tList.add("Type -- Crop-Name: " + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile)tTileEntity).getID()].name() - + " Growth: " + ((ic2.api.crops.ICropTile)tTileEntity).getGrowth() - + " Gain: " + ((ic2.api.crops.ICropTile)tTileEntity).getGain() - + " Resistance: " + ((ic2.api.crops.ICropTile)tTileEntity).getResistance() + tList.add("Type -- Crop-Name: " + card.name() + + " Growth: " + crop.getGrowth() + + " Gain: " + crop.getGain() + + " Resistance: " + crop.getResistance() ); - tList.add("Plant -- Fertilizer: " + ((ic2.api.crops.ICropTile)tTileEntity).getNutrientStorage() - + " Water: " + ((ic2.api.crops.ICropTile)tTileEntity).getHydrationStorage() - + " Weed-Ex: " + ((ic2.api.crops.ICropTile)tTileEntity).getWeedExStorage() - + " Scan-Level: " + ((ic2.api.crops.ICropTile)tTileEntity).getScanLevel() + tList.add("Plant -- Fertilizer: " + crop.getNutrientStorage() + + " Water: " + crop.getHydrationStorage() + + " Weed-Ex: " + crop.getWeedExStorage() + + " Scan-Level: " + crop.getScanLevel() ); - tList.add("Environment -- Nutrients: " + ((ic2.api.crops.ICropTile)tTileEntity).getNutrients() - + " Humidity: " + ((ic2.api.crops.ICropTile)tTileEntity).getHumidity() - + " Air-Quality: " + ((ic2.api.crops.ICropTile)tTileEntity).getAirQuality() + tList.add("Environment -- Nutrients: " + crop.getNutrients() + + " Humidity: " + crop.getHumidity() + + " Air-Quality: " + crop.getAirQuality() ); String tString = ""; - for (String tAttribute : ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile)tTileEntity).getID()].attributes()) { + for (String tAttribute : card.attributes()) tString += ", " + tAttribute; - } tList.add("Attributes:" + tString.replaceFirst(",", "")); - tList.add("Discovered by: " + ic2.api.crops.Crops.instance.getCropList()[((ic2.api.crops.ICropTile)tTileEntity).getID()].discoveredBy()); + tList.add("Discovered by: " + card.discoveredBy()); + if (!aWorld.isRemote && aPlayer.capabilities.isCreativeMode) + crop.setSize((byte) Math.min(crop.getSize() + 1, crop.getCrop().maxSize())); } }} catch(Throwable e) {if (GregTech_API.DEBUG_MODE) GT_Log.log.catching(e);} } diff --git a/src/main/java/gregtechmod/loaders/load/GT_ItemIterator.java b/src/main/java/gregtechmod/loaders/load/GT_ItemIterator.java index db63e45..28c425a 100644 --- a/src/main/java/gregtechmod/loaders/load/GT_ItemIterator.java +++ b/src/main/java/gregtechmod/loaders/load/GT_ItemIterator.java @@ -210,6 +210,7 @@ public class GT_ItemIterator implements Runnable { } else if (tName.equals("tile.TFRoots")) { GT_ModHandler.addPulverisationRecipe(new ItemStack(tItem, 1, 0), new ItemStack(Items.stick, 2), new ItemStack(Items.stick, 1), 30); GT_ModHandler.addSawmillRecipe(new ItemStack(tItem, 1, 0), new ItemStack(Items.stick, 4), new ItemStack(Items.stick, 2)); + RecipeMaps.SAWMILL.factory().EUt(30).duration(200).setShaped(true).input(new ItemStack(tItem, 1, 0)).input(GT_ModHandler.getWater(1000)).outputs(new ItemStack(Items.stick, 1)).buildAndRegister(); RecipeMaps.MAGIC_FUELS.factory().EUt(16).duration(2).input(new ItemStack(tItem, 1, 1)).output(new ItemStack(Items.stick, 4)).buildAndRegister(); } else if (tName.equals("item.liveRoot")) { RecipeMaps.MAGIC_FUELS.factory().EUt(16).duration(1).input(new ItemStack(tItem, 1, 0)).output(new ItemStack(Items.stick, 2)).buildAndRegister(); diff --git a/src/main/java/gregtechmod/loaders/postload/GT_CropLoader.java b/src/main/java/gregtechmod/loaders/postload/GT_CropLoader.java index bcfbe70..9aeeaf6 100644 --- a/src/main/java/gregtechmod/loaders/postload/GT_CropLoader.java +++ b/src/main/java/gregtechmod/loaders/postload/GT_CropLoader.java @@ -1,10 +1,19 @@ package gregtechmod.loaders.postload; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + import gregtechmod.api.GregTech_API; +import gregtechmod.api.enums.GT_Items; import gregtechmod.api.util.GT_BaseCrop; import gregtechmod.api.util.GT_Log; import gregtechmod.api.util.GT_OreDictUnificator; + import gregtechmod.common.items.GT_MetaItem_Material; +import ic2.api.crops.CropCard; + import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; @@ -27,11 +36,35 @@ public class GT_CropLoader implements Runnable { new GT_BaseCrop(134, "gt_crops.creeperweed" , "General Spaz" , GT_OreDictUnificator.get("dustGunpowder", 1) , null , null , 7, 4, 0, 1, 4, 3, 0, 5, 1, 3, new String[] {"Creeper", "Vine", "Explosive", "Fire", "Sulfur", "Saltpeter", "Coal"}); new GT_BaseCrop(135, "gt_crops.enderbloom" , "RichardG" , GT_OreDictUnificator.get("dustEnderPearl", 1) , new ItemStack[] {new ItemStack(Items.ender_pearl, 1), new ItemStack(Items.ender_pearl , 1), new ItemStack(Items.ender_eye , 1)} , null ,10, 4, 0, 1, 4, 5, 0, 2, 1, 6, new String[] {"Ender", "Flower", "Shiny"}); new GT_BaseCrop(136, "gt_crops.meatrose" , "VintageBeef" , new ItemStack(Items.dye, 1, 9) , new ItemStack[] {new ItemStack(Items.beef, 1), new ItemStack(Items.porkchop , 1), new ItemStack(Items.chicken , 1), new ItemStack(Items.fish , 1)} , null , 7, 4, 1500, 1, 4, 0, 4, 1, 3, 0, new String[] {"Edible", "Flower", "Cow", "Fish", "Chicken", "Pig"}); - new GT_BaseCrop(137, "gt_crops.milkwart" , "Mr. Brain" , new ItemStack(Items.milk_bucket, 1) , null , null , 6, 3, 900, 1, 3, 0, 3, 0, 1, 0, new String[] {"Edible", "Milk", "Cow"}); + new GT_BaseCrop(137, "gt_crops.milkwart" , "Mr. Brain" , GT_Items.Crop_Drop_MilkWart.get(1) , null , null , 6, 3, 900, 1, 3, 0, 3, 0, 1, 0, new String[] {"Edible", "Milk", "Cow"}); new GT_BaseCrop(138, "gt_crops.slimeplant" , "Neowulf" , new ItemStack(Items.slime_ball, 1) , null , null , 6, 4, 0, 3, 4, 3, 0, 0, 0, 2, new String[] {"Slime", "Bouncy", "Sticky", "Bush"}); new GT_BaseCrop(139, "gt_crops.spidernip" , "Mr. Kenny" , new ItemStack(Items.string, 1) , new ItemStack[] {new ItemStack(Items.spider_eye, 1), new ItemStack(Blocks.web , 1)} , null , 4, 4, 600, 1, 4, 2, 1, 4, 1, 3, new String[] {"Toxic", "Silk", "Spider", "Flower", "Ingredient", "Addictive"}); new GT_BaseCrop(140, "gt_crops.tearstalks" , "Neowulf" , new ItemStack(Items.ghast_tear, 1) , null , null , 8, 4, 0, 1, 4, 1, 2, 0, 0, 0, new String[] {"Healing", "Nether", "Ingredient", "Reed", "Ghast"}); - new GT_BaseCrop(141, "gt_crops.tine" , "Gregorius Techneticies" , GT_OreDictUnificator.get("nuggetTin", 1) , null , null , 5, 3, 0, 2, 3, 2, 0, 3, 0, 0, new String[] {"Shiny", "Metal", "Pine", "Tin", "Bush"}); + new GT_BaseCrop(141, "gt_crops.tine" , "Gregorius Techneticies" , GT_Items.Crop_Drop_Tine.get(1) , null , null , 5, 3, 0, 2, 3, 2, 0, 3, 0, 0, new String[] {"Shiny", "Metal", "Pine", "Tin", "Bush"}); + + // Changing drop of default IC2 crops + GT_Log.log.info("Changing default IC2 crop loot"); + Map crops = new HashMap<>(); + + crops.put(ic2.core.crop.IC2Crops.cropPlumbiscus , GT_Items.Crop_Drop_Plumbilia .get(1)); + crops.put(ic2.core.crop.IC2Crops.cropShining , GT_Items.Crop_Drop_Argentia .get(1)); + crops.put(ic2.core.crop.IC2Crops.cropFerru , GT_Items.Crop_Drop_Ferru .get(1)); + crops.put(ic2.core.crop.IC2Crops.cropAurelia , GT_Items.Crop_Drop_Aurelia .get(1)); + crops.put(ic2.core.crop.IC2Crops.cropCyprium , GT_Items.Crop_Drop_Coppon .get(1)); + + for (Entry entry : crops.entrySet()) { + try { + Field f = entry.getKey().getClass().getDeclaredField("mDrop"); + f.setAccessible(true); + f.set(entry.getKey(), entry.getValue()); + } catch (Throwable e) { + GT_Log.log.error("Unable to change drop for IC2:" + entry.getKey().name()); + if (GregTech_API.DEBUG_MODE) { + GT_Log.log.catching(e); + } + } + } + } catch(Throwable e) { GT_Log.log.error("GT_Mod: Failed to register Crops to IC2."); if (GregTech_API.DEBUG_MODE) {