2016-01-08 00:32:03 -08:00
|
|
|
package WayofTime.bloodmagic.ritual.harvest;
|
|
|
|
|
2016-02-25 08:54:18 -05:00
|
|
|
import java.util.List;
|
|
|
|
|
2016-01-08 16:14:27 -08:00
|
|
|
import net.minecraft.block.Block;
|
2016-01-08 00:32:03 -08:00
|
|
|
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 net.minecraftforge.common.IPlantable;
|
2016-02-25 08:54:18 -05:00
|
|
|
import WayofTime.bloodmagic.api.BlockStack;
|
|
|
|
import WayofTime.bloodmagic.api.iface.IHarvestHandler;
|
|
|
|
import WayofTime.bloodmagic.api.registry.HarvestRegistry;
|
2016-01-08 00:32:03 -08:00
|
|
|
|
2016-01-09 01:54:25 -08:00
|
|
|
/**
|
|
|
|
* 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)}
|
|
|
|
*/
|
2016-01-08 00:32:03 -08:00
|
|
|
public class HarvestHandlerPlantable implements IHarvestHandler
|
|
|
|
{
|
|
|
|
public HarvestHandlerPlantable()
|
|
|
|
{
|
|
|
|
HarvestRegistry.registerStandardCrop(Blocks.carrots, 7);
|
|
|
|
HarvestRegistry.registerStandardCrop(Blocks.wheat, 7);
|
|
|
|
HarvestRegistry.registerStandardCrop(Blocks.potatoes, 7);
|
|
|
|
HarvestRegistry.registerStandardCrop(Blocks.nether_wart, 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean harvestAndPlant(World world, BlockPos pos, BlockStack blockStack)
|
|
|
|
{
|
2016-01-09 01:54:25 -08:00
|
|
|
if (!HarvestRegistry.getStandardCrops().containsKey(blockStack.getBlock()))
|
2016-01-08 00:32:03 -08:00
|
|
|
return false;
|
|
|
|
|
2016-01-09 01:54:25 -08:00
|
|
|
int matureMeta = HarvestRegistry.getStandardCrops().get(blockStack.getBlock());
|
2016-01-08 00:32:03 -08:00
|
|
|
|
|
|
|
if(blockStack.getMeta() < matureMeta)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
List<ItemStack> drops = blockStack.getBlock().getDrops(world, pos, blockStack.getState(), 0);
|
|
|
|
boolean foundSeed = false;
|
|
|
|
|
|
|
|
for (ItemStack stack : drops) {
|
|
|
|
if (stack == null)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (stack.getItem() instanceof IPlantable)
|
|
|
|
{
|
|
|
|
if (stack.stackSize > 1)
|
|
|
|
stack.stackSize--;
|
|
|
|
else
|
|
|
|
drops.remove(stack);
|
|
|
|
|
|
|
|
foundSeed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (foundSeed)
|
|
|
|
{
|
2016-01-08 16:14:27 -08:00
|
|
|
world.setBlockState(pos, blockStack.getBlock().getDefaultState());
|
|
|
|
world.playAuxSFX(2001, pos, Block.getIdFromBlock(blockStack.getBlock()) + (blockStack.getMeta() << 12));
|
2016-01-08 00:32:03 -08:00
|
|
|
for (ItemStack stack : drops)
|
|
|
|
{
|
|
|
|
if (!world.isRemote)
|
|
|
|
{
|
|
|
|
EntityItem toDrop = new EntityItem(world, pos.getX(), pos.getY() + 0.5, pos.getZ(), stack);
|
|
|
|
world.spawnEntityInWorld(toDrop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|