Add handlers for "tall" and "stem" crops
Documentation for all harvest-y stuff as well.
This commit is contained in:
parent
4a9d37f8b3
commit
34e6350cbc
|
@ -2,17 +2,23 @@ package WayofTime.bloodmagic.api.registry;
|
||||||
|
|
||||||
import WayofTime.bloodmagic.api.BlockStack;
|
import WayofTime.bloodmagic.api.BlockStack;
|
||||||
import WayofTime.bloodmagic.api.iface.IHarvestHandler;
|
import WayofTime.bloodmagic.api.iface.IHarvestHandler;
|
||||||
|
import lombok.Getter;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockStem;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class HarvestRegistry
|
public class HarvestRegistry
|
||||||
{
|
{
|
||||||
|
@Getter
|
||||||
private static List<IHarvestHandler> handlerList = new ArrayList<IHarvestHandler>();
|
private static List<IHarvestHandler> handlerList = new ArrayList<IHarvestHandler>();
|
||||||
private static Map<Block, Integer> validBlocks = new HashMap<Block, Integer>();
|
@Getter
|
||||||
|
private static Map<Block, Integer> standardCrops = new HashMap<Block, Integer>();
|
||||||
|
@Getter
|
||||||
|
private static Set<BlockStack> tallCrops = new HashSet<BlockStack>();
|
||||||
|
@Getter
|
||||||
|
private static Map<BlockStack, BlockStack> stemCrops = new HashMap<BlockStack, BlockStack>();
|
||||||
|
@Getter
|
||||||
private static Map<BlockStack, Integer> amplifierMap = new HashMap<BlockStack, Integer>();
|
private static Map<BlockStack, Integer> amplifierMap = new HashMap<BlockStack, Integer>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,8 +46,43 @@ public class HarvestRegistry
|
||||||
*/
|
*/
|
||||||
public static void registerStandardCrop(Block crop, int matureMeta)
|
public static void registerStandardCrop(Block crop, int matureMeta)
|
||||||
{
|
{
|
||||||
if (!validBlocks.containsKey(crop))
|
if (!standardCrops.containsKey(crop))
|
||||||
validBlocks.put(crop, matureMeta);
|
standardCrops.put(crop, matureMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a tall crop (Sugar Cane and Cactus) for the
|
||||||
|
* {@link WayofTime.bloodmagic.ritual.harvest.HarvestHandlerTall} handler
|
||||||
|
* to handle.
|
||||||
|
*
|
||||||
|
* @param crop
|
||||||
|
* - The crop block to handle.
|
||||||
|
*/
|
||||||
|
public static void registerTallCrop(BlockStack crop)
|
||||||
|
{
|
||||||
|
if (!tallCrops.contains(crop))
|
||||||
|
tallCrops.add(crop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers a stem crop (Melon and Pumpkin) for the
|
||||||
|
* {@link WayofTime.bloodmagic.ritual.harvest.HarvestHandlerStem} handler
|
||||||
|
* to handle.
|
||||||
|
*
|
||||||
|
* Use {@link net.minecraftforge.oredict.OreDictionary#WILDCARD_VALUE} to accept
|
||||||
|
* any meta for the crop block.
|
||||||
|
*
|
||||||
|
* The Stem must be instanceof {@link BlockStem}
|
||||||
|
*
|
||||||
|
* @param crop
|
||||||
|
* - The crop block to handle.
|
||||||
|
* @param stem
|
||||||
|
* - The stem of the crop
|
||||||
|
*/
|
||||||
|
public static void registerStemCrop(BlockStack crop, BlockStack stem)
|
||||||
|
{
|
||||||
|
if (!stemCrops.containsKey(crop) && stem.getBlock() instanceof BlockStem)
|
||||||
|
stemCrops.put(stem, crop);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,16 +98,4 @@ public class HarvestRegistry
|
||||||
if (!amplifierMap.containsKey(blockStack))
|
if (!amplifierMap.containsKey(blockStack))
|
||||||
amplifierMap.put(blockStack, range);
|
amplifierMap.put(blockStack, range);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<IHarvestHandler> getHandlerList() {
|
|
||||||
return handlerList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<Block, Integer> getValidBlocks() {
|
|
||||||
return validBlocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Map<BlockStack, Integer> getAmplifierMap() {
|
|
||||||
return amplifierMap;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package WayofTime.bloodmagic.registry;
|
package WayofTime.bloodmagic.registry;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.BlockStack;
|
||||||
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
|
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
|
||||||
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
|
import WayofTime.bloodmagic.api.registry.ImperfectRitualRegistry;
|
||||||
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
import WayofTime.bloodmagic.api.registry.RitualRegistry;
|
||||||
|
@ -7,7 +8,10 @@ import WayofTime.bloodmagic.api.ritual.Ritual;
|
||||||
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
import WayofTime.bloodmagic.api.ritual.imperfect.ImperfectRitual;
|
||||||
import WayofTime.bloodmagic.ritual.*;
|
import WayofTime.bloodmagic.ritual.*;
|
||||||
import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerPlantable;
|
import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerPlantable;
|
||||||
|
import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerStem;
|
||||||
|
import WayofTime.bloodmagic.ritual.harvest.HarvestHandlerTall;
|
||||||
import WayofTime.bloodmagic.ritual.imperfect.*;
|
import WayofTime.bloodmagic.ritual.imperfect.*;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
|
||||||
public class ModRituals
|
public class ModRituals
|
||||||
{
|
{
|
||||||
|
@ -63,6 +67,12 @@ public class ModRituals
|
||||||
|
|
||||||
public static void initHarvestHandlers()
|
public static void initHarvestHandlers()
|
||||||
{
|
{
|
||||||
|
HarvestRegistry.registerRangeAmplifier(new BlockStack(Blocks.diamond_block), 15);
|
||||||
|
HarvestRegistry.registerRangeAmplifier(new BlockStack(Blocks.gold_block), 10);
|
||||||
|
HarvestRegistry.registerRangeAmplifier(new BlockStack(Blocks.iron_block), 6);
|
||||||
|
|
||||||
HarvestRegistry.registerHandler(new HarvestHandlerPlantable());
|
HarvestRegistry.registerHandler(new HarvestHandlerPlantable());
|
||||||
|
HarvestRegistry.registerHandler(new HarvestHandlerTall());
|
||||||
|
HarvestRegistry.registerHandler(new HarvestHandlerStem());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,23 @@ import WayofTime.bloodmagic.api.network.SoulNetwork;
|
||||||
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
|
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
|
||||||
import WayofTime.bloodmagic.api.ritual.*;
|
import WayofTime.bloodmagic.api.ritual.*;
|
||||||
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
import WayofTime.bloodmagic.api.util.helper.NetworkHelper;
|
||||||
import net.minecraft.init.Blocks;
|
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This ritual uses registered {@link IHarvestHandler}'s to
|
||||||
|
* harvest blocks.
|
||||||
|
*
|
||||||
|
* To register a new Handler for this ritual use
|
||||||
|
* {@link HarvestRegistry#registerHandler(IHarvestHandler)}
|
||||||
|
*
|
||||||
|
* This ritual includes a way to change the range based on what block
|
||||||
|
* is above the MasterRitualStone. You can use
|
||||||
|
* {@link HarvestRegistry#registerRangeAmplifier(BlockStack, int)}
|
||||||
|
* to register a new amplifier.
|
||||||
|
*/
|
||||||
public class RitualHarvest extends Ritual
|
public class RitualHarvest extends Ritual
|
||||||
{
|
{
|
||||||
public static final String HARVEST_RANGE = "harvestRange";
|
public static final String HARVEST_RANGE = "harvestRange";
|
||||||
|
@ -20,10 +31,6 @@ public class RitualHarvest extends Ritual
|
||||||
public RitualHarvest()
|
public RitualHarvest()
|
||||||
{
|
{
|
||||||
super("ritualHarvest", 0, 20000, "ritual." + Constants.Mod.MODID + ".harvestRitual");
|
super("ritualHarvest", 0, 20000, "ritual." + Constants.Mod.MODID + ".harvestRitual");
|
||||||
|
|
||||||
HarvestRegistry.registerRangeAmplifier(new BlockStack(Blocks.diamond_block), 15);
|
|
||||||
HarvestRegistry.registerRangeAmplifier(new BlockStack(Blocks.gold_block), 10);
|
|
||||||
HarvestRegistry.registerRangeAmplifier(new BlockStack(Blocks.iron_block), 6);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,6 +13,13 @@ import net.minecraftforge.common.IPlantable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Harvest handler for standard plantable crops such as
|
||||||
|
* Wheat, Potatoes, and Netherwart.
|
||||||
|
* <br>
|
||||||
|
* Register a new crop for this handler with
|
||||||
|
* {@link HarvestRegistry#registerStandardCrop(Block, int)}
|
||||||
|
*/
|
||||||
public class HarvestHandlerPlantable implements IHarvestHandler
|
public class HarvestHandlerPlantable implements IHarvestHandler
|
||||||
{
|
{
|
||||||
public HarvestHandlerPlantable()
|
public HarvestHandlerPlantable()
|
||||||
|
@ -26,10 +33,10 @@ public class HarvestHandlerPlantable implements IHarvestHandler
|
||||||
@Override
|
@Override
|
||||||
public boolean harvestAndPlant(World world, BlockPos pos, BlockStack blockStack)
|
public boolean harvestAndPlant(World world, BlockPos pos, BlockStack blockStack)
|
||||||
{
|
{
|
||||||
if (!HarvestRegistry.getValidBlocks().containsKey(blockStack.getBlock()))
|
if (!HarvestRegistry.getStandardCrops().containsKey(blockStack.getBlock()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
int matureMeta = HarvestRegistry.getValidBlocks().get(blockStack.getBlock());
|
int matureMeta = HarvestRegistry.getStandardCrops().get(blockStack.getBlock());
|
||||||
|
|
||||||
if(blockStack.getMeta() < matureMeta)
|
if(blockStack.getMeta() < matureMeta)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package WayofTime.bloodmagic.ritual.harvest;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.BlockStack;
|
||||||
|
import WayofTime.bloodmagic.api.iface.IHarvestHandler;
|
||||||
|
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
|
||||||
|
import net.minecraft.block.BlockStem;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.util.EnumFacing;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Harvest handler for crops with stems such as Pumpkins and Melons.
|
||||||
|
* {@link OreDictionary#WILDCARD_VALUE} is used as a wildcard to allow
|
||||||
|
* the crop to be harvested at any metadata. Rotation based crop blocks
|
||||||
|
* are a good reason to use this (see pumpkins).
|
||||||
|
* <br>
|
||||||
|
* Register a new crop for this handler with
|
||||||
|
* {@link HarvestRegistry#registerStemCrop(BlockStack, BlockStack)}
|
||||||
|
*/
|
||||||
|
public class HarvestHandlerStem implements IHarvestHandler
|
||||||
|
{
|
||||||
|
public HarvestHandlerStem()
|
||||||
|
{
|
||||||
|
HarvestRegistry.registerStemCrop(new BlockStack(Blocks.pumpkin, OreDictionary.WILDCARD_VALUE), new BlockStack(Blocks.pumpkin_stem, 7));
|
||||||
|
HarvestRegistry.registerStemCrop(new BlockStack(Blocks.melon_block), new BlockStack(Blocks.melon_stem, 7));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean harvestAndPlant(World world, BlockPos pos, BlockStack blockStack)
|
||||||
|
{
|
||||||
|
boolean retFlag = false;
|
||||||
|
List<ItemStack> drops = new ArrayList<ItemStack>();
|
||||||
|
BlockPos cropPos = pos;
|
||||||
|
if (HarvestRegistry.getStemCrops().containsKey(blockStack))
|
||||||
|
{
|
||||||
|
EnumFacing cropDir = blockStack.getBlock().getActualState(blockStack.getState(), world, pos).getValue(BlockStem.FACING);
|
||||||
|
|
||||||
|
if (cropDir != EnumFacing.UP)
|
||||||
|
{
|
||||||
|
cropPos = pos.offset(cropDir);
|
||||||
|
BlockStack probableCrop = BlockStack.getStackFromPos(world, cropPos);
|
||||||
|
BlockStack regCrop = HarvestRegistry.getStemCrops().get(blockStack);
|
||||||
|
|
||||||
|
if ((regCrop.getMeta() == OreDictionary.WILDCARD_VALUE && regCrop.getBlock() == probableCrop.getBlock()) || regCrop == probableCrop)
|
||||||
|
{
|
||||||
|
drops = probableCrop.getBlock().getDrops(world, cropPos, probableCrop.getState(), 0);
|
||||||
|
world.destroyBlock(cropPos, false);
|
||||||
|
retFlag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
|
for (ItemStack drop : drops)
|
||||||
|
{
|
||||||
|
EntityItem item = new EntityItem(world, cropPos.getX(), cropPos.getY() + 0.5, cropPos.getZ(), drop);
|
||||||
|
world.spawnEntityInWorld(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retFlag;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package WayofTime.bloodmagic.ritual.harvest;
|
||||||
|
|
||||||
|
import WayofTime.bloodmagic.api.BlockStack;
|
||||||
|
import WayofTime.bloodmagic.api.iface.IHarvestHandler;
|
||||||
|
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Harvest handler for crops that grow vertically such as
|
||||||
|
* Sugar Cane and Cactus.
|
||||||
|
* <br>
|
||||||
|
* Register a new crop for this handler with
|
||||||
|
* {@link HarvestRegistry#registerTallCrop(BlockStack)}
|
||||||
|
*/
|
||||||
|
public class HarvestHandlerTall implements IHarvestHandler
|
||||||
|
{
|
||||||
|
public HarvestHandlerTall()
|
||||||
|
{
|
||||||
|
HarvestRegistry.registerTallCrop(new BlockStack(Blocks.reeds));
|
||||||
|
HarvestRegistry.registerTallCrop(new BlockStack(Blocks.cactus));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean harvestAndPlant(World world, BlockPos pos, BlockStack blockStack)
|
||||||
|
{
|
||||||
|
boolean retFlag = false;
|
||||||
|
|
||||||
|
List<ItemStack> drops = new ArrayList<ItemStack>();
|
||||||
|
if (HarvestRegistry.getTallCrops().contains(blockStack))
|
||||||
|
{
|
||||||
|
BlockStack up = BlockStack.getStackFromPos(world, pos.up());
|
||||||
|
if (up.equals(blockStack))
|
||||||
|
{
|
||||||
|
drops = up.getBlock().getDrops(world, pos.up(), up.getState(), 0);
|
||||||
|
world.destroyBlock(pos.up(), false);
|
||||||
|
retFlag = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!world.isRemote)
|
||||||
|
{
|
||||||
|
for (ItemStack drop : drops)
|
||||||
|
{
|
||||||
|
EntityItem item = new EntityItem(world, pos.getX(), pos.getY() + 0.5, pos.getZ(), drop);
|
||||||
|
world.spawnEntityInWorld(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return retFlag;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue