Close #1859, Close #1858 Add Natura huge glowshrooms farm support

This commit is contained in:
Nedelosk committed 2018-02-17 15:54:49 +01:00
1 parent 89e8ec8e38
commit d43cc63367
6 files changed
+150 -61

No files matched your search

+2 -2
View File
@@ -69,8 +69,8 @@ import forestry.plugins.PluginNatura;
acceptedMinecraftVersions = "[1.12.2,1.13.0)",
dependencies = "required-after:forge@[14.23.0.2500,);"
+ "after:jei@[4.7.8.91,);"
+ "after:" + PluginIC2.modId + ";"
+ "after:" + PluginNatura.modId + ";"
+ "after:" + PluginIC2.MOD_ID + ";"
+ "after:" + PluginNatura.MOD_ID + ";"
+ "after:toughasnails;")
public class Forestry {
@@ -38,7 +38,7 @@ public class CropBasicIC2Crop extends Crop {
* @param tileEntity tile entity to be checked.
* @return true if there is an IC2 crop and false otherwise.
*/
@Optional.Method(modid = PluginIC2.modId)
@Optional.Method(modid = PluginIC2.MOD_ID)
public static boolean isIC2Crop(TileEntity tileEntity) {
return tileEntity instanceof ICropTile;
}
@@ -49,7 +49,7 @@ public class CropBasicIC2Crop extends Crop {
* @param tileEntity tile entity to be checked.
* @return true if crop size is optimal for harvest and false otherwise.
*/
@Optional.Method(modid = PluginIC2.modId)
@Optional.Method(modid = PluginIC2.MOD_ID)
public static boolean canHarvestCrop(TileEntity tileEntity) {
if (isIC2Crop(tileEntity)) {
ICropTile crop = (ICropTile) tileEntity;
@@ -70,7 +70,7 @@ public class CropBasicIC2Crop extends Crop {
* @param tileEntity tile entity to be checked.
* @return list containing the drops.
*/
@Optional.Method(modid = PluginIC2.modId)
@Optional.Method(modid = PluginIC2.MOD_ID)
private static NonNullList<ItemStack> getCropDrops(TileEntity tileEntity) {
if (isIC2Crop(tileEntity)) {
ICropTile crop = (ICropTile) tileEntity;
@@ -22,7 +22,7 @@ public class FarmableBasicIC2Crop implements IFarmable {
/**
* Perform some of the actions of the crop-matron.
*/
@Optional.Method(modid = PluginIC2.modId)
@Optional.Method(modid = PluginIC2.MOD_ID)
public static void babysitCrop(TileEntity tileEntity) {
if (CropBasicIC2Crop.isIC2Crop(tileEntity)) {
ICropTile crop = (ICropTile) tileEntity;
@@ -12,11 +12,13 @@ package forestry.farming.logic.farmables;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import forestry.api.farming.ICrop;
import forestry.core.utils.BlockUtil;
import forestry.farming.logic.crops.CropDestroy;
public class FarmableVanillaMushroom extends FarmableBase {
@@ -35,4 +37,12 @@ public class FarmableVanillaMushroom extends FarmableBase {
return new CropDestroy(world, blockState, pos, null);
}
@Override
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
if(!plantedState.getBlock().canPlaceBlockAt(world, pos)) {
return false;
}
return BlockUtil.setBlockWithPlaceSound(world, pos, plantedState);
}
}
@@ -71,7 +71,7 @@ import ic2.api.recipe.Recipes;
@SuppressWarnings("unused")
@ForestryModule(containerID = ForestryCompatPlugins.ID, moduleID = ForestryModuleUids.INDUSTRIALCRAFT2, name = "IndustrialCraft2", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.module.ic2.description")
public class PluginIC2 extends BlankForestryModule {
public static final String modId = "ic2";
public static final String MOD_ID = "ic2";
@Nullable
private static ItemStack rubberSapling;
@@ -89,7 +89,7 @@ public class PluginIC2 extends BlankForestryModule {
@Override
public boolean isAvailable() {
return ModUtil.isModLoaded(PluginIC2.modId);
return ModUtil.isModLoaded(PluginIC2.MOD_ID);
}
@Override
@@ -108,7 +108,7 @@ public class PluginIC2 extends BlankForestryModule {
}
@Override
@Optional.Method(modid = PluginIC2.modId)
@Optional.Method(modid = PluginIC2.MOD_ID)
public void preInit() {
// rubber chain
rubberWood = IC2Items.getItem("rubber_wood");
@@ -130,7 +130,7 @@ public class PluginIC2 extends BlankForestryModule {
}
@Override
@Optional.Method(modid = PluginIC2.modId)
@Optional.Method(modid = PluginIC2.MOD_ID)
public void doInit() {
// Remove some items from the recycler
if (Recipes.recyclerBlacklist != null) {
@@ -210,7 +210,7 @@ public class PluginIC2 extends BlankForestryModule {
}
@Override
@Optional.Method(modid = PluginIC2.modId)
@Optional.Method(modid = PluginIC2.MOD_ID)
public void registerRecipes() {
ItemRegistryCore coreItems = ModuleCore.items;
+129 -50
View File
@@ -31,9 +31,11 @@ import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;
import forestry.api.core.ForestryAPI;
import forestry.api.farming.IFarmProperties;
import forestry.api.farming.IFarmRegistry;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.MoistenerFuel;
import forestry.api.modules.ForestryModule;
@@ -43,6 +45,7 @@ import forestry.api.storage.StorageManager;
import forestry.core.ModuleCore;
import forestry.core.config.Constants;
import forestry.core.fluids.Fluids;
import forestry.core.items.ItemRegistryCore;
import forestry.core.recipes.RecipeUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
@@ -50,6 +53,7 @@ import forestry.core.utils.ModUtil;
import forestry.farming.FarmRegistry;
import forestry.farming.logic.farmables.FarmableAgingCrop;
import forestry.farming.logic.farmables.FarmableSapling;
import forestry.farming.logic.farmables.FarmableVanillaMushroom;
import forestry.modules.BlankForestryModule;
import forestry.modules.ForestryModuleUids;
@@ -57,19 +61,26 @@ import forestry.modules.ForestryModuleUids;
@ForestryModule(containerID = ForestryCompatPlugins.ID, moduleID = ForestryModuleUids.NATURA, name = "Natura", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.module.natura.description")
public class PluginNatura extends BlankForestryModule {
public static final String modId = "natura";
public static final String MOD_ID = "natura";
private static ArrayList<ItemStack> fruits = new ArrayList<>();
private static ArrayList<ItemStack> soups = new ArrayList<>();
private static ArrayList<ItemStack> berries = new ArrayList<>();
private static ArrayList<ItemStack> edibles = new ArrayList<>();
private static ArrayList<ItemStack> seeds = new ArrayList<>();
private static ArrayList<ItemStack> logs = new ArrayList<>();
private static ArrayList<ItemStack> saplings = new ArrayList<>();
private static ArrayList<ItemStack> shrooms = new ArrayList<>();
private static ArrayList<ItemStack> materials = new ArrayList<>();
private static ArrayList<ItemStack> crops = new ArrayList<>();
private static ArrayList<ItemStack> cropBlocks = new ArrayList<>();
@ObjectHolder("natura:nether_green_large_glowshroom")
private static final Block greenLargeGlowshroomBlock = null;
@ObjectHolder("natura:nether_blue_large_glowshroom")
private static final Block blueLargeGlowshroomBlock = null;
@ObjectHolder("natura:nether_purple_large_glowshroom")
private static final Block purpleLargeGlowshroomBlock = null;
private static final ArrayList<ItemStack> fruits = new ArrayList<>();
private static final ArrayList<ItemStack> soups = new ArrayList<>();
private static final ArrayList<ItemStack> berries = new ArrayList<>();
private static final ArrayList<ItemStack> edibles = new ArrayList<>();
private static final ArrayList<ItemStack> seeds = new ArrayList<>();
private static final ArrayList<ItemStack> logs = new ArrayList<>();
private static final ArrayList<ItemStack> saplings = new ArrayList<>();
private static final ArrayList<ItemStack> shrooms = new ArrayList<>();
private static final ArrayList<ItemStack> materials = new ArrayList<>();
private static final ArrayList<ItemStack> crops = new ArrayList<>();
private static final ArrayList<ItemStack> cropBlocks = new ArrayList<>();
public PluginNatura() {
super();
@@ -78,7 +89,7 @@ public class PluginNatura extends BlankForestryModule {
@Override
public boolean isAvailable() {
return ModUtil.isModLoaded(modId);
return ModUtil.isModLoaded(MOD_ID);
}
@Override
@@ -88,42 +99,84 @@ public class PluginNatura extends BlankForestryModule {
@SubscribeEvent
public void registerItems(RegistryEvent<Item> itemRegistryEvent) {
final ItemStack potashApple = findPotashAppleInRegistry();
boolean hasMushroom = blueLargeGlowshroomBlock != null && greenLargeGlowshroomBlock != null && purpleLargeGlowshroomBlock != null;
ForgeRegistries.ITEMS.forEach(item -> {
final ResourceLocation registryName = item.getRegistryName();
if(!registryName.getResourceDomain().equals(modId)) return;
if (registryName == null || !registryName.getResourceDomain().equals(MOD_ID)) {
return;
}
final String itemName = registryName.getResourcePath();
if(itemName.matches("^.*_sapling\\d?$")) {
if (itemName.matches("^.*_sapling\\d?$")) {
consumeSubItems(item, "saplings", saplings);
RecipeUtil.addFermenterRecipes(
new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE),
ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"),
Fluids.BIOMASS
new ItemStack(item, 1, OreDictionary.WILDCARD_VALUE),
ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.sapling"),
Fluids.BIOMASS
);
ItemStack[] windfall = new ItemStack[]{};
// add potash apple as windfall for darkwood (nether_sapling:2)
if (itemName.endsWith("nether_sapling")) {
windfall = new ItemStack[]{potashApple};
}
FarmRegistry.getInstance().registerFarmables("farmArboreal", new FarmableSapling(
new ItemStack(item),
new ItemStack[] {}
new ItemStack(item),
windfall
));
return;
}
if(itemName.matches("^edibles|.*fruit_item|soups$")) {
if (hasMushroom && itemName.matches("^.*nether_glowshroom\\d?$")) {
complexConsumeSubItems(item, "shrooms", subItem -> {
shrooms.add(subItem);
// find large shroom block that matches subItem
final Block largeShroomBlock;
if (subItem.getMetadata() == blueLargeGlowshroomBlock.damageDropped(blueLargeGlowshroomBlock.getDefaultState())) {
largeShroomBlock = blueLargeGlowshroomBlock;
} else if (subItem.getMetadata() == greenLargeGlowshroomBlock.damageDropped(greenLargeGlowshroomBlock.getDefaultState())) {
largeShroomBlock = greenLargeGlowshroomBlock;
} else {
largeShroomBlock = purpleLargeGlowshroomBlock;
}
// block representing planted glowshroom
final Block smallShroomBlock = Block.getBlockFromItem(subItem.getItem());
FarmRegistry.getInstance().registerFarmables("farmShroom", new FarmableVanillaMushroom(
subItem,
smallShroomBlock.getStateFromMeta(subItem.getMetadata()),
largeShroomBlock
));
});
return;
}
if (itemName.matches("^edibles|.*fruit_item|soups$")) {
complexConsumeSubItems(item, "edibles", subitem -> {
final String subItemName = subitem.getUnlocalizedName();
if(subItemName.matches("^.*berry$")) {
if (subItemName.matches("^.*berry$")) {
berries.add(subitem);
return;
}
if(subItemName.matches("^.*(fruit_item|apple)$")) {
if (subItemName.matches("^.*(fruit_item|apple)$")) {
fruits.add(subitem);
return;
}
if(subItemName.matches("^.*stew$")) {
if (subItemName.matches("^.*stew$")) {
soups.add(subitem);
return;
}
@@ -132,22 +185,22 @@ public class PluginNatura extends BlankForestryModule {
});
}
if(itemName.matches("^.*_seeds$")) {
if (itemName.matches("^.*_seeds$")) {
consumeSubItems(item, "seeds", seeds);
return;
}
if(itemName.matches("^.*_logs\\d?$")) {
if (itemName.matches("^.*_logs\\d?$")) {
consumeSubItems(item, "logs", logs);
return;
}
if(itemName.matches("^.*_crop\\d?$")) {
if (itemName.matches("^.*_crop\\d?$")) {
consumeSubItems(item, "cropBlocks", cropBlocks);
return;
}
if(itemName.matches("^materials$")) {
if (itemName.matches("^materials$")) {
complexConsumeSubItems(item, "materials", subitem -> {
final String subItemName = subitem.getUnlocalizedName();
@@ -162,7 +215,7 @@ public class PluginNatura extends BlankForestryModule {
}
private void consumeSubItems(Item item, String groupName, Collection<ItemStack> consumer) {
complexConsumeSubItems(item, groupName, subItem -> consumer.add(subItem));
complexConsumeSubItems(item, groupName, consumer::add);
}
private void complexConsumeSubItems(Item item, String groupName, Consumer<ItemStack> consumer) {
@@ -170,7 +223,7 @@ public class PluginNatura extends BlankForestryModule {
item.getSubItems(CreativeTabs.SEARCH, subItems);
// Fallback if item is not returned in sub items
if(subItems.isEmpty()) {
if (subItems.isEmpty()) {
final ItemStack itemStack = new ItemStack(item, 1);
final String subItemName = itemStack.getUnlocalizedName();
Log.info("[PluginNatura] Adding '{}' to list of {}", subItemName, groupName);
@@ -185,15 +238,32 @@ public class PluginNatura extends BlankForestryModule {
});
}
private ItemStack findPotashAppleInRegistry() {
Item edibleItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(MOD_ID, "edibles"));
if (edibleItem != null) {
NonNullList<ItemStack> edibleSubItems = NonNullList.create();
edibleItem.getSubItems(CreativeTabs.SEARCH, edibleSubItems);
for (ItemStack edibleSubItem : edibleSubItems) {
if (edibleSubItem.getUnlocalizedName().endsWith("potashapple")) {
return edibleSubItem;
}
}
}
return ItemStack.EMPTY;
}
@SuppressWarnings("unchecked")
@Override
public void registerCrates() {
ICrateRegistry crateRegistry = StorageManager.crateRegistry;
Iterables.concat(
edibles, logs, saplings, shrooms,
materials, seeds, berries, fruits,
crops
).forEach(item -> crateRegistry.registerCrate(item));
edibles, logs, saplings, shrooms,
materials, seeds, berries, fruits,
crops
).forEach(crateRegistry::registerCrate);
}
@Override
@@ -210,7 +280,7 @@ public class PluginNatura extends BlankForestryModule {
ItemStack seedItem;
int maxAge;
try {
maxAge = (int)block.getClass().getDeclaredMethod("getMaxAge").invoke(block);
maxAge = (int) block.getClass().getDeclaredMethod("getMaxAge").invoke(block);
seedItem = block.getPickBlock(block.getBlockState().getBaseState(), null, null, null, null);
} catch (Exception ignored) {
return;
@@ -224,20 +294,22 @@ public class PluginNatura extends BlankForestryModule {
new FarmableAgingCrop(
seedItem,
block,
(IProperty<Integer>)block.getBlockState().getProperty("age"),
(IProperty<Integer>) block.getBlockState().getProperty("age"),
maxAge
)
);
});
}
ItemRegistryCore coreItems = ModuleCore.getItems();
amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 2;
final int juiceAmount = Math.max(amount, 1); // Produce at least 1 mb of juice.
ItemStack mulch = ModuleCore.items.mulch.getItemStack();
ItemStack mulch = coreItems.mulch.getItemStack();
fruits.forEach(fruit -> RecipeManagers.squeezerManager.addRecipe(
10, NonNullList.from(fruit, fruit),
Fluids.JUICE.getFluid(juiceAmount), mulch,
ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple"))
10, NonNullList.from(fruit, fruit),
Fluids.JUICE.getFluid(juiceAmount), mulch,
ForestryAPI.activeMode.getIntegerSetting("squeezer.mulch.apple"))
);
amount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.apple") / 25;
@@ -249,28 +321,35 @@ public class PluginNatura extends BlankForestryModule {
crops.forEach(crop -> {
RecipeUtil.addFermenterRecipes(crop, ForestryAPI.activeMode.getIntegerSetting("fermenter.yield.wheat"), Fluids.BIOMASS);
if (crop.getUnlocalizedName().matches("^.*cotton$")) return;
if (crop.getUnlocalizedName().matches("^.*cotton$")) {
return;
}
int compostWheatAmount = ForestryAPI.activeMode.getIntegerSetting("recipe.output.compost.wheat");
if (compostWheatAmount > 0) {
ItemStack compostWheat = ModuleCore.items.fertilizerCompound.getItemStack(compostWheatAmount);
ItemStack compostWheat = coreItems.fertilizerCompound.getItemStack(compostWheatAmount);
RecipeUtil.addRecipe(compostWheat.getUnlocalizedName(), compostWheat, " X ", "X#X", " X ", '#', Blocks.DIRT, 'X', crop);
}
FuelManager.moistenerResource.put(crop, new MoistenerFuel(crop, ModuleCore.items.mouldyWheat.getItemStack(), 0, 300));
FuelManager.moistenerResource.put(crop, new MoistenerFuel(crop, coreItems.mouldyWheat.getItemStack(), 0, 300));
});
}
/*
* Register soils required by Natura trees. Must run in postInit(), after core PluginFarming has registered FarmingLogic instances
*/
@Override
public void postInit() {
IFarmProperties farmArboreal = FarmRegistry.getInstance().getProperties("managedArboreal");
if(farmArboreal != null) {
farmArboreal.registerSoil(new ItemStack(Blocks.NETHERRACK), Blocks.NETHERRACK.getDefaultState(), false);
IFarmRegistry registry = FarmRegistry.getInstance();
IFarmProperties mushroomFarm = registry.getProperties("farmShroom");
IFarmProperties farmArboreal = registry.getProperties("farmArboreal");
if (farmArboreal != null) {
farmArboreal.registerSoil(new ItemStack(Blocks.NETHERRACK), Blocks.NETHERRACK.getDefaultState());
}
if(mushroomFarm != null){
mushroomFarm.registerSoil(new ItemStack(Blocks.NETHERRACK), Blocks.NETHERRACK.getDefaultState());
mushroomFarm.registerSoil(new ItemStack(Blocks.SOUL_SAND), Blocks.SOUL_SAND.getDefaultState());
}
}
}