mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Fix up farmer behaviors
This commit is contained in:
parent
7a5b1dcd1c
commit
f59c431649
8 changed files with 61 additions and 42 deletions
|
@ -10,8 +10,24 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.api.farmer;
|
package de.ellpeck.actuallyadditions.api.farmer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return values for IFarmerBehavior, each one has a different meaning in harvest and planting contexts.
|
||||||
|
*
|
||||||
|
*/
|
||||||
public enum FarmerResult {
|
public enum FarmerResult {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that your behavior failed to perform the action it attempted.
|
||||||
|
*/
|
||||||
FAIL,
|
FAIL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that your behavior succeeded doing the action it attempted. For harvesting, this also shrinks the current stack by one, and stops processing.
|
||||||
|
*/
|
||||||
SUCCESS,
|
SUCCESS,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates you want the farmer to halt all further actions this tick. This will exit the farmer behavior loop if returned.
|
||||||
|
*/
|
||||||
STOP_PROCESSING
|
STOP_PROCESSING
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,5 +42,7 @@ public interface IFarmerBehavior{
|
||||||
|
|
||||||
int getPriority();
|
int getPriority();
|
||||||
|
|
||||||
default Integer getPrioInt() { return getPriority(); }
|
default Integer getPrioInt() {
|
||||||
|
return getPriority();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class CactusFarmerBehavior implements IFarmerBehavior{
|
||||||
farmer.extractEnergy(use);
|
farmer.extractEnergy(use);
|
||||||
return FarmerResult.SUCCESS;
|
return FarmerResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return FarmerResult.STOP_PROCESSING;
|
return FarmerResult.FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class DefaultFarmerBehavior implements IFarmerBehavior {
|
||||||
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer) {
|
public FarmerResult tryPlantSeed(ItemStack seed, World world, BlockPos pos, IFarmer farmer) {
|
||||||
int use = 350;
|
int use = 350;
|
||||||
if (farmer.getEnergy() >= use * 2) {
|
if (farmer.getEnergy() >= use * 2) {
|
||||||
if (defaultPlant(world, pos, this.getPlantablePlantFromStack(seed, world, pos), farmer, use)) { return FarmerResult.SUCCESS; }
|
if (defaultPlant(world, pos, this.getPlantablePlantFromStack(seed, world, pos), farmer, use)) return FarmerResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.FAIL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,11 @@ public class MelonPumpkinFarmerBehavior implements IFarmerBehavior{
|
||||||
if (isPumpkin || seedItem == Items.MELON_SEEDS) {
|
if (isPumpkin || seedItem == Items.MELON_SEEDS) {
|
||||||
if ((pos.getX() % 2 == 0) == (pos.getZ() % 2 == 0)) {
|
if ((pos.getX() % 2 == 0) == (pos.getZ() % 2 == 0)) {
|
||||||
IBlockState toPlant = (isPumpkin ? Blocks.PUMPKIN_STEM : Blocks.MELON_STEM).getDefaultState();
|
IBlockState toPlant = (isPumpkin ? Blocks.PUMPKIN_STEM : Blocks.MELON_STEM).getDefaultState();
|
||||||
|
if (DefaultFarmerBehavior.defaultPlant(world, pos, toPlant, farmer, use)) return FarmerResult.SUCCESS;
|
||||||
if(DefaultFarmerBehavior.defaultPlant(world, pos, toPlant, farmer, use)){
|
|
||||||
return FarmerResult.SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return FarmerResult.STOP_PROCESSING;
|
return FarmerResult.STOP_PROCESSING;
|
||||||
}
|
}
|
||||||
|
return FarmerResult.FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.FAIL;
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
||||||
farmer.extractEnergy(use);
|
farmer.extractEnergy(use);
|
||||||
return FarmerResult.SUCCESS;
|
return FarmerResult.SUCCESS;
|
||||||
}
|
}
|
||||||
return FarmerResult.STOP_PROCESSING;
|
return FarmerResult.FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.FAIL;
|
||||||
|
@ -70,7 +70,7 @@ public class NetherWartFarmerBehavior implements IFarmerBehavior{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.STOP_PROCESSING;
|
return FarmerResult.FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FarmerResult.FAIL;
|
return FarmerResult.FAIL;
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class ReedFarmerBehavior implements IFarmerBehavior{
|
||||||
farmer.extractEnergy(use);
|
farmer.extractEnergy(use);
|
||||||
farmer.addToOutput(drops);
|
farmer.addToOutput(drops);
|
||||||
|
|
||||||
result = FarmerResult.STOP_PROCESSING; //Success no longer makes it not replant, and the plant logic seems sketchy right after harvesting. This works tho.
|
result = FarmerResult.STOP_PROCESSING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,7 +127,10 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer
|
||||||
IBlockState state = world.getBlockState(query);
|
IBlockState state = world.getBlockState(query);
|
||||||
if (StackUtil.isValid(stack) && state.getBlock().isReplaceable(world, query)) {
|
if (StackUtil.isValid(stack) && state.getBlock().isReplaceable(world, query)) {
|
||||||
FarmerResult plantResult = behavior.tryPlantSeed(stack, this.world, query, this);
|
FarmerResult plantResult = behavior.tryPlantSeed(stack, this.world, query, this);
|
||||||
if (plantResult == FarmerResult.SUCCESS) this.inv.getStackInSlot(i).shrink(1);
|
if (plantResult == FarmerResult.SUCCESS) {
|
||||||
|
this.inv.getStackInSlot(i).shrink(1);
|
||||||
|
return;
|
||||||
|
} else if (plantResult == FarmerResult.STOP_PROCESSING) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue