mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 23:03:18 +00:00
Update for 1.11. Missing assets, unstable.
This commit is contained in:
1 parent
30d7365518
commit
9611ae08ae
1145 files changed
+15561
-18107
No files matched your search
@@ -10,36 +10,19 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming;
|
||||
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.block.BlockBeetroot;
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.block.BlockNetherWart;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.Forestry;
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
@@ -47,12 +30,13 @@ import forestry.api.circuits.ICircuitLayout;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.circuits.Circuit;
|
||||
import forestry.core.circuits.CircuitLayout;
|
||||
import forestry.core.circuits.Circuits;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.config.LocalizedConfiguration;
|
||||
import forestry.core.items.EnumElectronTube;
|
||||
import forestry.core.items.ItemRegistryCore;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
@@ -90,14 +74,32 @@ import forestry.farming.triggers.FarmingTriggers;
|
||||
import forestry.plugins.BlankForestryPlugin;
|
||||
import forestry.plugins.ForestryPlugin;
|
||||
import forestry.plugins.ForestryPluginUids;
|
||||
import net.minecraft.block.BlockBeetroot;
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.block.BlockNetherWart;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
@ForestryPlugin(pluginID = ForestryPluginUids.FARMING, name = "Farming", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.farming.description")
|
||||
public class PluginFarming extends BlankForestryPlugin {
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@SidedProxy(clientSide = "forestry.farming.proxy.ProxyFarmingClient", serverSide = "forestry.farming.proxy.ProxyFarming")
|
||||
public static ProxyFarming proxy;
|
||||
public static int modelIdFarmBlock;
|
||||
|
||||
@Nullable
|
||||
public static BlockRegistryFarming blocks;
|
||||
|
||||
@Override
|
||||
@@ -107,8 +109,10 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
|
||||
@Override
|
||||
public void preInit() {
|
||||
Preconditions.checkState(blocks != null);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
|
||||
Farmables.farmables.put("farmArboreal", new FarmableVanillaSapling());
|
||||
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.ARBORICULTURE)) {
|
||||
Farmables.farmables.put("farmArboreal", new FarmableGE());
|
||||
@@ -144,7 +148,7 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
|
||||
//Foretsry fertilizer
|
||||
Farmables.fertilizers.put(new ItemStack(PluginCore.items.fertilizerCompound, 1, OreDictionary.WILDCARD_VALUE), 500);
|
||||
|
||||
|
||||
proxy.initializeModels();
|
||||
|
||||
// Layouts
|
||||
@@ -153,8 +157,8 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
ICircuitLayout layoutManual = new CircuitLayout("farms.manual", CircuitSocketType.FARM);
|
||||
ChipsetManager.circuitRegistry.registerLayout(layoutManual);
|
||||
}
|
||||
|
||||
private void loadConfig(LocalizedConfiguration config){
|
||||
|
||||
private void loadConfig(LocalizedConfiguration config) {
|
||||
List<String> defaultFertilizers = new ArrayList<>(getItemStrings(Farmables.fertilizers));
|
||||
Collections.sort(defaultFertilizers);
|
||||
String[] defaultSortedFertilizers = defaultFertilizers.toArray(new String[defaultFertilizers.size()]);
|
||||
@@ -162,21 +166,20 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
|
||||
Farmables.fertilizers.clear();
|
||||
String[] fertilizerList = fertilizerConf.getStringList();
|
||||
for(int i = 0;i < fertilizerList.length;i++){
|
||||
try{
|
||||
for (int i = 0; i < fertilizerList.length; i++) {
|
||||
try {
|
||||
String fertilizer = fertilizerList[i];
|
||||
String[] fertilizers = fertilizer.split(";");
|
||||
ItemStack fertilizerItem = ItemStackUtil.parseItemStackString(fertilizers[0], OreDictionary.WILDCARD_VALUE);
|
||||
int fertilizerValue = Integer.parseInt(fertilizers[1]);
|
||||
Farmables.fertilizers.put(fertilizerItem, fertilizerValue);
|
||||
}catch(Exception e){
|
||||
} catch (Exception e) {
|
||||
Log.error("Forestry failed to parse a fertilizer entry at the farm config, at the position " + i + ".", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static Set<String> getItemStrings(LinkedHashMap<ItemStack, Integer> itemStacks) {
|
||||
private static Set<String> getItemStrings(Map<ItemStack, Integer> itemStacks) {
|
||||
Set<String> itemStrings = new HashSet<>(itemStacks.size());
|
||||
for (Entry<ItemStack, Integer> itemStack : itemStacks.entrySet()) {
|
||||
String itemString = ItemStackUtil.getStringForItemStack(itemStack.getKey());
|
||||
@@ -185,7 +188,7 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
}
|
||||
return itemStrings;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registerTriggers() {
|
||||
FarmingTriggers.initialize();
|
||||
@@ -194,7 +197,7 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
@Override
|
||||
public void doInit() {
|
||||
super.doInit();
|
||||
|
||||
|
||||
//Load config
|
||||
File configFile = new File(Forestry.instance.getConfigFolder(), Config.CATEGORY_FARM + ".cfg");
|
||||
LocalizedConfiguration config = new LocalizedConfiguration(configFile, "1.0.0");
|
||||
@@ -207,27 +210,30 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
GameRegistry.registerTileEntity(TileFarmValve.class, "forestry.FarmValve");
|
||||
GameRegistry.registerTileEntity(TileFarmControl.class, "forestry.FarmControl");
|
||||
|
||||
Circuit.farmArborealManaged = new CircuitFarmLogic("managedArboreal", new FarmLogicArboreal());
|
||||
Circuit.farmShroomManaged = new CircuitFarmLogic("managedShroom", new FarmLogicMushroom());
|
||||
Circuit.farmPeatManaged = new CircuitFarmLogic("managedPeat", new FarmLogicPeat());
|
||||
Circuit.farmCerealManaged = new CircuitFarmLogic("managedCereal", new FarmLogicCereal());
|
||||
Circuit.farmVegetableManaged = new CircuitFarmLogic("managedVegetable", new FarmLogicVegetable());
|
||||
Circuit.farmInfernalManaged = new CircuitFarmLogic("managedInfernal", new FarmLogicInfernal());
|
||||
Circuits.farmArborealManaged = new CircuitFarmLogic("managedArboreal", new FarmLogicArboreal());
|
||||
Circuits.farmShroomManaged = new CircuitFarmLogic("managedShroom", new FarmLogicMushroom());
|
||||
Circuits.farmPeatManaged = new CircuitFarmLogic("managedPeat", new FarmLogicPeat());
|
||||
Circuits.farmCerealManaged = new CircuitFarmLogic("managedCereal", new FarmLogicCereal());
|
||||
Circuits.farmVegetableManaged = new CircuitFarmLogic("managedVegetable", new FarmLogicVegetable());
|
||||
Circuits.farmInfernalManaged = new CircuitFarmLogic("managedInfernal", new FarmLogicInfernal());
|
||||
|
||||
Circuit.farmPeatManual = new CircuitFarmLogic("manualPeat", new FarmLogicPeat()).setManual();
|
||||
Circuit.farmShroomManual = new CircuitFarmLogic("manualShroom", new FarmLogicMushroom()).setManual();
|
||||
Circuit.farmCerealManual = new CircuitFarmLogic("manualCereal", new FarmLogicCereal()).setManual();
|
||||
Circuit.farmVegetableManual = new CircuitFarmLogic("manualVegetable", new FarmLogicVegetable()).setManual();
|
||||
Circuit.farmSucculentManual = new CircuitFarmLogic("manualSucculent", new FarmLogicSucculent()).setManual();
|
||||
Circuit.farmPoalesManual = new CircuitFarmLogic("manualPoales", new FarmLogicReeds()).setManual();
|
||||
Circuit.farmGourdManual = new CircuitFarmLogic("manualGourd", new FarmLogicGourd()).setManual();
|
||||
Circuit.farmCocoaManual = new CircuitFarmLogic("manualCocoa", new FarmLogicCocoa()).setManual();
|
||||
Circuits.farmPeatManual = new CircuitFarmLogic("manualPeat", new FarmLogicPeat()).setManual();
|
||||
Circuits.farmShroomManual = new CircuitFarmLogic("manualShroom", new FarmLogicMushroom()).setManual();
|
||||
Circuits.farmCerealManual = new CircuitFarmLogic("manualCereal", new FarmLogicCereal()).setManual();
|
||||
Circuits.farmVegetableManual = new CircuitFarmLogic("manualVegetable", new FarmLogicVegetable()).setManual();
|
||||
Circuits.farmSucculentManual = new CircuitFarmLogic("manualSucculent", new FarmLogicSucculent()).setManual();
|
||||
Circuits.farmPoalesManual = new CircuitFarmLogic("manualPoales", new FarmLogicReeds()).setManual();
|
||||
Circuits.farmGourdManual = new CircuitFarmLogic("manualGourd", new FarmLogicGourd()).setManual();
|
||||
Circuits.farmCocoaManual = new CircuitFarmLogic("manualCocoa", new FarmLogicCocoa()).setManual();
|
||||
|
||||
Circuit.farmOrchardManual = new CircuitFarmLogic("manualOrchard", new FarmLogicOrchard());
|
||||
Circuits.farmOrchardManual = new CircuitFarmLogic("manualOrchard", new FarmLogicOrchard());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipes() {
|
||||
ItemRegistryCore coreItems = PluginCore.items;
|
||||
Preconditions.checkState(blocks != null);
|
||||
Preconditions.checkState(coreItems != null);
|
||||
|
||||
ItemStack basic = blocks.farm.get(EnumFarmBlockType.PLAIN, 1);
|
||||
ItemStack gearbox = blocks.farm.get(EnumFarmBlockType.GEARBOX, 1);
|
||||
@@ -235,6 +241,7 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
ItemStack valve = blocks.farm.get(EnumFarmBlockType.VALVE, 1);
|
||||
ItemStack control = blocks.farm.get(EnumFarmBlockType.CONTROL, 1);
|
||||
|
||||
|
||||
for (EnumFarmBlockTexture block : EnumFarmBlockTexture.values()) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
block.saveToCompound(compound);
|
||||
@@ -250,7 +257,7 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
"WCW",
|
||||
'#', block.getBase(),
|
||||
'W', "slabWood",
|
||||
'C', PluginCore.items.tubes.get(EnumElectronTube.TIN, 1),
|
||||
'C', coreItems.tubes.get(EnumElectronTube.TIN, 1),
|
||||
'I', "ingotCopper");
|
||||
|
||||
RecipeUtil.addRecipe(gearbox,
|
||||
@@ -277,7 +284,7 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
" # ",
|
||||
"XTX",
|
||||
'#', basic,
|
||||
'T', PluginCore.items.tubes.get(EnumElectronTube.GOLD, 1),
|
||||
'T', coreItems.tubes.get(EnumElectronTube.GOLD, 1),
|
||||
'X', "dustRedstone");
|
||||
}
|
||||
|
||||
@@ -285,26 +292,28 @@ public class PluginFarming extends BlankForestryPlugin {
|
||||
ICircuitLayout layoutManaged = ChipsetManager.circuitRegistry.getLayout("forestry.farms.managed");
|
||||
ICircuitLayout layoutManual = ChipsetManager.circuitRegistry.getLayout("forestry.farms.manual");
|
||||
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.COPPER, 1), Circuit.farmArborealManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.TIN, 1), Circuit.farmPeatManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.BRONZE, 1), Circuit.farmCerealManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.IRON, 1), Circuit.farmVegetableManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.BLAZE, 1), Circuit.farmInfernalManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, PluginCore.items.tubes.get(EnumElectronTube.APATITE, 1), Circuit.farmShroomManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmArborealManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPeatManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCerealManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.IRON, 1), Circuits.farmVegetableManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.BLAZE, 1), Circuits.farmInfernalManaged);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManaged, coreItems.tubes.get(EnumElectronTube.APATITE, 1), Circuits.farmShroomManaged);
|
||||
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.COPPER, 1), Circuit.farmOrchardManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.TIN, 1), Circuit.farmPeatManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.BRONZE, 1), Circuit.farmCerealManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.IRON, 1), Circuit.farmVegetableManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.GOLD, 1), Circuit.farmSucculentManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.DIAMOND, 1), Circuit.farmPoalesManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuit.farmGourdManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.APATITE, 1), Circuit.farmShroomManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, PluginCore.items.tubes.get(EnumElectronTube.LAPIS, 1), Circuit.farmCocoaManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.COPPER, 1), Circuits.farmOrchardManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.TIN, 1), Circuits.farmPeatManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.BRONZE, 1), Circuits.farmCerealManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.IRON, 1), Circuits.farmVegetableManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.GOLD, 1), Circuits.farmSucculentManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.DIAMOND, 1), Circuits.farmPoalesManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.OBSIDIAN, 1), Circuits.farmGourdManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.APATITE, 1), Circuits.farmShroomManual);
|
||||
ChipsetManager.solderManager.addRecipe(layoutManual, coreItems.tubes.get(EnumElectronTube.LAPIS, 1), Circuits.farmCocoaManual);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void getHiddenItems(List<ItemStack> hiddenItems) {
|
||||
Preconditions.checkState(blocks != null);
|
||||
|
||||
// mushrooms are a workaround for the farm and should not be obtainable
|
||||
hiddenItems.add(new ItemStack(blocks.mushroom, 1, OreDictionary.WILDCARD_VALUE));
|
||||
}
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.blocks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
@@ -28,6 +30,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -43,8 +46,8 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import forestry.api.core.IModelManager;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.core.blocks.BlockStructure;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.core.blocks.properties.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.properties.UnlistedBlockPos;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.farming.models.EnumFarmBlockTexture;
|
||||
import forestry.farming.tiles.TileFarm;
|
||||
@@ -90,15 +93,14 @@ public class BlockFarm extends BlockStructure {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (i == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (EnumFarmBlockTexture block : EnumFarmBlockTexture.values()) {
|
||||
ItemStack stack = new ItemStack(item, 1, i);
|
||||
ItemStack stack = new ItemStack(itemIn, 1, i);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
block.saveToCompound(compound);
|
||||
stack.setTagCompound(compound);
|
||||
@@ -120,12 +122,14 @@ public class BlockFarm extends BlockStructure {
|
||||
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, pos, state, placer, stack);
|
||||
|
||||
if (!stack.hasTagCompound()) {
|
||||
if (stack.getTagCompound() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileFarm tile = (TileFarm) world.getTileEntity(pos);
|
||||
tile.setFarmBlockTexture(EnumFarmBlockTexture.getFromCompound(stack.getTagCompound()));
|
||||
TileFarm tile = TileUtil.getTile(world, pos, TileFarm.class);
|
||||
if (tile != null) {
|
||||
tile.setFarmBlockTexture(EnumFarmBlockTexture.getFromCompound(stack.getTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,7 +195,7 @@ public class BlockFarm extends BlockStructure {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) {
|
||||
public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, @Nullable EnumFacing side) {
|
||||
return state.getValue(META) == EnumFarmBlockType.CONTROL;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
@@ -158,12 +159,10 @@ public class BlockMushroom extends BlockBush implements IItemModelRegister, IGro
|
||||
this.generateGiantMushroom(worldIn, pos, state, rand);
|
||||
}
|
||||
|
||||
/* ICONS */
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list) {
|
||||
list.add(new ItemStack(item, 1, 0));
|
||||
list.add(new ItemStack(item, 1, 1));
|
||||
public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
|
||||
list.add(new ItemStack(itemIn, 1, 0));
|
||||
list.add(new ItemStack(itemIn, 1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.blocks;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.circuits;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
@@ -35,6 +37,7 @@ public class CircuitFarmLogic extends Circuit {
|
||||
return tile instanceof IFarmHousing;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private IFarmHousing getCircuitable(Object tile) {
|
||||
if (!isCircuitable(tile)) {
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.circuits;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
+70
-76
@@ -1,76 +1,70 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gui.widgets;
|
||||
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.farming.multiblock.IFarmControllerInternal;
|
||||
|
||||
public class FarmLogicSlot extends Widget {
|
||||
|
||||
private final IFarmControllerInternal farmController;
|
||||
private final FarmDirection farmDirection;
|
||||
|
||||
public FarmLogicSlot(IFarmControllerInternal farmController, WidgetManager manager, int xPos, int yPos, FarmDirection farmDirection) {
|
||||
super(manager, xPos, yPos);
|
||||
this.farmController = farmController;
|
||||
this.farmDirection = farmDirection;
|
||||
}
|
||||
|
||||
private IFarmLogic getLogic() {
|
||||
return farmController.getFarmLogic(farmDirection);
|
||||
}
|
||||
|
||||
private ItemStack getStackIndex() {
|
||||
if (getLogic() == null) {
|
||||
return null;
|
||||
}
|
||||
return getLogic().getIconItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
if (getStackIndex() != null) {
|
||||
Proxies.render.bindTexture(getLogic().getTextureMap());
|
||||
RenderItem renderItem = Proxies.common.getClientInstance().getRenderItem();
|
||||
renderItem.renderItemIntoGUI(getStackIndex(), startX + xPos, startY + yPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
if (isMouseOver(mouseX, mouseY)) {
|
||||
return toolTip;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected final ToolTip toolTip = new ToolTip(250) {
|
||||
@Override
|
||||
public void refresh() {
|
||||
toolTip.clear();
|
||||
if (getLogic() == null) {
|
||||
return;
|
||||
}
|
||||
toolTip.add(getLogic().getName());
|
||||
toolTip.add("Fertilizer: " + getLogic().getFertilizerConsumption());
|
||||
toolTip.add("Water: " + getLogic().getWaterConsumption(farmController.getFarmLedgerDelegate().getHydrationModifier()));
|
||||
}
|
||||
};
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gui;
|
||||
|
||||
import net.minecraft.client.renderer.RenderItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.farming.multiblock.IFarmControllerInternal;
|
||||
|
||||
public class FarmLogicSlot extends Widget {
|
||||
|
||||
private final IFarmControllerInternal farmController;
|
||||
private final FarmDirection farmDirection;
|
||||
|
||||
public FarmLogicSlot(IFarmControllerInternal farmController, WidgetManager manager, int xPos, int yPos, FarmDirection farmDirection) {
|
||||
super(manager, xPos, yPos);
|
||||
this.farmController = farmController;
|
||||
this.farmDirection = farmDirection;
|
||||
}
|
||||
|
||||
private IFarmLogic getLogic() {
|
||||
return farmController.getFarmLogic(farmDirection);
|
||||
}
|
||||
|
||||
private ItemStack getStackIndex() {
|
||||
return getLogic().getIconItemStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
if (!getStackIndex().isEmpty()) {
|
||||
Proxies.render.bindTexture(getLogic().getTextureMap());
|
||||
RenderItem renderItem = Proxies.common.getClientInstance().getRenderItem();
|
||||
renderItem.renderItemIntoGUI(getStackIndex(), startX + xPos, startY + yPos);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
if (isMouseOver(mouseX, mouseY)) {
|
||||
return toolTip;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected final ToolTip toolTip = new ToolTip(250) {
|
||||
@Override
|
||||
public void refresh() {
|
||||
toolTip.clear();
|
||||
toolTip.add(getLogic().getName());
|
||||
toolTip.add("Fertilizer: " + getLogic().getFertilizerConsumption());
|
||||
toolTip.add("Water: " + getLogic().getWaterConsumption(farmController.getFarmLedgerDelegate().getHydrationModifier()));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.ledgers.ClimateLedger;
|
||||
import forestry.core.gui.widgets.SocketWidget;
|
||||
import forestry.core.gui.widgets.TankWidget;
|
||||
import forestry.farming.gui.widgets.FarmLogicSlot;
|
||||
import forestry.farming.multiblock.IFarmControllerInternal;
|
||||
import forestry.farming.tiles.TileFarm;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.gui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -33,7 +33,7 @@ public class ItemBlockFarm extends ItemBlock {
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack itemstack, EntityPlayer player, List<String> info, boolean par4) {
|
||||
if (!itemstack.hasTagCompound()) {
|
||||
if (itemstack.getTagCompound() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.items;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -10,33 +10,30 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
|
||||
public abstract class Crop implements ICrop {
|
||||
|
||||
private final World world;
|
||||
protected final BlockPos position;
|
||||
|
||||
protected Crop(@Nonnull World world, @Nonnull BlockPos position) {
|
||||
protected Crop(World world, BlockPos position) {
|
||||
this.world = world;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
protected abstract boolean isCrop(World world, BlockPos pos);
|
||||
|
||||
protected abstract Collection<ItemStack> harvestBlock(World world, BlockPos pos);
|
||||
protected abstract NonNullList<ItemStack> harvestBlock(World world, BlockPos pos);
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Collection<ItemStack> harvest() {
|
||||
public NonNullList<ItemStack> harvest() {
|
||||
if (!isCrop(world, position)) {
|
||||
return null;
|
||||
}
|
||||
@@ -44,7 +41,6 @@ public abstract class Crop implements ICrop {
|
||||
return harvestBlock(world, position);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public BlockPos getPosition() {
|
||||
return position;
|
||||
|
||||
@@ -10,12 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -36,9 +34,10 @@ public class CropBasicAgriCraft extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Block block = blockState.getBlock();
|
||||
List<ItemStack> harvest = block.getDrops(world, pos, blockState, 0);
|
||||
NonNullList<ItemStack> harvest = NonNullList.create();
|
||||
harvest.addAll(block.getDrops(world, pos, blockState, 0));
|
||||
if (harvest.size() > 1) {
|
||||
harvest.remove(1); //AgriCraft returns cropsticks in 0, seeds in 1 in getDrops, removing since harvesting doesn't return them.
|
||||
}
|
||||
|
||||
@@ -10,12 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -42,15 +40,16 @@ public class CropBasicGrowthCraft extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Block block = blockState.getBlock();
|
||||
List<ItemStack> harvest = block.getDrops(world, pos, blockState, 0);
|
||||
NonNullList<ItemStack> harvest = NonNullList.create();
|
||||
harvest.addAll(block.getDrops(world, pos, blockState, 0));
|
||||
if (harvest.size() > 1) {
|
||||
harvest.remove(0); //Hops have rope as first drop.
|
||||
}
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, world);
|
||||
Proxies.net.sendNetworkPacket(packet, pos, world);
|
||||
|
||||
if (isGrape) {
|
||||
world.setBlockToAir(pos);
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
import forestry.plugins.compat.PluginIC2;
|
||||
|
||||
import ic2.api.crops.ICropTile;
|
||||
|
||||
public class CropBasicIC2Crop extends Crop {
|
||||
private final TileEntity tileEntity;
|
||||
|
||||
public CropBasicIC2Crop(@Nonnull World world, @Nonnull TileEntity tileEntity, @Nonnull BlockPos position) {
|
||||
super(world, position);
|
||||
this.tileEntity = tileEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(World world, BlockPos pos) {
|
||||
return canHarvestCrop(this.tileEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
return getCropDrops(this.tileEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is an instance of ICropTile.
|
||||
* @param tileEntity tile entity to be checked.
|
||||
* @return true if there is an IC2 crop and false otherwise.
|
||||
*/
|
||||
@Optional.Method(modid = PluginIC2.modId)
|
||||
public static boolean isIC2Crop(TileEntity tileEntity) {
|
||||
if (tileEntity instanceof ICropTile) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an IC2 crop is ready to be harvested.
|
||||
* @param tileEntity tile entity to be checked.
|
||||
* @return true if crop size is optimal for harvest and false otherwise.
|
||||
*/
|
||||
@Optional.Method(modid = PluginIC2.modId)
|
||||
public static boolean canHarvestCrop(TileEntity tileEntity) {
|
||||
if (isIC2Crop(tileEntity)) {
|
||||
ICropTile crop = (ICropTile) tileEntity;
|
||||
if (crop.getCrop() == null) {
|
||||
return false;
|
||||
}
|
||||
if (crop.getCurrentSize() == crop.getCrop().getOptimalHarvestSize(crop)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function takes care of everything related to the harvesting of the
|
||||
* crop meaning it will calculate the drops and also do setSizeAfterHarvest().
|
||||
* @param tileEntity tile entity to be checked.
|
||||
* @return list containing the drops.
|
||||
*/
|
||||
@Optional.Method(modid = PluginIC2.modId)
|
||||
private static List<ItemStack> getCropDrops(TileEntity tileEntity) {
|
||||
if (isIC2Crop(tileEntity)) {
|
||||
ICropTile crop = (ICropTile) tileEntity;
|
||||
return crop.performHarvest();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
//package forestry.farming.logic;
|
||||
//
|
||||
//import javax.annotation.Nonnull;
|
||||
//
|
||||
//import java.util.Collection;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import net.minecraft.item.ItemStack;
|
||||
//import net.minecraft.tileentity.TileEntity;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.world.World;
|
||||
//
|
||||
//import net.minecraftforge.fml.common.Optional;
|
||||
//
|
||||
//import forestry.plugins.compat.PluginIC2;
|
||||
//
|
||||
//import ic2.api.crops.ICropTile;
|
||||
//
|
||||
//public class CropBasicIC2Crop extends Crop {
|
||||
// private final TileEntity tileEntity;
|
||||
//
|
||||
// public CropBasicIC2Crop(@Nonnull World world, @Nonnull TileEntity tileEntity, @Nonnull BlockPos position) {
|
||||
// super(world, position);
|
||||
// this.tileEntity = tileEntity;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected boolean isCrop(World world, BlockPos pos) {
|
||||
// return canHarvestCrop(this.tileEntity);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
// return getCropDrops(this.tileEntity);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Check if there is an instance of ICropTile.
|
||||
// * @param tileEntity tile entity to be checked.
|
||||
// * @return true if there is an IC2 crop and false otherwise.
|
||||
// */
|
||||
// @Optional.Method(modid = PluginIC2.modId)
|
||||
// public static boolean isIC2Crop(TileEntity tileEntity) {
|
||||
// if (tileEntity instanceof ICropTile) {
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Check if an IC2 crop is ready to be harvested.
|
||||
// * @param tileEntity tile entity to be checked.
|
||||
// * @return true if crop size is optimal for harvest and false otherwise.
|
||||
// */
|
||||
// @Optional.Method(modid = PluginIC2.modId)
|
||||
// public static boolean canHarvestCrop(TileEntity tileEntity) {
|
||||
// if (isIC2Crop(tileEntity)) {
|
||||
// ICropTile crop = (ICropTile) tileEntity;
|
||||
// if (crop.getCrop() == null) {
|
||||
// return false;
|
||||
// }
|
||||
// if (crop.getCurrentSize() == crop.getCrop().getOptimalHarvestSize(crop)) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * This function takes care of everything related to the harvesting of the
|
||||
// * crop meaning it will calculate the drops and also do setSizeAfterHarvest().
|
||||
// * @param tileEntity tile entity to be checked.
|
||||
// * @return list containing the drops.
|
||||
// */
|
||||
// @Optional.Method(modid = PluginIC2.modId)
|
||||
// private static List<ItemStack> getCropDrops(TileEntity tileEntity) {
|
||||
// if (isIC2Crop(tileEntity)) {
|
||||
// ICropTile crop = (ICropTile) tileEntity;
|
||||
// return crop.performHarvest();
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
@@ -11,11 +11,11 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -41,12 +41,13 @@ public class CropDestroy extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Block block = blockState.getBlock();
|
||||
Collection<ItemStack> harvested = block.getDrops(world, pos, blockState, 0);
|
||||
NonNullList<ItemStack> harvested = NonNullList.create();
|
||||
harvested.addAll(block.getDrops(world, pos, blockState, 0));
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, world);
|
||||
Proxies.net.sendNetworkPacket(packet, pos, world);
|
||||
|
||||
if (replantState != null) {
|
||||
world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC);
|
||||
|
||||
@@ -10,12 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -47,16 +45,16 @@ public class CropFruit extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (!(tile instanceof IFruitBearer)) {
|
||||
return Collections.emptySet();
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, world);
|
||||
return ((IFruitBearer) tile).pickFruit(null);
|
||||
Proxies.net.sendNetworkPacket(packet, pos, world);
|
||||
return ((IFruitBearer) tile).pickFruit(ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,22 +10,18 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.PluginCore;
|
||||
import forestry.core.blocks.BlockBogEarth;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CropPeat extends Crop {
|
||||
|
||||
@@ -46,14 +42,14 @@ public class CropPeat extends Crop {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
List<ItemStack> drops = new ArrayList<>();
|
||||
protected NonNullList<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
NonNullList<ItemStack> drops = NonNullList.create();
|
||||
drops.add(PluginCore.items.peat.getItemStack());
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, world);
|
||||
Proxies.net.sendNetworkPacket(packet, pos, world);
|
||||
|
||||
world.setBlockState(pos, Blocks.DIRT.getDefaultState(), Constants.FLAG_BLOCK_SYNC);
|
||||
return drops;
|
||||
|
||||
@@ -1,94 +1,94 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.network.packets.PacketFXSignal;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.plugins.compat.PluginIC2;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class CropRubber extends CropDestroy {
|
||||
|
||||
public CropRubber(World world, IBlockState blockState, BlockPos position) {
|
||||
super(world, blockState, position, getReplantState(blockState));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a "wet" rubber log blockstate into the dry version.
|
||||
* Total hack since we don't have access to the blockstates.
|
||||
*/
|
||||
private static <T extends Comparable<T>> IBlockState getReplantState(IBlockState sappyState) {
|
||||
if (hasRubberToHarvest(sappyState)) {
|
||||
for (Map.Entry<IProperty<?>, Comparable<?>> wetPropertyEntry : sappyState.getProperties().entrySet()) {
|
||||
String valueWetString = wetPropertyEntry.getValue().toString();
|
||||
String valueDryString = valueWetString.replace("wet", "dry");
|
||||
IProperty<?> property = wetPropertyEntry.getKey();
|
||||
|
||||
IBlockState baseState = sappyState.getBlock().getBlockState().getBaseState();
|
||||
IBlockState dryState = getStateWithValue(baseState, property, valueDryString);
|
||||
if (dryState != null) {
|
||||
return dryState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sappyState.getBlock().getDefaultState();
|
||||
}
|
||||
|
||||
public static boolean hasRubberToHarvest(IBlockState blockState) {
|
||||
Block block = blockState.getBlock();
|
||||
if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
|
||||
ImmutableCollection<Comparable<?>> propertyValues = blockState.getProperties().values();
|
||||
for (Comparable<?> propertyValue : propertyValues) {
|
||||
if (propertyValue.toString().contains("wet")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static <T extends Comparable<T>> IBlockState getStateWithValue(IBlockState baseState, IProperty<T> property, String valueString) {
|
||||
Optional<T> value = property.parseValue(valueString);
|
||||
if (value.isPresent()) {
|
||||
return baseState.withProperty(property, value.get());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
Collection<ItemStack> harvested = new ArrayList<>();
|
||||
harvested.add(PluginIC2.resin.copy());
|
||||
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
Proxies.net.sendNetworkPacket(packet, world);
|
||||
|
||||
world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC);
|
||||
return harvested;
|
||||
}
|
||||
|
||||
}
|
||||
///*******************************************************************************
|
||||
// * Copyright (c) 2011-2014 SirSengir.
|
||||
// * All rights reserved. This program and the accompanying materials
|
||||
// * are made available under the terms of the GNU Lesser Public License v3
|
||||
// * which accompanies this distribution, and is available at
|
||||
// * http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// *
|
||||
// * Various Contributors including, but not limited to:
|
||||
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
// ******************************************************************************/
|
||||
//package forestry.farming.logic;
|
||||
//
|
||||
//import javax.annotation.Nullable;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.Collection;
|
||||
//import java.util.Map;
|
||||
//
|
||||
//import com.google.common.base.Optional;
|
||||
//import com.google.common.collect.ImmutableCollection;
|
||||
//import forestry.core.config.Constants;
|
||||
//import forestry.core.network.packets.PacketFXSignal;
|
||||
//import forestry.core.proxy.Proxies;
|
||||
//import forestry.core.utils.ItemStackUtil;
|
||||
//import forestry.plugins.compat.PluginIC2;
|
||||
//import net.minecraft.block.Block;
|
||||
//import net.minecraft.block.properties.IProperty;
|
||||
//import net.minecraft.block.state.IBlockState;
|
||||
//import net.minecraft.item.ItemStack;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.world.World;
|
||||
//
|
||||
//public class CropRubber extends CropDestroy {
|
||||
//
|
||||
// public CropRubber(World world, IBlockState blockState, BlockPos position) {
|
||||
// super(world, blockState, position, getReplantState(blockState));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Convert a "wet" rubber log blockstate into the dry version.
|
||||
// * Total hack since we don't have access to the blockstates.
|
||||
// */
|
||||
// private static <T extends Comparable<T>> IBlockState getReplantState(IBlockState sappyState) {
|
||||
// if (hasRubberToHarvest(sappyState)) {
|
||||
// for (Map.Entry<IProperty<?>, Comparable<?>> wetPropertyEntry : sappyState.getProperties().entrySet()) {
|
||||
// String valueWetString = wetPropertyEntry.getValue().toString();
|
||||
// String valueDryString = valueWetString.replace("wet", "dry");
|
||||
// IProperty<?> property = wetPropertyEntry.getKey();
|
||||
//
|
||||
// IBlockState baseState = sappyState.getBlock().getBlockState().getBaseState();
|
||||
// IBlockState dryState = getStateWithValue(baseState, property, valueDryString);
|
||||
// if (dryState != null) {
|
||||
// return dryState;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return sappyState.getBlock().getDefaultState();
|
||||
// }
|
||||
//
|
||||
// public static boolean hasRubberToHarvest(IBlockState blockState) {
|
||||
// Block block = blockState.getBlock();
|
||||
// if (ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
|
||||
// ImmutableCollection<Comparable<?>> propertyValues = blockState.getProperties().values();
|
||||
// for (Comparable<?> propertyValue : propertyValues) {
|
||||
// if (propertyValue.toString().contains("wet")) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// private static <T extends Comparable<T>> IBlockState getStateWithValue(IBlockState baseState, IProperty<T> property, String valueString) {
|
||||
// Optional<T> value = property.parseValue(valueString);
|
||||
// if (value.isPresent()) {
|
||||
// return baseState.withProperty(property, value.get());
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Collection<ItemStack> harvestBlock(World world, BlockPos pos) {
|
||||
// Collection<ItemStack> harvested = new ArrayList<>();
|
||||
// harvested.add(PluginIC2.resin.copy());
|
||||
//
|
||||
// PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.VisualFXType.BLOCK_BREAK, PacketFXSignal.SoundFXType.BLOCK_BREAK, pos, blockState);
|
||||
// Proxies.net.sendNetworkPacket(packet, world);
|
||||
//
|
||||
// world.setBlockState(pos, replantState, Constants.FLAG_BLOCK_SYNC);
|
||||
// return harvested;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -10,8 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
@@ -25,6 +24,7 @@ import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -48,23 +48,18 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
public ResourceLocation getTextureMap() {
|
||||
return TextureMap.LOCATION_BLOCKS_TEXTURE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public abstract ItemStack getIconItemStack();
|
||||
|
||||
public abstract boolean isAcceptedWindfall(ItemStack stack);
|
||||
|
||||
@Deprecated
|
||||
protected final boolean isAirBlock(@Nonnull Block block, @Nonnull IBlockState blockState, @Nonnull World world, @Nonnull BlockPos blockPos) {
|
||||
return block.isAir(blockState, world, blockPos);
|
||||
}
|
||||
|
||||
protected final boolean isWaterSourceBlock(World world, BlockPos position) {
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
return block == Blocks.WATER;
|
||||
}
|
||||
|
||||
|
||||
protected final BlockPos translateWithOffset(BlockPos pos, FarmDirection farmDirection, int step) {
|
||||
return VectUtil.scale(farmDirection.getFacing().getDirectionVec(), step).add(pos);
|
||||
}
|
||||
@@ -85,11 +80,11 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
return new AxisAlignedBB(min.getX(), min.getY(), min.getZ(), max.getX(), maxY, max.getZ());
|
||||
}
|
||||
|
||||
protected List<ItemStack> collectEntityItems(World world, IFarmHousing farmHousing, boolean toWorldHeight) {
|
||||
protected NonNullList<ItemStack> collectEntityItems(World world, IFarmHousing farmHousing, boolean toWorldHeight) {
|
||||
AxisAlignedBB harvestBox = getHarvestBox(world, farmHousing, toWorldHeight);
|
||||
|
||||
List<EntityItem> entityItems = world.getEntitiesWithinAABB(EntityItem.class, harvestBox, entitySelectorFarm);
|
||||
List<ItemStack> stacks = new ArrayList<>();
|
||||
NonNullList<ItemStack> stacks = NonNullList.create();
|
||||
for (EntityItem entity : entityItems) {
|
||||
ItemStack contained = entity.getEntityItem();
|
||||
stacks.add(contained.copy());
|
||||
@@ -106,8 +101,8 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(EntityItem entity) {
|
||||
if (entity.isDead) {
|
||||
public boolean apply(@Nullable EntityItem entity) {
|
||||
if (entity == null || entity.isDead) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -21,6 +22,7 @@ import java.util.Stack;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -61,8 +63,8 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
NonNullList<ItemStack> products = produce;
|
||||
produce = collectEntityItems(world, farmHousing, true);
|
||||
return products;
|
||||
}
|
||||
@@ -122,6 +124,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
return crops;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IFarmable getFarmableForBlock(World world, BlockPos position, Collection<IFarmable> farmables) {
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
for (IFarmable farmable : farmables) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -74,8 +75,8 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
private final Map<BlockPos, Integer> lastExtentsCultivation = new HashMap<>();
|
||||
@@ -146,10 +147,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
|
||||
private static boolean isJungleTreeTrunk(IBlockState blockState) {
|
||||
Block block = blockState.getBlock();
|
||||
if (block == Blocks.LOG && blockState.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.JUNGLE) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return block == Blocks.LOG && blockState.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.JUNGLE;
|
||||
}
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Stack;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -61,8 +62,8 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
NonNullList<ItemStack> products = produce;
|
||||
produce = collectEntityItems(world, farmHousing, false);
|
||||
return products;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -54,8 +55,8 @@ public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.Stack;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -70,8 +71,8 @@ public class FarmLogicGourd extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,21 +10,20 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
@@ -32,15 +31,15 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
private final IBlockState soilState;
|
||||
protected final List<IFarmable> farmables;
|
||||
|
||||
List<ItemStack> produce = new ArrayList<>();
|
||||
protected NonNullList<ItemStack> produce = NonNullList.create();
|
||||
|
||||
protected FarmLogicHomogeneous(ItemStack resource, @Nonnull IBlockState soilState, Collection<IFarmable> farmables) {
|
||||
protected FarmLogicHomogeneous(ItemStack resource, IBlockState soilState, Collection<IFarmable> farmables) {
|
||||
this.resource = resource;
|
||||
this.soilState = soilState;
|
||||
this.farmables = new ArrayList<>(farmables);
|
||||
}
|
||||
|
||||
protected boolean isAcceptedSoil(@Nonnull IBlockState blockState) {
|
||||
protected boolean isAcceptedSoil(IBlockState blockState) {
|
||||
return soilState.getBlock() == blockState.getBlock();
|
||||
}
|
||||
|
||||
@@ -71,16 +70,13 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
@Override
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
|
||||
if (maintainSoil(world, farmHousing, pos, direction, extent)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return maintainGermlings(world, farmHousing, pos.up(), direction, extent);
|
||||
return maintainSoil(world, farmHousing, pos, direction, extent) ||
|
||||
maintainGermlings(world, farmHousing, pos.up(), direction, extent);
|
||||
}
|
||||
|
||||
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
NonNullList<ItemStack> resources = NonNullList.create();
|
||||
resources.add(resource);
|
||||
if (!farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -54,8 +55,8 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,15 +10,12 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class FarmLogicMushroom extends FarmLogicArboreal {
|
||||
|
||||
@@ -51,9 +48,9 @@ public class FarmLogicMushroom extends FarmLogicArboreal {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
produce = new ArrayList<>();
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
NonNullList<ItemStack> products = produce;
|
||||
produce = NonNullList.create();
|
||||
return products;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,6 +26,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -92,8 +95,8 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,7 +141,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
// Determine what type we want to harvest.
|
||||
IBlockState blockState = world.getBlockState(position);
|
||||
Block block = blockState.getBlock();
|
||||
if (!block.isWood(world, position) && !isBlockTraversable(blockState, world, position, traversalBlocks) && !isFruitBearer(world, position)) {
|
||||
if (!block.isWood(world, position) && !isBlockTraversable(blockState, traversalBlocks) && !isFruitBearer(world, position)) {
|
||||
return crops;
|
||||
}
|
||||
|
||||
@@ -181,7 +184,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
|
||||
IBlockState blockState = world.getBlockState(candidate);
|
||||
Block block = blockState.getBlock();
|
||||
if (block.isWood(world, candidate) || isBlockTraversable(blockState, world, candidate, traversalBlocks)) {
|
||||
if (block.isWood(world, candidate) || isBlockTraversable(blockState, traversalBlocks)) {
|
||||
candidates.add(candidate);
|
||||
seen.add(candidate);
|
||||
}
|
||||
@@ -217,7 +220,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isBlockTraversable(IBlockState blockState, World world, BlockPos position, ImmutableList<Block> traversalBlocks) {
|
||||
private static boolean isBlockTraversable(IBlockState blockState, ImmutableList<Block> traversalBlocks) {
|
||||
Block candidate = blockState.getBlock();
|
||||
for (Block block : traversalBlocks) {
|
||||
if (block == candidate) {
|
||||
@@ -227,6 +230,7 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ICrop getCrop(World world, BlockPos position) {
|
||||
|
||||
TileEntity tile = world.getTileEntity(position);
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -78,8 +79,8 @@ public class FarmLogicReeds extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,132 +1,132 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.plugins.compat.PluginIC2;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class FarmLogicRubber extends FarmLogic {
|
||||
|
||||
private boolean active = true;
|
||||
|
||||
public FarmLogicRubber() {
|
||||
if (PluginIC2.rubberWood == null || PluginIC2.resin == null) {
|
||||
Log.warning("Failed to init a farm logic {} since IC2 rubber wood or resin were not found", getClass().getName());
|
||||
active = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getIconItemStack() {
|
||||
return PluginIC2.resin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Rubber Plantation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFertilizerConsumption() {
|
||||
return 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWaterConsumption(float hydrationModifier) {
|
||||
return (int) (5 * hydrationModifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedWindfall(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private final Map<BlockPos, Integer> lastExtents = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
if (!active) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!lastExtents.containsKey(pos)) {
|
||||
lastExtents.put(pos, 0);
|
||||
}
|
||||
|
||||
int lastExtent = lastExtents.get(pos);
|
||||
if (lastExtent > extent) {
|
||||
lastExtent = 0;
|
||||
}
|
||||
|
||||
BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
|
||||
Collection<ICrop> crops = getHarvestBlocks(world, position);
|
||||
lastExtent++;
|
||||
lastExtents.put(pos, lastExtent);
|
||||
|
||||
return crops;
|
||||
}
|
||||
|
||||
private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
Stack<ICrop> crops = new Stack<>();
|
||||
|
||||
for (int j = 0; j < 10; j++) {
|
||||
BlockPos candidate = position.add(0, j, 0);
|
||||
|
||||
IBlockState blockState = world.getBlockState(candidate);
|
||||
Block block = blockState.getBlock();
|
||||
if (!ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (CropRubber.hasRubberToHarvest(blockState)) {
|
||||
crops.push(new CropRubber(world, blockState, candidate));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return crops;
|
||||
}
|
||||
|
||||
}
|
||||
///*******************************************************************************
|
||||
// * Copyright (c) 2011-2014 SirSengir.
|
||||
// * All rights reserved. This program and the accompanying materials
|
||||
// * are made available under the terms of the GNU Lesser Public License v3
|
||||
// * which accompanies this distribution, and is available at
|
||||
// * http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// *
|
||||
// * Various Contributors including, but not limited to:
|
||||
// * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
// ******************************************************************************/
|
||||
//package forestry.farming.logic;
|
||||
//
|
||||
//import java.util.Collection;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//import java.util.Stack;
|
||||
//
|
||||
//import forestry.api.farming.FarmDirection;
|
||||
//import forestry.api.farming.ICrop;
|
||||
//import forestry.api.farming.IFarmHousing;
|
||||
//import forestry.core.utils.ItemStackUtil;
|
||||
//import forestry.core.utils.Log;
|
||||
//import forestry.plugins.compat.PluginIC2;
|
||||
//import net.minecraft.block.Block;
|
||||
//import net.minecraft.block.state.IBlockState;
|
||||
//import net.minecraft.item.ItemStack;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.world.World;
|
||||
//
|
||||
//public class FarmLogicRubber extends FarmLogic {
|
||||
//
|
||||
// private boolean active = true;
|
||||
//
|
||||
// public FarmLogicRubber() {
|
||||
// if (PluginIC2.rubberWood == null || PluginIC2.resin == null) {
|
||||
// Log.warning("Failed to init a farm logic {} since IC2 rubber wood or resin were not found", getClass().getName());
|
||||
// active = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public ItemStack getIconItemStack() {
|
||||
// return PluginIC2.resin;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getName() {
|
||||
// return "Rubber Plantation";
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getFertilizerConsumption() {
|
||||
// return 40;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int getWaterConsumption(float hydrationModifier) {
|
||||
// return (int) (5 * hydrationModifier);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isAcceptedWindfall(ItemStack stack) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean cultivate(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// private final Map<BlockPos, Integer> lastExtents = new HashMap<>();
|
||||
//
|
||||
// @Override
|
||||
// public Collection<ICrop> harvest(World world, BlockPos pos, FarmDirection direction, int extent) {
|
||||
// if (!active) {
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// if (!lastExtents.containsKey(pos)) {
|
||||
// lastExtents.put(pos, 0);
|
||||
// }
|
||||
//
|
||||
// int lastExtent = lastExtents.get(pos);
|
||||
// if (lastExtent > extent) {
|
||||
// lastExtent = 0;
|
||||
// }
|
||||
//
|
||||
// BlockPos position = translateWithOffset(pos.up(), direction, lastExtent);
|
||||
// Collection<ICrop> crops = getHarvestBlocks(world, position);
|
||||
// lastExtent++;
|
||||
// lastExtents.put(pos, lastExtent);
|
||||
//
|
||||
// return crops;
|
||||
// }
|
||||
//
|
||||
// private Collection<ICrop> getHarvestBlocks(World world, BlockPos position) {
|
||||
// Stack<ICrop> crops = new Stack<>();
|
||||
//
|
||||
// for (int j = 0; j < 10; j++) {
|
||||
// BlockPos candidate = position.add(0, j, 0);
|
||||
//
|
||||
// IBlockState blockState = world.getBlockState(candidate);
|
||||
// Block block = blockState.getBlock();
|
||||
// if (!ItemStackUtil.equals(block, PluginIC2.rubberWood)) {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// if (CropRubber.hasRubberToHarvest(blockState)) {
|
||||
// crops.push(new CropRubber(world, blockState, candidate));
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return crops;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -78,8 +79,8 @@ public class FarmLogicSucculent extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return null;
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
return NonNullList.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,36 +10,30 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
protected final IBlockState ground;
|
||||
private final ItemStack resource;
|
||||
|
||||
|
||||
private static final FluidStack STACK_WATER = new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME);
|
||||
|
||||
protected List<ItemStack> produce = new ArrayList<>();
|
||||
protected NonNullList<ItemStack> produce = NonNullList.create();
|
||||
|
||||
protected FarmLogicWatered(ItemStack resource, @Nonnull IBlockState ground) {
|
||||
protected FarmLogicWatered(ItemStack resource, IBlockState ground) {
|
||||
this.ground = ground;
|
||||
this.resource = resource;
|
||||
}
|
||||
@@ -64,9 +58,9 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
Collection<ItemStack> products = produce;
|
||||
produce = new ArrayList<>();
|
||||
public NonNullList<ItemStack> collect(World world, IFarmHousing farmHousing) {
|
||||
NonNullList<ItemStack> products = produce;
|
||||
produce = NonNullList.create();
|
||||
return products;
|
||||
}
|
||||
|
||||
@@ -89,7 +83,8 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
}
|
||||
|
||||
private boolean maintainSoil(World world, IFarmHousing farmHousing, BlockPos pos, FarmDirection direction, int extent) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
NonNullList<ItemStack> resources = NonNullList.create();
|
||||
resources.add(resource);
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
BlockPos position = translateWithOffset(pos, direction, i);
|
||||
@@ -146,7 +141,8 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
}
|
||||
|
||||
private boolean trySetSoil(World world, IFarmHousing farmHousing, BlockPos position) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
NonNullList<ItemStack> resources = NonNullList.create();
|
||||
resources.add(resource);
|
||||
if (!farmHousing.getFarmInventory().hasResources(resources)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
@@ -11,10 +14,6 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
|
||||
/**
|
||||
* For blocks that are harvestable once they are a certain age.
|
||||
*/
|
||||
@@ -26,11 +25,15 @@ public class FarmableAgingCrop implements IFarmable {
|
||||
@Nullable
|
||||
protected final Integer replantAge;
|
||||
|
||||
public FarmableAgingCrop(@Nonnull ItemStack germling, @Nonnull Block cropBlock, @Nonnull IProperty<Integer> ageProperty, int minHarvestAge) {
|
||||
public FarmableAgingCrop(ItemStack germling, Block cropBlock, IProperty<Integer> ageProperty, int minHarvestAge) {
|
||||
this(germling, cropBlock, ageProperty, minHarvestAge, null);
|
||||
}
|
||||
|
||||
public FarmableAgingCrop(ItemStack germling, Block cropBlock, IProperty<Integer> ageProperty, int minHarvestAge, @Nullable Integer replantAge) {
|
||||
Preconditions.checkNotNull(germling);
|
||||
Preconditions.checkNotNull(cropBlock);
|
||||
Preconditions.checkNotNull(ageProperty);
|
||||
|
||||
this.germling = germling;
|
||||
this.cropBlock = cropBlock;
|
||||
this.ageProperty = ageProperty;
|
||||
@@ -45,6 +48,7 @@ public class FarmableAgingCrop implements IFarmable {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
if (blockState.getBlock() != cropBlock) {
|
||||
return null;
|
||||
@@ -54,15 +58,15 @@ public class FarmableAgingCrop implements IFarmable {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (replantAge != null) {
|
||||
IBlockState replantState = getReplantState(world, pos, blockState);
|
||||
return new CropDestroy(world, blockState, pos, replantState);
|
||||
} else {
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
IBlockState replantState = getReplantState(blockState);
|
||||
return new CropDestroy(world, blockState, pos, replantState);
|
||||
}
|
||||
|
||||
protected IBlockState getReplantState(World world, BlockPos pos, IBlockState blockState) {
|
||||
@Nullable
|
||||
protected IBlockState getReplantState(IBlockState blockState) {
|
||||
if (replantAge == null) {
|
||||
return null;
|
||||
}
|
||||
return blockState.withProperty(ageProperty, replantAge);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,8 @@ public abstract class FarmableBase implements IFarmable {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (replant) {
|
||||
return new CropDestroy(world, blockState, pos, plantedState);
|
||||
} else {
|
||||
return new CropDestroy(world, blockState, pos, null);
|
||||
}
|
||||
IBlockState replantState = replant ? plantedState : null;
|
||||
return new CropDestroy(world, blockState, pos, replantState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,85 +1,85 @@
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fml.common.Optional;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.plugins.compat.PluginIC2;
|
||||
|
||||
import ic2.api.crops.ICropTile;
|
||||
|
||||
public class FarmableBasicIC2Crop implements IFarmable {
|
||||
|
||||
/**
|
||||
* Perform some of the actions of the crop-matron.
|
||||
*/
|
||||
@Optional.Method(modid = PluginIC2.modId)
|
||||
public static void babysitCrop(TileEntity tileEntity) {
|
||||
if (CropBasicIC2Crop.isIC2Crop(tileEntity)) {
|
||||
ICropTile crop = (ICropTile) tileEntity;
|
||||
/*
|
||||
This part might be unbalanced until a custom farm logic is added and makes use of weed-ex.
|
||||
if (crop.getCrop() != null) {
|
||||
if (crop.getCrop().isWeed(crop)) {
|
||||
crop.reset();
|
||||
}
|
||||
}*/
|
||||
if (crop.getStorageWater() <= 200) {
|
||||
crop.setStorageWater(200);
|
||||
}
|
||||
if (crop.getStorageNutrient() <= 100) {
|
||||
crop.setStorageNutrient(crop.getStorageNutrient() + 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
TileEntity crop = world.getTileEntity(pos);
|
||||
if (CropBasicIC2Crop.isIC2Crop(crop)) {
|
||||
babysitCrop(crop);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
TileEntity crop = world.getTileEntity(pos);
|
||||
if (crop == null) {
|
||||
return null;
|
||||
}
|
||||
if (!CropBasicIC2Crop.isIC2Crop(crop)) {
|
||||
return null;
|
||||
}
|
||||
if (!CropBasicIC2Crop.canHarvestCrop(crop)) {
|
||||
return null;
|
||||
}
|
||||
return new CropBasicIC2Crop(world, crop, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGermling(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWindfall(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//package forestry.farming.logic;
|
||||
//
|
||||
//import javax.annotation.Nullable;
|
||||
//
|
||||
//import net.minecraft.block.state.IBlockState;
|
||||
//import net.minecraft.entity.player.EntityPlayer;
|
||||
//import net.minecraft.item.ItemStack;
|
||||
//import net.minecraft.tileentity.TileEntity;
|
||||
//import net.minecraft.util.math.BlockPos;
|
||||
//import net.minecraft.world.World;
|
||||
//
|
||||
//import net.minecraftforge.fml.common.Optional;
|
||||
//
|
||||
//import forestry.api.farming.ICrop;
|
||||
//import forestry.api.farming.IFarmable;
|
||||
//import forestry.plugins.compat.PluginIC2;
|
||||
//
|
||||
//import ic2.api.crops.ICropTile;
|
||||
//
|
||||
//public class FarmableBasicIC2Crop implements IFarmable {
|
||||
//
|
||||
// /**
|
||||
// * Perform some of the actions of the crop-matron.
|
||||
// */
|
||||
// @Optional.Method(modid = PluginIC2.modId)
|
||||
// public static void babysitCrop(TileEntity tileEntity) {
|
||||
// if (CropBasicIC2Crop.isIC2Crop(tileEntity)) {
|
||||
// ICropTile crop = (ICropTile) tileEntity;
|
||||
// /*
|
||||
// This part might be unbalanced until a custom farm logic is added and makes use of weed-ex.
|
||||
// if (crop.getCrop() != null) {
|
||||
// if (crop.getCrop().isWeed(crop)) {
|
||||
// crop.reset();
|
||||
// }
|
||||
// }*/
|
||||
// if (crop.getStorageWater() <= 200) {
|
||||
// crop.setStorageWater(200);
|
||||
// }
|
||||
// if (crop.getStorageNutrient() <= 100) {
|
||||
// crop.setStorageNutrient(crop.getStorageNutrient() + 100);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isSaplingAt(World world, BlockPos pos) {
|
||||
// TileEntity crop = world.getTileEntity(pos);
|
||||
// if (CropBasicIC2Crop.isIC2Crop(crop)) {
|
||||
// babysitCrop(crop);
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Nullable
|
||||
// @Override
|
||||
// public ICrop getCropAt(World world, BlockPos pos, IBlockState blockState) {
|
||||
// TileEntity crop = world.getTileEntity(pos);
|
||||
// if (crop == null) {
|
||||
// return null;
|
||||
// }
|
||||
// if (!CropBasicIC2Crop.isIC2Crop(crop)) {
|
||||
// return null;
|
||||
// }
|
||||
// if (!CropBasicIC2Crop.canHarvestCrop(crop)) {
|
||||
// return null;
|
||||
// }
|
||||
// return new CropBasicIC2Crop(world, crop, pos);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isGermling(ItemStack itemstack) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean isWindfall(ItemStack itemstack) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
// return false;
|
||||
// }
|
||||
//}
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import forestry.api.arboriculture.ITreeRoot;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -50,11 +51,15 @@ public class FarmableGE implements IFarmable {
|
||||
|
||||
@Override
|
||||
public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) {
|
||||
ITree tree = TreeManager.treeRoot.getMember(germling);
|
||||
if (tree == null) {
|
||||
ITreeRoot treeRoot = TreeManager.treeRoot;
|
||||
|
||||
germling = GeneticsUtil.convertToGeneticEquivalent(germling);
|
||||
if (treeRoot.isMember(germling)) {
|
||||
ITree tree = treeRoot.getMember(germling);
|
||||
return treeRoot.plantSapling(world, tree, player.getGameProfile(), pos);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return TreeManager.treeRoot.plantSapling(world, tree, player.getGameProfile(), pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,7 @@ public class FarmableVanillaSapling implements IFarmable {
|
||||
EnumActionResult actionResult = germling.copy().onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
|
||||
if (actionResult == EnumActionResult.SUCCESS) {
|
||||
PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState());
|
||||
Proxies.net.sendNetworkPacket(packet, world);
|
||||
Proxies.net.sendNetworkPacket(packet, pos, world);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.logic;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.models;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -107,7 +109,7 @@ public enum EnumFarmBlockTexture {
|
||||
return base;
|
||||
}
|
||||
|
||||
public static EnumFarmBlockTexture getFromCompound(NBTTagCompound compound) {
|
||||
public static EnumFarmBlockTexture getFromCompound(@Nullable NBTTagCompound compound) {
|
||||
if (compound != null) {
|
||||
int farmBlockOrdinal = compound.getInteger("FarmBlock");
|
||||
if (farmBlockOrdinal < EnumFarmBlockTexture.values().length) {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package forestry.farming.models;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Objects;
|
||||
|
||||
import forestry.api.core.IModelBaker;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.propertys.UnlistedBlockPos;
|
||||
import forestry.core.blocks.properties.UnlistedBlockAccess;
|
||||
import forestry.core.blocks.properties.UnlistedBlockPos;
|
||||
import forestry.core.models.ModelBlockCached;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.farming.blocks.BlockFarm;
|
||||
@@ -52,7 +51,7 @@ public class ModelFarmBlock extends ModelBlockCached<BlockFarm, ModelFarmBlock.K
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key getInventoryKey(@Nonnull ItemStack stack) {
|
||||
protected Key getInventoryKey(ItemStack stack) {
|
||||
EnumFarmBlockTexture texture = EnumFarmBlockTexture.getFromCompound(stack.getTagCompound());
|
||||
EnumFarmBlockType type = EnumFarmBlockType.VALUES[stack.getItemDamage()];
|
||||
|
||||
@@ -60,7 +59,7 @@ public class ModelFarmBlock extends ModelBlockCached<BlockFarm, ModelFarmBlock.K
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Key getWorldKey(@Nonnull IBlockState state) {
|
||||
protected Key getWorldKey(IBlockState state) {
|
||||
IExtendedBlockState stateExtended = (IExtendedBlockState) state;
|
||||
IBlockAccess world = stateExtended.getValue(UnlistedBlockAccess.BLOCKACCESS);
|
||||
BlockPos pos = stateExtended.getValue(UnlistedBlockPos.POS);
|
||||
@@ -78,7 +77,7 @@ public class ModelFarmBlock extends ModelBlockCached<BlockFarm, ModelFarmBlock.K
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bakeBlock(@Nonnull BlockFarm blockFarm, @Nonnull Key key, @Nonnull IModelBaker baker, boolean inventory) {
|
||||
protected void bakeBlock(BlockFarm blockFarm, Key key, IModelBaker baker, boolean inventory) {
|
||||
TextureAtlasSprite[] textures = getSprites(key.texture);
|
||||
|
||||
// Add the plain block.
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.models;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -10,16 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitSocketType;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
@@ -32,6 +22,14 @@ import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.multiblock.FakeMultiblockController;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FakeFarmController extends FakeMultiblockController implements IFarmControllerInternal {
|
||||
public static final FakeFarmController instance = new FakeFarmController();
|
||||
@@ -87,7 +85,7 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
|
||||
@Override
|
||||
public IFarmLogic getFarmLogic(FarmDirection direction) {
|
||||
return null;
|
||||
return new FarmLogicArboreal();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +105,7 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
|
||||
@Override
|
||||
public ItemStack getSocket(int slot) {
|
||||
return null;
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,7 +128,6 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITankManager getTankManager() {
|
||||
return FakeTankManager.instance;
|
||||
@@ -149,12 +146,12 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResources(ItemStack[] resources) {
|
||||
public boolean hasResources(NonNullList<ItemStack> resources) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
public void removeResources(NonNullList<ItemStack> resources) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -28,6 +27,7 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitBoard;
|
||||
@@ -48,18 +48,16 @@ import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.FilteredTank;
|
||||
import forestry.core.fluids.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.multiblock.IMultiblockControllerInternal;
|
||||
import forestry.core.multiblock.MultiblockValidationException;
|
||||
import forestry.core.multiblock.RectangularMultiblockControllerBase;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.TopDownBlockPosComparator;
|
||||
@@ -74,6 +72,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
@@ -110,7 +109,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
private final Map<FarmDirection, List<FarmTarget>> targets = new EnumMap<>(FarmDirection.class);
|
||||
private int allowedExtent = 0;
|
||||
|
||||
@Nullable
|
||||
private IFarmLogic harvestProvider; // The farm logic which supplied the pending crops.
|
||||
private final List<ICrop> pendingCrops = new LinkedList<>();
|
||||
private final Stack<ItemStack> pendingProduce = new Stack<>();
|
||||
@@ -136,6 +135,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
// tick updates can come from multiple gearboxes so keep track of them here
|
||||
private int farmWorkTicks = 0;
|
||||
|
||||
@Nullable
|
||||
private Vec3i offset;
|
||||
@Nullable
|
||||
private Vec3i area;
|
||||
|
||||
public FarmController(World world) {
|
||||
super(world, FarmMultiblockSizeLimits.instance);
|
||||
|
||||
@@ -156,7 +160,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return hydrationManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
if (isAssembled()) {
|
||||
@@ -166,7 +170,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
@@ -185,7 +189,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
if (newPart instanceof IFarmComponent.Active) {
|
||||
farmActiveComponents.put((IFarmComponent.Active) newPart, worldObj.rand.nextInt(256));
|
||||
farmActiveComponents.put((IFarmComponent.Active) newPart, world.rand.nextInt(256));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +254,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
protected boolean updateServer(int tickCount) {
|
||||
hydrationManager.updateServer(worldObj, getTopCenterCoord());
|
||||
hydrationManager.updateServer(world, getTopCenterCoord());
|
||||
|
||||
if (updateOnInterval(20)) {
|
||||
inventory.drainCan(tankManager);
|
||||
@@ -334,12 +338,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public BlockPos getCoordinates() {
|
||||
BlockPos coord = getReferenceCoord();
|
||||
return new BlockPos(coord);
|
||||
return getReferenceCoord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeGuiData(PacketBufferForestry data) {
|
||||
tankManager.writeData(data);
|
||||
hydrationManager.writeData(data);
|
||||
fertilizerManager.writeData(data);
|
||||
@@ -347,7 +350,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
public void readGuiData(PacketBufferForestry data) throws IOException {
|
||||
tankManager.readData(data);
|
||||
hydrationManager.readData(data);
|
||||
fertilizerManager.readData(data);
|
||||
@@ -363,7 +366,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
// See whether we have socketed stuff.
|
||||
ItemStack chip = sockets.getStackInSlot(0);
|
||||
if (chip != null) {
|
||||
if (!chip.isEmpty()) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(chip);
|
||||
if (chipset != null) {
|
||||
chipset.onLoad(this);
|
||||
@@ -383,19 +386,16 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
BlockPos coords = getReferenceCoord();
|
||||
BlockPos coords = getCoordinates();
|
||||
return ForestryAPI.climateManager.getTemperature(getWorldObj(), coords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
BlockPos coords = getReferenceCoord();
|
||||
BlockPos coords = getCoordinates();
|
||||
return ForestryAPI.climateManager.getHumidity(getWorldObj(), coords);
|
||||
}
|
||||
|
||||
private Vec3i offset;
|
||||
private Vec3i area;
|
||||
|
||||
@Override
|
||||
public BlockPos getCoords() {
|
||||
return getCenterCoord();
|
||||
@@ -444,7 +444,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
// Cull queued crops.
|
||||
if (!pendingCrops.isEmpty()) {
|
||||
if (!pendingCrops.isEmpty() && harvestProvider != null) {
|
||||
ICrop first = pendingCrops.get(0);
|
||||
if (cullCrop(first, harvestProvider)) {
|
||||
pendingCrops.remove(0);
|
||||
@@ -458,12 +458,9 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
|
||||
|
||||
List<FarmDirection> farmDirections = Arrays.asList(FarmDirection.values());
|
||||
Collections.shuffle(farmDirections, worldObj.rand);
|
||||
Collections.shuffle(farmDirections, world.rand);
|
||||
for (FarmDirection farmSide : farmDirections) {
|
||||
IFarmLogic logic = getFarmLogic(farmSide);
|
||||
if (logic == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Always try to collect windfall.
|
||||
if (collectWindfall(logic)) {
|
||||
@@ -473,11 +470,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
List<FarmTarget> farmTargets = targets.get(farmSide);
|
||||
|
||||
if (stage == Stage.HARVEST) {
|
||||
Collection<ICrop> harvested = harvestTargets(worldObj, farmTargets, logic, farmListeners);
|
||||
Collection<ICrop> harvested = harvestTargets(world, farmTargets, logic, farmListeners);
|
||||
farmWorkStatus.didWork = !harvested.isEmpty();
|
||||
if (!harvested.isEmpty()) {
|
||||
pendingCrops.addAll(harvested);
|
||||
Collections.sort(pendingCrops, TopDownICropComparator.INSTANCE);
|
||||
pendingCrops.sort(TopDownICropComparator.INSTANCE);
|
||||
harvestProvider = logic;
|
||||
}
|
||||
} else if (stage == Stage.CULTIVATE) {
|
||||
@@ -513,8 +510,8 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
// Set the maximum allowed extent.
|
||||
allowedExtent = Math.max(sizeNorthSouth, sizeEastWest) * Config.farmSize + 1;
|
||||
|
||||
createTargets(worldObj, targets, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest, min, max);
|
||||
setExtents(worldObj, targets);
|
||||
createTargets(world, targets, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest, min, max);
|
||||
setExtents(world, targets);
|
||||
}
|
||||
|
||||
private static void createTargets(World world, Map<FarmDirection, List<FarmTarget>> targets, BlockPos targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest, BlockPos minFarmCoord, BlockPos maxFarmCoord) {
|
||||
@@ -594,13 +591,13 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void setExtents(World worldObj, Map<FarmDirection, List<FarmTarget>> targets) {
|
||||
private static void setExtents(World world, Map<FarmDirection, List<FarmTarget>> targets) {
|
||||
for (List<FarmTarget> targetsList : targets.values()) {
|
||||
if (!targetsList.isEmpty()) {
|
||||
BlockPos groundPosition = getGroundPosition(worldObj, targetsList.get(0).getStart());
|
||||
BlockPos groundPosition = getGroundPosition(world, targetsList.get(0).getStart());
|
||||
|
||||
for (FarmTarget target : targetsList) {
|
||||
target.setExtentAndYOffset(worldObj, groundPosition);
|
||||
target.setExtentAndYOffset(world, groundPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -615,13 +612,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
private FarmWorkStatus cultivateTargets(FarmWorkStatus farmWorkStatus, List<FarmTarget> farmTargets, IFarmLogic logic, FarmDirection farmSide) {
|
||||
boolean hasFarmland = false;
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
if (target.getExtent() > 0) {
|
||||
hasFarmland = true;
|
||||
farmWorkStatus.hasFarmland = true;
|
||||
break;
|
||||
}
|
||||
for (FarmTarget target : farmTargets) {
|
||||
if (target.getExtent() > 0) {
|
||||
hasFarmland = true;
|
||||
farmWorkStatus.hasFarmland = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,7 +638,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cultivateTarget(worldObj, this, target, logic, farmListeners)) {
|
||||
if (cultivateTarget(world, this, target, logic, farmListeners)) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(liquid);
|
||||
@@ -669,12 +664,10 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
private static Collection<ICrop> harvestTargets(World world, List<FarmTarget> farmTargets, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
Collection<ICrop> harvested = harvestTarget(world, target, logic, farmListeners);
|
||||
if (!harvested.isEmpty()) {
|
||||
return harvested;
|
||||
}
|
||||
for (FarmTarget target : farmTargets) {
|
||||
Collection<ICrop> harvested = harvestTarget(world, target, logic, farmListeners);
|
||||
if (!harvested.isEmpty()) {
|
||||
return harvested;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,21 +677,18 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
private static Collection<ICrop> harvestTarget(World world, FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
BlockPos pos = target.getStart().add(0, target.getYOffset(), 0);
|
||||
Collection<ICrop> harvested = logic.harvest(world, pos, target.getDirection(), target.getExtent());
|
||||
if (harvested == null || harvested.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
if (!harvested.isEmpty()) {
|
||||
// Let event handlers know.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasScheduledHarvest(harvested, logic, pos, target.getDirection(), target.getExtent());
|
||||
}
|
||||
}
|
||||
|
||||
// Let event handlers know.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasScheduledHarvest(harvested, logic, pos, target.getDirection(), target.getExtent());
|
||||
}
|
||||
|
||||
return harvested;
|
||||
}
|
||||
|
||||
private boolean collectWindfall(IFarmLogic logic) {
|
||||
Collection<ItemStack> collected = logic.collect(worldObj, this);
|
||||
if (collected == null || collected.size() <= 0) {
|
||||
NonNullList<ItemStack> collected = logic.collect(world, this);
|
||||
if (collected.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -744,22 +734,19 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return false;
|
||||
}
|
||||
|
||||
Collection<ItemStack> harvested = crop.harvest();
|
||||
if (harvested == null) {
|
||||
return true;
|
||||
NonNullList<ItemStack> harvested = crop.harvest();
|
||||
if (harvested != null) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(requiredLiquid);
|
||||
|
||||
// Let event handlers handle the harvest first.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.afterCropHarvest(harvested, crop);
|
||||
}
|
||||
|
||||
inventory.stowHarvest(harvested, pendingProduce);
|
||||
}
|
||||
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(requiredLiquid);
|
||||
|
||||
// Let event handlers handle the harvest first.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.afterCropHarvest(harvested, crop);
|
||||
}
|
||||
|
||||
inventory.stowHarvest(harvested, pendingProduce);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -771,7 +758,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
FluidStack drained = resourceTank.drainInternal(liquid, false);
|
||||
return FluidHelper.areFluidStacksEqual(drained, liquid);
|
||||
return drained.isFluidStackIdentical(liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -782,7 +769,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, BlockPos pos) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, getOwnerHandler().getOwner());
|
||||
return inventory.plantGermling(germling, player, pos);
|
||||
return player != null && inventory.plantGermling(germling, player, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -792,9 +779,8 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public void setFarmLogic(FarmDirection direction, IFarmLogic logic) {
|
||||
if (logic == null) {
|
||||
throw new NullPointerException("logic must not be null");
|
||||
}
|
||||
Preconditions.checkNotNull(direction);
|
||||
Preconditions.checkNotNull(logic, "logic must not be null");
|
||||
farmLogics.put(direction, logic);
|
||||
}
|
||||
|
||||
@@ -820,30 +806,26 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public void setSocket(int slot, ItemStack stack) {
|
||||
if (stack != null && !ChipsetManager.circuitRegistry.isChipset(stack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Dispose old chipsets correctly
|
||||
if (sockets.getStackInSlot(slot) != null) {
|
||||
if (ChipsetManager.circuitRegistry.isChipset(sockets.getStackInSlot(slot))) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(sockets.getStackInSlot(slot));
|
||||
if (chipset != null) {
|
||||
chipset.onRemoval(this);
|
||||
if (ChipsetManager.circuitRegistry.isChipset(stack)) {
|
||||
// Dispose old chipsets correctly
|
||||
if (!sockets.getStackInSlot(slot).isEmpty()) {
|
||||
if (ChipsetManager.circuitRegistry.isChipset(sockets.getStackInSlot(slot))) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(sockets.getStackInSlot(slot));
|
||||
if (chipset != null) {
|
||||
chipset.onRemoval(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sockets.setInventorySlotContents(slot, stack);
|
||||
refreshFarmLogics();
|
||||
sockets.setInventorySlotContents(slot, stack);
|
||||
refreshFarmLogics();
|
||||
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack);
|
||||
if (chipset != null) {
|
||||
chipset.onInsertion(this);
|
||||
if (!stack.isEmpty()) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack);
|
||||
if (chipset != null) {
|
||||
chipset.onInsertion(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,11 @@ package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
|
||||
public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStreamable {
|
||||
@@ -80,12 +79,12 @@ public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStrea
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
data.writeVarInt(storedFertilizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
storedFertilizer = data.readVarInt();
|
||||
}
|
||||
}
|
||||
@@ -10,32 +10,28 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class FarmHydrationManager implements IFarmLedgerDelegate, INbtWritable, INbtReadable, IStreamable {
|
||||
private static final int DELAY_HYDRATION = 100;
|
||||
private static final float RAINFALL_MODIFIER_MAX = 15f;
|
||||
private static final float RAINFALL_MODIFIER_MIN = 0.5f;
|
||||
|
||||
@Nonnull
|
||||
private final IClimatised climatised;
|
||||
private int hydrationDelay = 0;
|
||||
private int ticksSinceRainfall = 0;
|
||||
|
||||
public FarmHydrationManager(@Nonnull IClimatised climatised) {
|
||||
public FarmHydrationManager(IClimatised climatised) {
|
||||
this.climatised = climatised;
|
||||
}
|
||||
|
||||
@@ -96,13 +92,13 @@ public class FarmHydrationManager implements IFarmLedgerDelegate, INbtWritable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
data.writeVarInt(hydrationDelay);
|
||||
data.writeVarInt(ticksSinceRainfall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
hydrationDelay = data.readVarInt();
|
||||
ticksSinceRainfall = data.readVarInt();
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.multiblock.IFarmController;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
@@ -27,6 +25,5 @@ public interface IFarmControllerInternal extends IFarmController, IMultiblockCon
|
||||
|
||||
IInventoryAdapter getInternalInventory();
|
||||
|
||||
@Nonnull
|
||||
ITankManager getTankManager();
|
||||
}
|
||||
@@ -10,18 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
@@ -35,6 +26,15 @@ import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class InventoryFarm extends InventoryAdapterRestricted implements IFarmInventory {
|
||||
public static final int SLOT_RESOURCES_1 = 0;
|
||||
@@ -50,7 +50,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
public static final int SLOT_CAN_COUNT = 1;
|
||||
|
||||
public static final int SLOT_COUNT = SLOT_RESOURCES_COUNT + SLOT_GERMLINGS_COUNT + SLOT_PRODUCTION_COUNT + SLOT_FERTILIZER_COUNT + SLOT_CAN_COUNT;
|
||||
|
||||
|
||||
private static final int FERTILIZER_MODIFIER = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.modifier");
|
||||
|
||||
private final FarmController farmController;
|
||||
@@ -80,7 +80,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
return acceptsAsResource(itemStack);
|
||||
} else if (SlotUtil.isSlotInRange(slotIndex, SLOT_CAN, SLOT_CAN_COUNT)) {
|
||||
FluidStack fluid = FluidUtil.getFluidContained(itemStack);
|
||||
return farmController.getTankManager().canFillFluidType(fluid);
|
||||
return fluid != null && farmController.getTankManager().canFillFluidType(fluid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -91,19 +91,19 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResources(ItemStack[] resources) {
|
||||
public boolean hasResources(NonNullList<ItemStack> resources) {
|
||||
return InventoryUtil.contains(resourcesInventory, resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
public void removeResources(NonNullList<ItemStack> resources) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorldObj(), farmController.getOwnerHandler().getOwner());
|
||||
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsGermling(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsResource(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -135,17 +135,17 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsFertilizer(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()){
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if(itemstack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == itemstack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
for (Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()) {
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if (itemstack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == itemstack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,11 +175,11 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
public boolean plantGermling(IFarmable germling, EntityPlayer player, BlockPos pos) {
|
||||
for (int i = 0; i < germlingsInventory.getSizeInventory(); i++) {
|
||||
ItemStack germlingStack = germlingsInventory.getStackInSlot(i);
|
||||
if (germlingStack == null || !germling.isGermling(germlingStack)) {
|
||||
if (germlingStack.isEmpty() || !germling.isGermling(germlingStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (germling.plantSaplingAt(player, germlingStack, player.worldObj, pos)) {
|
||||
if (germling.plantSaplingAt(player, germlingStack, player.world, pos)) {
|
||||
germlingsInventory.decrStackSize(i, 1);
|
||||
return true;
|
||||
}
|
||||
@@ -188,13 +188,15 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
}
|
||||
|
||||
public void addProduce(ItemStack produce) {
|
||||
produce.stackSize -= InventoryUtil.addStack(productInventory, produce, true);
|
||||
int added = InventoryUtil.addStack(productInventory, produce, true);
|
||||
produce.shrink(added);
|
||||
}
|
||||
|
||||
public void stowHarvest(Iterable<ItemStack> harvested, Stack<ItemStack> pendingProduce) {
|
||||
for (ItemStack harvest : harvested) {
|
||||
harvest.stackSize -= InventoryUtil.addStack(productInventory, harvest, true);
|
||||
if (harvest.stackSize > 0) {
|
||||
int added = InventoryUtil.addStack(productInventory, harvest, true);
|
||||
harvest.shrink(added);
|
||||
if (!harvest.isEmpty()) {
|
||||
pendingProduce.push(harvest);
|
||||
}
|
||||
}
|
||||
@@ -212,33 +214,28 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
|
||||
public int getFertilizerValue() {
|
||||
ItemStack fertilizerStack = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizerStack == null || fertilizerStack.stackSize <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()){
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if(fertilizerStack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == fertilizerStack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)){
|
||||
return fertilizer.getValue() * FERTILIZER_MODIFIER;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (fertilizerStack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()) {
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if (fertilizerStack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == fertilizerStack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return fertilizer.getValue() * FERTILIZER_MODIFIER;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean useFertilizer() {
|
||||
ItemStack fertilizer = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizer == null || fertilizer.stackSize <= 0) {
|
||||
return false;
|
||||
if (acceptsAsFertilizer(fertilizer)) {
|
||||
decrStackSize(SLOT_FERTILIZER, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!acceptsAsFertilizer(fertilizer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
decrStackSize(SLOT_FERTILIZER, 1);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class MultiblockLogicFarm extends MultiblockLogic<IFarmControllerInternal
|
||||
|
||||
@Override
|
||||
public IFarmControllerInternal getController() {
|
||||
if (super.isConnected()) {
|
||||
if (controller != null) {
|
||||
return controller;
|
||||
} else {
|
||||
return FakeFarmController.instance;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -17,6 +17,7 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.farming.PluginFarming;
|
||||
import forestry.farming.models.ModelFarmBlock;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ProxyFarmingClient extends ProxyFarming {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.proxy;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -10,19 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.circuits.ICircuitSocketType;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
@@ -33,24 +23,30 @@ import forestry.core.config.Config;
|
||||
import forestry.core.gui.IHintSource;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.multiblock.MultiblockTileEntityForestry;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.owner.IOwnerHandler;
|
||||
import forestry.core.tiles.ITitled;
|
||||
import forestry.farming.blocks.EnumFarmBlockType;
|
||||
import forestry.farming.gui.ContainerFarm;
|
||||
import forestry.farming.gui.GuiFarm;
|
||||
import forestry.farming.models.EnumFarmBlockTexture;
|
||||
import forestry.farming.multiblock.MultiblockLogicFarm;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLogicFarm> implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource, IOwnedTile, ITitled {
|
||||
|
||||
private EnumFarmBlockTexture farmBlockTexture = EnumFarmBlockTexture.BRICK_STONE;
|
||||
|
||||
protected TileFarm() {
|
||||
super(new MultiblockLogicFarm());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
|
||||
return oldState.getBlock() != newState.getBlock();
|
||||
@@ -58,13 +54,13 @@ public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLo
|
||||
|
||||
@Override
|
||||
public void onMachineAssembled(IMultiblockController multiblockController, BlockPos minCoord, BlockPos maxCoord) {
|
||||
worldObj.notifyBlockOfStateChange(getPos(), worldObj.getBlockState(pos).getBlock());
|
||||
world.notifyNeighborsOfStateChange(getPos(), world.getBlockState(pos).getBlock(), false);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineBroken() {
|
||||
worldObj.notifyBlockOfStateChange(getPos(), worldObj.getBlockState(pos).getBlock());
|
||||
world.notifyNeighborsOfStateChange(getPos(), world.getBlockState(pos).getBlock(), false);
|
||||
markDirty();
|
||||
}
|
||||
|
||||
@@ -80,7 +76,6 @@ public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLo
|
||||
farmBlockTexture = EnumFarmBlockTexture.getFromCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound = super.writeToNBT(nbttagcompound);
|
||||
@@ -93,14 +88,14 @@ public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLo
|
||||
public void setFarmBlockTexture(EnumFarmBlockTexture farmBlockTexture) {
|
||||
if (this.farmBlockTexture != farmBlockTexture) {
|
||||
this.farmBlockTexture = farmBlockTexture;
|
||||
worldObj.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
world.markBlockRangeForRenderUpdate(getPos(), getPos());
|
||||
}
|
||||
}
|
||||
|
||||
public EnumFarmBlockTexture getFarmBlockTexture() {
|
||||
return farmBlockTexture;
|
||||
}
|
||||
|
||||
|
||||
public EnumFarmBlockType getFarmBlockType() {
|
||||
return EnumFarmBlockType.VALUES[getBlockMetadata()];
|
||||
}
|
||||
@@ -149,12 +144,12 @@ public abstract class TileFarm extends MultiblockTileEntityForestry<MultiblockLo
|
||||
|
||||
/* IStreamableGui */
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeGuiData(PacketBufferForestry data) {
|
||||
getMultiblockLogic().getController().writeGuiData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
public void readGuiData(PacketBufferForestry data) throws IOException {
|
||||
getMultiblockLogic().getController().readGuiData(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,19 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.multiblock.IFarmComponent;
|
||||
import forestry.api.multiblock.IFarmController;
|
||||
import forestry.energy.EnergyHelper;
|
||||
import forestry.energy.EnergyManager;
|
||||
import forestry.energy.compat.rf.IEnergyReceiverDelegated;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
public class TileFarmGearbox extends TileFarm implements IEnergyReceiverDelegated, IFarmComponent.Active {
|
||||
public class TileFarmGearbox extends TileFarm implements IFarmComponent.Active {
|
||||
|
||||
private static final int WORK_CYCLES = 4;
|
||||
private static final int ENERGY_PER_OPERATION = WORK_CYCLES * 50;
|
||||
@@ -47,7 +45,7 @@ public class TileFarmGearbox extends TileFarm implements IEnergyReceiverDelegate
|
||||
previousDelays = nbttagcompound.getInteger("PrevDelays");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound = super.writeToNBT(nbttagcompound);
|
||||
@@ -92,19 +90,18 @@ public class TileFarmGearbox extends TileFarm implements IEnergyReceiverDelegate
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnergyManager getEnergyManager() {
|
||||
return energyManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return energyManager.hasCapability(capability) || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Nullable
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
T energyCapability = energyManager.getCapability(capability);
|
||||
if (energyCapability != null) {
|
||||
return energyCapability;
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.multiblock.IFarmComponent;
|
||||
import forestry.core.inventory.AdjacentInventoryCache;
|
||||
@@ -18,7 +18,6 @@ import forestry.core.tiles.AdjacentTileCache;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
@@ -37,12 +36,7 @@ public class TileFarmHatch extends TileFarm implements ISidedInventory, IFarmCom
|
||||
|
||||
public TileFarmHatch() {
|
||||
this.tileCache = new AdjacentTileCache(this);
|
||||
this.inventoryCache = new AdjacentInventoryCache(this, tileCache, new AdjacentInventoryCache.ITileFilter() {
|
||||
@Override
|
||||
public boolean matches(TileEntity tile) {
|
||||
return !(tile instanceof TileFarm) && tile.getPos().getY() < getPos().getY();
|
||||
}
|
||||
});
|
||||
this.inventoryCache = new AdjacentInventoryCache(this, tileCache, tile -> !(tile instanceof TileFarm) && tile.getPos().getY() < getPos().getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,12 +62,13 @@ public class TileFarmHatch extends TileFarm implements ISidedInventory, IFarmCom
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(@Nonnull Capability<?> capability, @Nonnull EnumFacing facing) {
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(@Nonnull Capability<T> capability, @Nonnull EnumFacing facing) {
|
||||
@Nullable
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
|
||||
SidedInvWrapper sidedInvWrapper = new SidedInvWrapper(this, facing);
|
||||
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(sidedInvWrapper);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TileFarmPlain extends TileFarm {
|
||||
// set band block meta
|
||||
int bandY = maxCoord.getY() - 1;
|
||||
if (getPos().getY() == bandY) {
|
||||
this.worldObj.setBlockState(getPos(), getBlockType().getStateFromMeta(1), 2);
|
||||
this.world.setBlockState(getPos(), getBlockType().getStateFromMeta(1), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,6 @@ public class TileFarmPlain extends TileFarm {
|
||||
super.onMachineBroken();
|
||||
|
||||
// set band block meta back to normal
|
||||
this.worldObj.setBlockState(getPos(), getBlockType().getDefaultState(), 2);
|
||||
this.world.setBlockState(getPos(), getBlockType().getDefaultState(), 2);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class TileFarmValve extends TileFarm implements ILiquidTankTile {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return true;
|
||||
}
|
||||
@@ -36,7 +37,8 @@ public class TileFarmValve extends TileFarm implements ILiquidTankTile {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
@Nullable
|
||||
public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
|
||||
if (super.hasCapability(capability, facing)) {
|
||||
return super.getCapability(capability, facing);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.tiles;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
@@ -56,7 +56,7 @@ public class TriggerLowSoil extends Trigger {
|
||||
// return InventoryUtil.containsPercent(resourcesInventory, threshold);
|
||||
// } else {
|
||||
// ItemStack filter = parameter.getItemStack().copy();
|
||||
// filter.stackSize = threshold;
|
||||
// filter.setCount(threshold);
|
||||
// return farmInventory.hasResources(new ItemStack[]{filter});
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.triggers;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
Reference in new issue
Block a user