Added support for Botanias horn of the wild to BoP flowers & plants, Closes #804 (#848)

* Added support for Botanias horn of the wild to BoP flowers & plants

* Made IHornHarvestable optional inferface
This commit is contained in:
Girafi 2016-08-24 20:50:55 +02:00 committed by Forstride
parent 6c6ab5188a
commit 57ca9427f2
4 changed files with 138 additions and 16 deletions

View File

@ -1,4 +1,4 @@
minecraft_version=1.10.2
forge_version=12.18.1.2046
forge_version=12.18.1.2073
mod_version=5.0.0
mappings_version=snapshot_nodoc_20160808

View File

@ -0,0 +1,65 @@
/**
* This class was created by <Vazkii>. It's distributed as
* part of the Botania Mod. Get the Source Code in github:
* https://github.com/Vazkii/Botania
*
* Botania is Open Source and distributed under the
* Botania License: http://botaniamod.net/license.php
*
* File Created @ [Oct 24, 2015, 11:16:00 PM (GMT)]
*/
package vazkii.botania.api.item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
* A Block that implements this can be uprooted by the various horns in Botania.
*/
public interface IHornHarvestable {
/**
* Returns true if this block can be uprooted.
* Note that the stack param can be null if it's a drum breaking it.
*/
public boolean canHornHarvest(World world, BlockPos pos, ItemStack stack, EnumHornType hornType);
/**
* Returns true if harvestByHorn() should be called. If false it just uses the normal
* block breaking method.
* Note that the stack param can be null if it's a drum breaking it.
*/
public boolean hasSpecialHornHarvest(World world, BlockPos pos, ItemStack stack, EnumHornType hornType);
/**
* Called to harvest by a horn.
* Note that the stack param can be null if it's a drum breaking it.
*/
public void harvestByHorn(World world, BlockPos pos, ItemStack stack, EnumHornType hornType);
public static enum EnumHornType {
/**
* Horn of the Wild, for grass and crops
*/
WILD,
/**
* Horn of the Canopy, for leaves
*/
CANOPY,
/**
* Horn of the Covering, for snow
*/
COVERING;
public static EnumHornType getTypeForMeta(int meta) {
EnumHornType[] values = EnumHornType.values();
return values[Math.min(values.length - 1, meta)];
}
};
}

View File

@ -8,10 +8,6 @@
package biomesoplenty.common.block;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import biomesoplenty.api.block.BOPBlocks;
import biomesoplenty.api.enums.BOPFlowers;
import biomesoplenty.common.config.GameplayConfigurationHandler;
@ -39,10 +35,17 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.item.IHornHarvestable;
public class BlockBOPFlower extends BlockBOPDecoration implements IShearable
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@Optional.Interface(iface = "vazkii.botania.api.item.IHornHarvestable", modid = "Botania")
public class BlockBOPFlower extends BlockBOPDecoration implements IShearable, IHornHarvestable
{
// setup paged variant property
@ -342,8 +345,30 @@ public class BlockBOPFlower extends BlockBOPDecoration implements IShearable
@Override
public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { return new ArrayList<ItemStack>(); }
@Override
@Optional.Method(modid = "Botania")
public boolean canHornHarvest(World world, BlockPos pos, ItemStack stack, EnumHornType hornType)
{
if (hornType != EnumHornType.WILD) return false;
BOPFlowers flower = ((BOPFlowers) world.getBlockState(pos).getValue(this.variantProperty));
switch (flower)
{
default:
return true;
}
}
@Override
@Optional.Method(modid = "Botania")
public boolean hasSpecialHornHarvest(World world, BlockPos pos, ItemStack stack, EnumHornType hornType)
{
return false;
}
@Override
@Optional.Method(modid = "Botania")
public void harvestByHorn(World world, BlockPos pos, ItemStack stack, EnumHornType hornType)
{
}
}

View File

@ -8,9 +8,6 @@
package biomesoplenty.common.block;
import java.util.List;
import java.util.Random;
import biomesoplenty.api.block.BlockQueries;
import biomesoplenty.api.enums.BOPPlants;
import biomesoplenty.api.item.BOPItems;
@ -50,12 +47,18 @@ import net.minecraft.world.biome.BiomeColorHelper;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.IShearable;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.common.Optional;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import vazkii.botania.api.item.IHornHarvestable;
import java.util.List;
import java.util.Random;
// TODO: pick block?
public class BlockBOPPlant extends BlockBOPDecoration implements IShearable
@Optional.Interface(iface = "vazkii.botania.api.item.IHornHarvestable", modid = "Botania")
public class BlockBOPPlant extends BlockBOPDecoration implements IShearable, IHornHarvestable
{
// setup paged variant property
@ -569,8 +572,37 @@ public class BlockBOPPlant extends BlockBOPDecoration implements IShearable
return Blocks.TALLGRASS.getFireSpreadSpeed(world, pos, face);
}
}
// TODO: pickblock on carrot?
@Override
@Optional.Method(modid = "Botania")
public boolean canHornHarvest(World world, BlockPos pos, ItemStack stack, EnumHornType hornType)
{
if (hornType != EnumHornType.WILD) return false;
BOPPlants plant = ((BOPPlants) world.getBlockState(pos).getValue(this.variantProperty));
switch (plant)
{
case BUSH:
case BERRYBUSH:
case RIVERCANE:
case TINYCACTUS:
case WITHERWART:
return false;
default:
return true;
}
}
@Override
@Optional.Method(modid = "Botania")
public boolean hasSpecialHornHarvest(World world, BlockPos pos, ItemStack stack, EnumHornType hornType)
{
return false;
}
@Override
@Optional.Method(modid = "Botania")
public void harvestByHorn(World world, BlockPos pos, ItemStack stack, EnumHornType hornType)
{
}
}