Skip to content

Commit

Permalink
Update JEI and add farming JEI Category
Browse files Browse the repository at this point in the history
  • Loading branch information
Nedelosk committed Jul 5, 2018
1 parent 8feb350 commit 1ee6c05
Show file tree
Hide file tree
Showing 37 changed files with 645 additions and 29 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Expand Up @@ -5,9 +5,9 @@ curse_project_id=59751

tesla_version=1.0.60
tesla_mcversion=1.12
jei_version=4.8.5.147
jei_version=4.10.0.200
jei_mcversion=1.12.2
ic2_version=2.8.24-ex112
ic2_version=2.8.90-ex112
TR_mcversion=1.12.2
TR_version=2.13.2.561
buildcraft_version=7.99.17
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/forestry/api/farming/IFarmCircuit.java
@@ -0,0 +1,8 @@
package forestry.api.farming;

import forestry.api.circuits.ICircuit;

public interface IFarmCircuit extends ICircuit {

IFarmLogic getFarmLogic();
}
7 changes: 6 additions & 1 deletion src/main/java/forestry/api/farming/IFarmLogic.java
Expand Up @@ -100,9 +100,14 @@ default IFarmProperties getProperties(){
return ForestryAPI.farmRegistry.createFakeInstance(this);
}

default boolean isManual(){
return false;
}

/**
* @deprecated Since Forestry 5.8 logic instances are created at the constructor of the {@link IFarmProperties} and
* have a immutable manual state. TODO Remove this method in 1.13
* have a immutable manual state.
* TODO Remove this method in 1.13
*/
@Deprecated
default IFarmLogic setManual(boolean manual){
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/forestry/api/farming/IFarmProperties.java
Expand Up @@ -22,6 +22,14 @@ default void registerSoil(ItemStack resource, IBlockState soilState){
*/
void registerSoil(ItemStack resource, IBlockState soilState, boolean hasMetaData);

void addGermlings(ItemStack... germlings);

void addGermlings(Collection<ItemStack> germlings);

void addProducts(ItemStack... products);

void addProducts(Collection<ItemStack> products);

/**
* Adds the {@link IFarmable}s that where registered with the given identifier.
*/
Expand All @@ -41,6 +49,8 @@ default void registerSoil(ItemStack resource, IBlockState soilState){

Collection<IFarmable> getFarmables();

Collection<IFarmableInfo> getFarmableInfo();

/**
* Returns the instance of the manual or managed {@link IFarmLogic}.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/forestry/api/farming/IFarmRegistry.java
Expand Up @@ -48,6 +48,8 @@ public interface IFarmRegistry {
void registerFarmables(String identifier, IFarmable... farmable);

Collection<IFarmable> getFarmables(String identifier);

IFarmableInfo getFarmableInfo(String identifier);

/**
* Can be used to create a simple version of a farm logic, like the vanilla vegetable or wheat farm logic.
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/forestry/api/farming/IFarmable.java
Expand Up @@ -45,6 +45,9 @@ default boolean isSaplingAt(World world, BlockPos pos, IBlockState blockState){
*/
boolean isGermling(ItemStack itemstack);

default void addInformation(IFarmableInfo info){
}

/**
* @return true if the item is something that can drop from this type without actually being harvested as a crop. (Apples or sapling from decaying leaves.)
*/
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/forestry/api/farming/IFarmableInfo.java
@@ -0,0 +1,40 @@
package forestry.api.farming;

import java.util.Arrays;
import java.util.Collection;

import net.minecraft.item.ItemStack;

/**
* IFarmableInfo describes the valid germlings and possible products of an IFarmable. This is mainly used by the jei farming
* category to display the valid germlings and possible products.
*/
public interface IFarmableInfo {

/***
* @return The identifier of the IFarmable.
*/
String getIdentifier();

default void addGermlings(ItemStack... germlings){
addGermlings(Arrays.asList(germlings));
}

void addGermlings(Collection<ItemStack> germlings);

/**
* @return a collection that contains all valid germlings of a farmable.
*/
Collection<ItemStack> getGermlings();

default void addProducts(ItemStack... products){
addProducts(Arrays.asList(products));
}

void addProducts(Collection<ItemStack> products);

/**
* @return a collection that contains all possible products of a farmable.
*/
Collection<ItemStack> getProducts();
}
Expand Up @@ -26,8 +26,8 @@ public class CharcoalPileWallCategory extends ForestryRecipeCategory<CharcoalPil
private final IDrawableAnimated flameAnimated;

public CharcoalPileWallCategory(IGuiHelper helper) {
super(helper.createBlankDrawable(120, 38), "tile.for.charcoal.pile.wall.name");
ResourceLocation resourceLocation = new ResourceLocation(Constants.MOD_ID, "textures/gui/jei/charcoal_pile_wall.png");
super(helper.createBlankDrawable(120, 38), "for.jei.charcoal.pile.name");
ResourceLocation resourceLocation = new ResourceLocation(Constants.MOD_ID, "textures/gui/jei/recipes.png");
arrow = helper.createDrawable(resourceLocation, 0, 14, 22, 16);
IDrawableStatic arrowAnimated = helper.createDrawable(resourceLocation, 22, 14, 22, 16);
this.arrowAnimated = helper.createAnimatedDrawable(arrowAnimated, 160, StartDirection.LEFT, false);
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/forestry/core/circuits/SolderManager.java
Expand Up @@ -10,15 +10,18 @@
******************************************************************************/
package forestry.core.circuits;

import com.google.common.base.Preconditions;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.common.base.Preconditions;
import net.minecraft.item.ItemStack;

import forestry.api.circuits.ICircuit;
import forestry.api.circuits.ICircuitLayout;
import forestry.api.circuits.ISolderManager;
import net.minecraft.item.ItemStack;

public class SolderManager implements ISolderManager {
private static final List<CircuitRecipe> recipes = new ArrayList<>();
Expand All @@ -32,6 +35,10 @@ public void addRecipe(ICircuitLayout layout, ItemStack resource, ICircuit circui
recipes.add(new CircuitRecipe(layout, resource, circuit));
}

public static Collection<CircuitRecipe> getRecipes() {
return recipes;
}

@Nullable
public static ICircuit getCircuit(ICircuitLayout layout, ItemStack resource) {
CircuitRecipe circuitRecipe = getMatchingRecipe(layout, resource);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/forestry/farming/DummyFarmRegistry.java
Expand Up @@ -11,8 +11,10 @@
import forestry.api.farming.IFarmProperties;
import forestry.api.farming.IFarmRegistry;
import forestry.api.farming.IFarmable;
import forestry.api.farming.IFarmableInfo;
import forestry.api.farming.ISimpleFarmLogic;
import forestry.farming.logic.FakeFarmProperties;
import forestry.farming.logic.farmables.FarmableInfo;

public class DummyFarmRegistry implements IFarmRegistry {

Expand All @@ -32,6 +34,11 @@ public Collection<IFarmable> getFarmables(String identifier) {
return Collections.emptyList();
}

@Override
public IFarmableInfo getFarmableInfo(String identifier) {
return new FarmableInfo(identifier);
}

@Override
public IFarmProperties registerLogic(String identifier, IFarmProperties farmInstance) {
return null;
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/forestry/farming/FarmRegistry.java
Expand Up @@ -27,6 +27,7 @@
import forestry.api.farming.IFarmProperties;
import forestry.api.farming.IFarmRegistry;
import forestry.api.farming.IFarmable;
import forestry.api.farming.IFarmableInfo;
import forestry.api.farming.ISimpleFarmLogic;
import forestry.core.config.LocalizedConfiguration;
import forestry.core.utils.ItemStackUtil;
Expand All @@ -35,12 +36,14 @@
import forestry.farming.logic.FakeFarmProperties;
import forestry.farming.logic.FarmLogicSimple;
import forestry.farming.logic.FarmProperties;
import forestry.farming.logic.farmables.FarmableInfo;

public final class FarmRegistry implements IFarmRegistry {

private static final FarmRegistry INSTANCE = new FarmRegistry();

private final Multimap<String, IFarmable> farmables = HashMultimap.create();
private final Map<String, IFarmableInfo> farmableInfo = new LinkedHashMap<>();
private final Map<ItemStack, Integer> fertilizers = new LinkedHashMap<>();
private final Map<String, IFarmProperties> farmInstances = new HashMap<>();
private FertilizerConfig fertilizer = FertilizerConfig.DUMMY;
Expand All @@ -56,6 +59,10 @@ public void registerLogic(String identifier, IFarmLogic logic) {

@Override
public void registerFarmables(String identifier, IFarmable... farmablesArray) {
IFarmableInfo info = getFarmableInfo(identifier);
for(IFarmable farmable : farmablesArray){
farmable.addInformation(info);
}
farmables.putAll(identifier, Arrays.asList(farmablesArray));
}

Expand All @@ -64,6 +71,11 @@ public Collection<IFarmable> getFarmables(String identifier) {
return farmables.get(identifier);
}

@Override
public IFarmableInfo getFarmableInfo(String identifier) {
return farmableInfo.computeIfAbsent(identifier, FarmableInfo::new);
}

@Override
public IFarmLogic createCropLogic(IFarmProperties instance, boolean isManual, ISimpleFarmLogic simpleFarmLogic) {
return new FarmLogicSimple(instance, isManual, simpleFarmLogic);
Expand Down Expand Up @@ -97,7 +109,7 @@ public IFarmProperties registerLogic(String identifier, IFarmProperties farmInst
public IFarmProperties registerLogic(String identifier, BiFunction<IFarmProperties, Boolean, IFarmLogic> logicFactory, String... farmablesIdentifiers) {
Set<String> identifiers = new HashSet<>(Arrays.asList(farmablesIdentifiers));
identifiers.add(identifier);
IFarmProperties instance = new FarmProperties(logicFactory, identifiers);
IFarmProperties instance = new FarmProperties(logicFactory, identifiers, identifier);
farmInstances.put(identifier, instance);
return instance;
}
Expand Down
49 changes: 45 additions & 4 deletions src/main/java/forestry/farming/ModuleFarming.java
Expand Up @@ -21,6 +21,8 @@
import net.minecraft.block.BlockCrops;
import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockNetherWart;
import net.minecraft.block.BlockOldLog;
import net.minecraft.block.BlockPlanks;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
Expand All @@ -37,13 +39,19 @@
import net.minecraftforge.fml.relauncher.SideOnly;

import forestry.Forestry;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.arboriculture.IFruitProvider;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.ITreeRoot;
import forestry.api.arboriculture.TreeManager;
import forestry.api.circuits.ChipsetManager;
import forestry.api.circuits.CircuitSocketType;
import forestry.api.circuits.ICircuitLayout;
import forestry.api.core.ForestryAPI;
import forestry.api.farming.IFarmProperties;
import forestry.api.farming.IFarmRegistry;
import forestry.api.modules.ForestryModule;
import forestry.arboriculture.genetics.alleles.AlleleFruits;
import forestry.core.ModuleCore;
import forestry.core.blocks.BlockBogEarth;
import forestry.core.blocks.BlockRegistryCore;
Expand Down Expand Up @@ -136,10 +144,10 @@ public void preInit() {
}

registry.registerFarmables(ForestryFarmIdentifier.CROPS,
new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, BlockCrops.AGE, 7, 0),
new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, BlockCrops.AGE, 7, 0),
new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, BlockCrops.AGE, 7, 0),
new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, BlockBeetroot.BEETROOT_AGE, 3, 0));
new FarmableAgingCrop(new ItemStack(Items.WHEAT_SEEDS), Blocks.WHEAT, new ItemStack(Items.WHEAT), BlockCrops.AGE, 7, 0),
new FarmableAgingCrop(new ItemStack(Items.POTATO), Blocks.POTATOES, new ItemStack(Items.POTATO), BlockCrops.AGE, 7, 0),
new FarmableAgingCrop(new ItemStack(Items.CARROT), Blocks.CARROTS, new ItemStack(Items.CARROT), BlockCrops.AGE, 7, 0),
new FarmableAgingCrop(new ItemStack(Items.BEETROOT_SEEDS), Blocks.BEETROOTS, new ItemStack(Items.BEETROOT), BlockBeetroot.BEETROOT_AGE, 3, 0));

IBlockState plantedBrownMushroom = blocks.mushroom.getDefaultState().withProperty(BlockMushroom.VARIANT, BlockMushroom.MushroomType.BROWN);
registry.registerFarmables(ForestryFarmIdentifier.SHROOM, new FarmableVanillaMushroom(new ItemStack(Blocks.BROWN_MUSHROOM), plantedBrownMushroom, Blocks.BROWN_MUSHROOM_BLOCK));
Expand Down Expand Up @@ -192,6 +200,7 @@ public void doInit() {

IFarmRegistry registry = FarmRegistry.getInstance();
BlockRegistryCore coreBlocks = ModuleCore.getBlocks();
ItemRegistryCore coreItems = ModuleCore.getItems();

IFarmProperties arborealFarm = registry.registerLogic(ForestryFarmIdentifier.ARBOREAL, FarmLogicArboreal::new);
IFarmProperties cropsFarm = registry.registerLogic(ForestryFarmIdentifier.CROPS, FarmLogicCrops::new);
Expand All @@ -209,6 +218,7 @@ public void doInit() {
Circuits.farmArborealManual = new CircuitFarmLogic("manualArboreal", arborealFarm, true);
arborealFarm.registerSoil(new ItemStack(Blocks.DIRT), coreBlocks.humus.getDefaultState());
arborealFarm.registerSoil(new ItemStack(coreBlocks.humus), coreBlocks.humus.getDefaultState());
arborealFarm.addProducts(new ItemStack(Blocks.SAND));

Circuits.farmShroomManaged = new CircuitFarmLogic("managedShroom", mushroomFarm, false);
Circuits.farmShroomManual = new CircuitFarmLogic("manualShroom", mushroomFarm, true);
Expand All @@ -219,6 +229,7 @@ public void doInit() {
Circuits.farmPeatManaged = new CircuitFarmLogic("managedPeat", peatFarm, false);
Circuits.farmPeatManual = new CircuitFarmLogic("manualPeat", peatFarm, true);
peatFarm.registerSoil(coreBlocks.bogEarth.get(BlockBogEarth.SoilType.BOG_EARTH, 1), coreBlocks.bogEarth.getDefaultState());
peatFarm.addProducts(new ItemStack(coreItems.peat), new ItemStack(Blocks.DIRT));

Circuits.farmCropsManaged = new CircuitFarmLogic("managedCrops", cropsFarm, false);
Circuits.farmCropsManual = new CircuitFarmLogic("manualCrops", cropsFarm, true);
Expand All @@ -231,6 +242,14 @@ public void doInit() {

Circuits.farmOrchardManaged = new CircuitFarmLogic("managedOrchard", orchardFarm, false);
Circuits.farmOrchardManual = new CircuitFarmLogic("manualOrchard", orchardFarm, true);
/*for(IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles(EnumTreeChromosome.FRUITS)){
if(allele instanceof IAlleleFruit){
IAlleleFruit alleleFruit = (IAlleleFruit) allele;
IFruitProvider fruitProvider = alleleFruit.getProvider();
orchardFarm.addProducts(fruitProvider.getProducts().keySet());
orchardFarm.addProducts(fruitProvider.getSpecialty().keySet());
}
}*/

Circuits.farmSucculentManaged = new CircuitFarmLogic("managedSucculent", succulentFarm, false);
Circuits.farmSucculentManual = new CircuitFarmLogic("manualSucculent", succulentFarm, true);
Expand All @@ -246,6 +265,10 @@ public void doInit() {

Circuits.farmCocoaManaged = new CircuitFarmLogic("managedCocoa", cocoaFarm, false);
Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", cocoaFarm, true);
cocoaFarm.registerSoil(new ItemStack(Blocks.LOG, 1, 3),
Blocks.LOG.getDefaultState().withProperty(BlockOldLog.VARIANT, BlockPlanks.EnumType.JUNGLE));
cocoaFarm.addGermlings(new ItemStack(Items.DYE, 1, 3));
cocoaFarm.addProducts(new ItemStack(Items.DYE, 1, 3));

Circuits.farmEnderManaged = new CircuitFarmLogic("managedEnder", enderFarm, false);
Circuits.farmEnderManual = new CircuitFarmLogic("manualEnder", enderFarm, true);
Expand Down Expand Up @@ -346,6 +369,24 @@ public void registerRecipes() {
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.ENDER, 1), Circuits.farmEnderManual);
}

@Override
public void postInit() {
IFarmProperties orchardFarm = FarmRegistry.getInstance().getProperties(ForestryFarmIdentifier.ORCHARD);
if(orchardFarm != null && ModuleHelper.isEnabled(ForestryModuleUids.ARBORICULTURE)) {
ITreeRoot treeRoot = TreeManager.treeRoot;
if (treeRoot != null) {
for (ITree tree : treeRoot.getIndividualTemplates()) {
IFruitProvider fruitProvider = tree.getGenome().getFruitProvider();
if (fruitProvider != AlleleFruits.fruitNone.getProvider()) {
orchardFarm.addGermlings(treeRoot.getMemberStack(tree, EnumGermlingType.SAPLING));
orchardFarm.addProducts(fruitProvider.getProducts().keySet());
orchardFarm.addProducts(fruitProvider.getSpecialty().keySet());
}
}
}
}
}

@Override
public void getHiddenItems(List<ItemStack> hiddenItems) {
// mushrooms are a workaround for the farm and should not be obtainable
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/forestry/farming/circuits/CircuitFarmLogic.java
Expand Up @@ -13,12 +13,13 @@
import javax.annotation.Nullable;

import forestry.api.farming.FarmDirection;
import forestry.api.farming.IFarmCircuit;
import forestry.api.farming.IFarmHousing;
import forestry.api.farming.IFarmLogic;
import forestry.api.farming.IFarmProperties;
import forestry.core.circuits.Circuit;

public class CircuitFarmLogic extends Circuit {
public class CircuitFarmLogic extends Circuit implements IFarmCircuit {

private final IFarmLogic logic;
private boolean isManual = false;
Expand All @@ -44,10 +45,7 @@ public String getLocalizedName() {
return logic.getName();
}

/**
* @deprecated TODO: Remove this method in 1.13
*/
@Deprecated
@Override
public IFarmLogic getFarmLogic() {
return logic;
}
Expand Down

0 comments on commit 1ee6c05

Please sign in to comment.