mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
added melon and pumpkin farmer behavior and broke the API x)
This commit is contained in:
parent
cd59523e06
commit
0485107c94
13 changed files with 224 additions and 61 deletions
|
@ -32,7 +32,7 @@ public final class ActuallyAdditionsAPI{
|
|||
|
||||
public static final String MOD_ID = "actuallyadditions";
|
||||
public static final String API_ID = MOD_ID+"api";
|
||||
public static final String API_VERSION = "32";
|
||||
public static final String API_VERSION = "33";
|
||||
|
||||
public static final List<CrusherRecipe> CRUSHER_RECIPES = new ArrayList<CrusherRecipe>();
|
||||
public static final List<BallOfFurReturn> BALL_OF_FUR_RETURN_ITEMS = new ArrayList<BallOfFurReturn>();
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* This file ("FarmerResult.java") is part of the Actually Additions mod for Minecraft.
|
||||
* It is created and owned by Ellpeck and distributed
|
||||
* under the Actually Additions License to be found at
|
||||
* http://ellpeck.de/actaddlicense
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015-2017 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.api.farmer;
|
||||
|
||||
public enum FarmerResult{
|
||||
FAIL,
|
||||
SUCCESS,
|
||||
STOP_PROCESSING
|
||||
}
|
|
@ -27,7 +27,7 @@ public interface IFarmerBehavior{
|
|||
* @param farmer The Farmer doing this action. Can be used to query and extract energy and add items to the slots
|
||||
* @return If planting was successful
|
||||
*/
|
||||
boolean tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer);
|
||||
FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer);
|
||||
|
||||
/**
|
||||
* Try to harvest a plant with this behavior
|
||||
|
@ -37,7 +37,7 @@ public interface IFarmerBehavior{
|
|||
* @param farmer The Farmer doing this action. Can be used to query and extract energy and add items to the slots
|
||||
* @return If harvesting was successful
|
||||
*/
|
||||
boolean tryHarvestPlant(World world, BlockPos pos, IFarmer farmer);
|
||||
|
||||
FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer);
|
||||
|
||||
int getPriority();
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ public final class InitBooklet{
|
|||
//RF Using Blocks
|
||||
new BookletChapter("fireworkBox", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockFireworkBox), new PageTextOnly(1).addTextReplacement("<rf>", TileEntityFireworkBox.USE_PER_SHOT), new PageCrafting(2, BlockCrafting.recipeFireworkBox)).setSpecial();
|
||||
new BookletChapter("batteryBox", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockBatteryBox), new PageTextOnly(1), new PageCrafting(2, BlockCrafting.recipeBatteryBox).setNoText()).setSpecial();
|
||||
new BookletChapter("farmer", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockFarmer), new PageTextOnly(1), new PagePicture(2, "page_farmer_crops", 95).addItemsToPage(new ItemStack(Items.WHEAT_SEEDS)).addItemsToPage(new ItemStack(InitItems.itemCanolaSeed)), new PagePicture(3, "page_farmer_cactus", 105).addItemsToPage(new ItemStack(Blocks.CACTUS)), new PagePicture(4, "page_farmer_wart", 95).addItemsToPage(new ItemStack(Items.NETHER_WART)), new PagePicture(5, "page_farmer_reeds", 105).addItemsToPage(new ItemStack(Items.REEDS)), new PageCrafting(4, BlockCrafting.recipeFarmer).setWildcard().setNoText()).setImportant();
|
||||
new BookletChapter("farmer", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockFarmer), new PageTextOnly(1), new PagePicture(2, "page_farmer_crops", 95).addItemsToPage(new ItemStack(Items.WHEAT_SEEDS)).addItemsToPage(new ItemStack(InitItems.itemCanolaSeed)), new PagePicture(3, "page_farmer_cactus", 105).addItemsToPage(new ItemStack(Blocks.CACTUS)), new PagePicture(4, "page_farmer_wart", 95).addItemsToPage(new ItemStack(Items.NETHER_WART)), new PagePicture(5, "page_farmer_reeds", 105).addItemsToPage(new ItemStack(Items.REEDS)), new PagePicture(6, "page_farmer_melons", 105).addItemsToPage(new ItemStack(Items.MELON), new ItemStack(Blocks.PUMPKIN), new ItemStack(Blocks.MELON_BLOCK)), new PageCrafting(4, BlockCrafting.recipeFarmer).setWildcard().setNoText()).setImportant();
|
||||
new BookletChapter("miner", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockMiner), new PageTextOnly(1).addTextReplacement("<rf>", TileEntityMiner.ENERGY_USE_PER_BLOCK).addTextReplacement("<range>", TileEntityMiner.DEFAULT_RANGE), new PageCrafting(2, BlockCrafting.recipeMiner)).setSpecial();
|
||||
new BookletChapterCoffee("coffeeMachine", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockCoffeeMachine), new PageTextOnly(1).addItemsToPage(new ItemStack(InitItems.itemCoffeeBean)).addTextReplacement("<rf>", TileEntityCoffeeMachine.ENERGY_USED).addTextReplacement("<coffee>", TileEntityCoffeeMachine.CACHE_USE).addTextReplacement("<water>", TileEntityCoffeeMachine.WATER_USE), new PageTextOnly(2).addItemsToPage(new ItemStack(InitItems.itemCoffee)), new PagePicture(3, "page_coffee_machine", 115), new PageCrafting(4, BlockCrafting.recipeCoffeeMachine).setWildcard().setNoText(), new PageCrafting(5, ItemCrafting.recipeCup).setNoText()).setImportant();
|
||||
new BookletChapterCrusher("crusher", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockGrinderDouble), new PageTextOnly(1).addTextReplacement("<rf>", TileEntityGrinder.ENERGY_USE), new PageCrafting(2, BlockCrafting.recipeCrusher).setWildcard().setNoText(), new PageCrafting(3, BlockCrafting.recipeDoubleCrusher).setWildcard().setNoText(), new PageCrusherRecipe(4, CrusherCrafting.recipeIronHorseArmor).setNoText(), new PageCrusherRecipe(5, CrusherCrafting.recipeGoldHorseArmor).setNoText(), new PageCrusherRecipe(6, CrusherCrafting.recipeDiamondHorseArmor).setNoText());
|
||||
|
|
|
@ -14,10 +14,7 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|||
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
|
||||
import de.ellpeck.actuallyadditions.mod.items.InitItems;
|
||||
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.CactusFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.DefaultFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.NetherWartFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.ReedFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer.*;
|
||||
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -47,6 +44,7 @@ public final class InitCrafting{
|
|||
ActuallyAdditionsAPI.addFarmerBehavior(new CactusFarmerBehavior());
|
||||
ActuallyAdditionsAPI.addFarmerBehavior(new NetherWartFarmerBehavior());
|
||||
ActuallyAdditionsAPI.addFarmerBehavior(new ReedFarmerBehavior());
|
||||
ActuallyAdditionsAPI.addFarmerBehavior(new MelonPumpkinFarmerBehavior());
|
||||
|
||||
RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShaped", RecipeKeepDataShaped.class, RecipeSorter.Category.SHAPED, "after:minecraft:shaped");
|
||||
RecipeSorter.register(ModUtil.MOD_ID+":recipeKeepDataShapeless", RecipeKeepDataShapeless.class, RecipeSorter.Category.SHAPELESS, "after:minecraft:shapeless");
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -26,31 +27,36 @@ import java.util.List;
|
|||
public class CactusFarmerBehavior implements IFarmerBehavior{
|
||||
|
||||
@Override
|
||||
public boolean tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 250;
|
||||
if(farmer.getEnergy() >= use){
|
||||
Item item = seed.getItem();
|
||||
if(item instanceof ItemBlock){
|
||||
Block block = Block.getBlockFromItem(item);
|
||||
if(block instanceof BlockCactus && block.canPlaceBlockAt(world, pos)){
|
||||
IBlockState state = block.getDefaultState();
|
||||
world.setBlockState(pos, state, 2);
|
||||
world.playEvent(2001, pos, Block.getStateId(state));
|
||||
if(block instanceof BlockCactus){
|
||||
if(block.canPlaceBlockAt(world, pos)){
|
||||
IBlockState state = block.getDefaultState();
|
||||
world.setBlockState(pos, state, 2);
|
||||
world.playEvent(2001, pos, Block.getStateId(state));
|
||||
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
farmer.extractEnergy(use);
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
return FarmerResult.STOP_PROCESSING;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 250;
|
||||
if(farmer.getEnergy() >= use){
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if(state.getBlock() instanceof BlockCactus){
|
||||
FarmerResult result = FarmerResult.STOP_PROCESSING;
|
||||
|
||||
for(int i = 2; i >= 1; i--){
|
||||
if(farmer.getEnergy() >= use){
|
||||
BlockPos up = pos.up(i);
|
||||
|
@ -65,14 +71,21 @@ public class CactusFarmerBehavior implements IFarmerBehavior{
|
|||
|
||||
farmer.extractEnergy(use);
|
||||
farmer.addToOutputInventory(drops, true);
|
||||
|
||||
result = FarmerResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,11 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockCrops;
|
||||
import net.minecraft.block.BlockDirt;
|
||||
import net.minecraft.block.BlockGrass;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
|
@ -34,9 +32,18 @@ import java.util.List;
|
|||
public class DefaultFarmerBehavior implements IFarmerBehavior{
|
||||
|
||||
@Override
|
||||
public boolean tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 350;
|
||||
if(farmer.getEnergy() >= use*2){
|
||||
if(defaultPlant(world, pos, this.getPlantablePlantFromStack(seed, world, pos), farmer, use)){
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
public static boolean defaultPlant(World world, BlockPos pos, IBlockState toPlant, IFarmer farmer, int use){
|
||||
if(toPlant != null){
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
|
@ -44,24 +51,21 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
|
|||
BlockPos farmland = pos.down();
|
||||
Block farmlandBlock = world.getBlockState(farmland).getBlock();
|
||||
|
||||
IBlockState toPlant = this.getPlantablePlantFromStack(seed, world, pos);
|
||||
if(toPlant != null){
|
||||
if(this.tryPlant(toPlant, world, pos)){
|
||||
if(tryPlant(toPlant, world, pos)){
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){
|
||||
world.setBlockState(farmland, Blocks.FARMLAND.getDefaultState(), 2);
|
||||
world.setBlockToAir(pos);
|
||||
world.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){
|
||||
world.setBlockState(farmland, Blocks.FARMLAND.getDefaultState(), 2);
|
||||
world.setBlockToAir(pos);
|
||||
world.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
|
||||
|
||||
if(tryPlant(toPlant, world, pos)){
|
||||
farmer.extractEnergy(use);
|
||||
|
||||
if(this.tryPlant(toPlant, world, pos)){
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,8 +74,8 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean tryPlant(IBlockState toPlant, World world, BlockPos pos){
|
||||
BlockCrops plantBlock = (BlockCrops)toPlant.getBlock();
|
||||
private static boolean tryPlant(IBlockState toPlant, World world, BlockPos pos){
|
||||
BlockBush plantBlock = (BlockBush)toPlant.getBlock();
|
||||
if(plantBlock.canPlaceBlockAt(world, pos) && plantBlock.canBlockStay(world, pos, toPlant)){
|
||||
//This fixes a bug with Beetroot being able to be planted anywhere because Minecraft sucks
|
||||
if(plantBlock != Blocks.BEETROOTS || Blocks.WHEAT.canPlaceBlockAt(world, pos)){
|
||||
|
@ -83,7 +87,7 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 250;
|
||||
if(farmer.getEnergy() >= use){
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
@ -121,12 +125,17 @@ public class DefaultFarmerBehavior implements IFarmerBehavior{
|
|||
world.setBlockToAir(pos);
|
||||
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
private IBlockState getPlantablePlantFromStack(ItemStack stack, World world, BlockPos pos){
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* This file ("MelonPumpkinFarmerBehavior.java") is part of the Actually Additions mod for Minecraft.
|
||||
* It is created and owned by Ellpeck and distributed
|
||||
* under the Actually Additions License to be found at
|
||||
* http://ellpeck.de/actaddlicense
|
||||
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
||||
*
|
||||
* © 2015-2017 Ellpeck
|
||||
*/
|
||||
|
||||
package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MelonPumpkinFarmerBehavior implements IFarmerBehavior{
|
||||
|
||||
@Override
|
||||
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 350;
|
||||
if(farmer.getEnergy() >= use*2){
|
||||
if(StackUtil.isValid(seed)){
|
||||
Item seedItem = seed.getItem();
|
||||
boolean isPumpkin = seedItem == Items.PUMPKIN_SEEDS;
|
||||
if(isPumpkin || seedItem == Items.MELON_SEEDS){
|
||||
if((pos.getX()%2 == 0) == (pos.getZ()%2 == 0)){
|
||||
IBlockState toPlant = (isPumpkin ? Blocks.PUMPKIN_STEM : Blocks.MELON_STEM).getDefaultState();
|
||||
|
||||
if(DefaultFarmerBehavior.defaultPlant(world, pos, toPlant, farmer, use)){
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return FarmerResult.STOP_PROCESSING;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 500;
|
||||
if(farmer.getEnergy() >= use){
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
if(block == Blocks.PUMPKIN || block == Blocks.MELON_BLOCK){
|
||||
List<ItemStack> drops = state.getBlock().getDrops(world, pos, state, 0);
|
||||
if(drops != null && !drops.isEmpty()){
|
||||
if(farmer.addToOutputInventory(drops, false)){
|
||||
world.playEvent(2001, pos, Block.getStateId(state));
|
||||
world.setBlockToAir(pos);
|
||||
|
||||
farmer.extractEnergy(use);
|
||||
farmer.addToOutputInventory(drops, true);
|
||||
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
return FarmerResult.STOP_PROCESSING;
|
||||
}
|
||||
}
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(){
|
||||
return 10;
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -27,7 +28,7 @@ import java.util.List;
|
|||
public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
||||
|
||||
@Override
|
||||
public boolean tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 500;
|
||||
if(farmer.getEnergy() >= use){
|
||||
if(seed.getItem() == Items.NETHER_WART){
|
||||
|
@ -36,15 +37,16 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
|||
if(stateBelow.getBlock() instanceof BlockSoulSand && Blocks.NETHER_BRICK.canPlaceBlockAt(world, pos)){
|
||||
world.setBlockState(pos, Blocks.NETHER_WART.getDefaultState(), 2);
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
return FarmerResult.STOP_PROCESSING;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 500;
|
||||
if(farmer.getEnergy() >= use){
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
|
@ -65,12 +67,18 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
|||
}
|
||||
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FarmerResult.STOP_PROCESSING;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
package de.ellpeck.actuallyadditions.mod.misc.apiimpl.farmer;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -26,26 +27,29 @@ import java.util.List;
|
|||
public class ReedFarmerBehavior implements IFarmerBehavior{
|
||||
|
||||
@Override
|
||||
public boolean tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 250;
|
||||
if(farmer.getEnergy() >= use){
|
||||
if(seed.getItem() == Items.REEDS){
|
||||
if(Blocks.REEDS.canPlaceBlockAt(world, pos)){
|
||||
world.setBlockState(pos, Blocks.REEDS.getDefaultState(), 2);
|
||||
farmer.extractEnergy(use);
|
||||
return true;
|
||||
return FarmerResult.SUCCESS;
|
||||
}
|
||||
return FarmerResult.STOP_PROCESSING;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
public FarmerResult tryHarvestPlant(World world, BlockPos pos, IFarmer farmer){
|
||||
int use = 250;
|
||||
if(farmer.getEnergy() >= use){
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
if(state.getBlock() instanceof BlockReed){
|
||||
FarmerResult result = FarmerResult.STOP_PROCESSING;
|
||||
|
||||
for(int i = 2; i >= 1; --i){
|
||||
if(farmer.getEnergy() >= use){
|
||||
BlockPos up = pos.up(i);
|
||||
|
@ -55,19 +59,27 @@ public class ReedFarmerBehavior implements IFarmerBehavior{
|
|||
|
||||
if(drops != null && !drops.isEmpty()){
|
||||
if(farmer.addToOutputInventory(drops, false)){
|
||||
world.playEvent(2011, up, Block.getStateId(upState));
|
||||
world.playEvent(2001, up, Block.getStateId(upState));
|
||||
world.setBlockToAir(up);
|
||||
|
||||
farmer.extractEnergy(use);
|
||||
farmer.addToOutputInventory(drops, true);
|
||||
|
||||
result = FarmerResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return FarmerResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority(){
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package de.ellpeck.actuallyadditions.mod.tile;
|
||||
|
||||
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||
import de.ellpeck.actuallyadditions.api.farmer.FarmerResult;
|
||||
import de.ellpeck.actuallyadditions.api.farmer.IFarmerBehavior;
|
||||
import de.ellpeck.actuallyadditions.api.internal.IFarmer;
|
||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||
|
@ -23,10 +24,14 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer{
|
||||
|
||||
private static final List<IFarmerBehavior> SORTED_FARMER_BEHAVIORS = new ArrayList<IFarmerBehavior>();
|
||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(100000, 1000, 0);
|
||||
|
||||
private int waitTime;
|
||||
|
@ -105,18 +110,37 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer
|
|||
}
|
||||
|
||||
private void checkBehaviors(BlockPos query){
|
||||
for(IFarmerBehavior behavior : ActuallyAdditionsAPI.FARMER_BEHAVIORS){
|
||||
if(behavior.tryHarvestPlant(this.world, query, this)){
|
||||
if(SORTED_FARMER_BEHAVIORS.size() != ActuallyAdditionsAPI.FARMER_BEHAVIORS.size()){
|
||||
SORTED_FARMER_BEHAVIORS.clear();
|
||||
SORTED_FARMER_BEHAVIORS.addAll(ActuallyAdditionsAPI.FARMER_BEHAVIORS);
|
||||
|
||||
Collections.sort(SORTED_FARMER_BEHAVIORS, new Comparator<IFarmerBehavior>(){
|
||||
@Override
|
||||
public int compare(IFarmerBehavior behavior1, IFarmerBehavior behavior2){
|
||||
Integer prio1 = behavior1.getPriority();
|
||||
Integer prio2 = behavior2.getPriority();
|
||||
return prio2.compareTo(prio1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for(IFarmerBehavior behavior : SORTED_FARMER_BEHAVIORS){
|
||||
FarmerResult harvestResult = behavior.tryHarvestPlant(this.world, query, this);
|
||||
if(harvestResult == FarmerResult.SUCCESS || harvestResult == FarmerResult.STOP_PROCESSING){
|
||||
return;
|
||||
}
|
||||
else{
|
||||
for(int i = 0; i < this.slots.getSlots(); i++){
|
||||
ItemStack stack = this.slots.getStackInSlot(i);
|
||||
if(StackUtil.isValid(stack)){
|
||||
if(behavior.tryPlantSeed(stack, this.world, query, this)){
|
||||
FarmerResult plantResult = behavior.tryPlantSeed(stack, this.world, query, this);
|
||||
if(plantResult == FarmerResult.SUCCESS){
|
||||
this.slots.decrStackSize(i, 1);
|
||||
return;
|
||||
}
|
||||
else if(plantResult == FarmerResult.STOP_PROCESSING){
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1204,6 +1204,7 @@ booklet.actuallyadditions.chapter.farmer.text.2=Farming basic crops <imp>crops<r
|
|||
booklet.actuallyadditions.chapter.farmer.text.3=Farming <item>Cactus<r>. Sand needs to be laid out for it to be planted. <imp><item>Cactus<r> higher than 2 blocks will have the <imp>top broken off<r> and placed inside of the Farmer.
|
||||
booklet.actuallyadditions.chapter.farmer.text.4=Farming <item>Nether Wart<r>. Soul Sand needs to be laid out for it to be planted.
|
||||
booklet.actuallyadditions.chapter.farmer.text.5=Farming <item>Sugar Cane<r>. Sand and water need to be laid out for it to be planted. Harvested in the same way as <item>Cactus<r>.
|
||||
booklet.actuallyadditions.chapter.farmer.text.6=Farming <item>Melons<r> and <item>Pumpkins<r>. There will be <imp>checkerboarded air spaces<r> left out inbetween the seeds for them to grow.
|
||||
|
||||
booklet.actuallyadditions.chapter.lensMoreDeath.name=Lens of the Killer
|
||||
booklet.actuallyadditions.chapter.lensMoreDeath.text.1=The <item>Lens of the Killer<r> works much like the <item>Lens of Certain Death<r>, however it will also <imp>drop experience<r> and <imp>player-kill loot<r>. <n>This means, however, that it will use <imp>a lot more power<r>. <n><n>To pick up the experience it drops, you might want to try an <item>Experience Solidifier<r>.
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
Loading…
Reference in a new issue