mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-20 12:19:46 +00:00
Added IHornHarvestable to the API.
This commit is contained in:
1 parent
952b71d9a0
commit
274c7e346b
6 files changed
+107
-14
No files matched your search
@@ -15,7 +15,9 @@ import net.minecraft.world.World;
|
||||
/**
|
||||
* A BlockBush can implement this to check if it can be broken
|
||||
* by a Horn/Drum of the Wild or not.
|
||||
* @Deprecated Use IHornHarvestable instead
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IGrassHornExcempt {
|
||||
|
||||
public boolean canUproot(World world, int x, int y, int z);
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 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.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, int x, int y, int z, 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, int x, int y, int z, 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, int x, int y, int z, 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)];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import thaumcraft.api.crafting.IInfusionStabiliser;
|
||||
import vazkii.botania.api.item.IGrassHornExcempt;
|
||||
import vazkii.botania.api.item.IHornHarvestable;
|
||||
import vazkii.botania.api.lexicon.ILexiconable;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
@@ -44,7 +45,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@Optional.Interface(modid = "Thaumcraft", iface = "thaumcraft.api.crafting.IInfusionStabiliser", striprefs = true)
|
||||
public class BlockModMushroom extends BlockMushroom implements IInfusionStabiliser, IGrassHornExcempt, ILexiconable {
|
||||
public class BlockModMushroom extends BlockMushroom implements IInfusionStabiliser, IHornHarvestable, ILexiconable {
|
||||
|
||||
public static IIcon[] icons;
|
||||
public int originalLight;
|
||||
@@ -131,14 +132,24 @@ public class BlockModMushroom extends BlockMushroom implements IInfusionStabilis
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUproot(World world, int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LexiconEntry getEntry(World world, int x, int y, int z, EntityPlayer player, ItemStack lexicon) {
|
||||
return LexiconData.mushrooms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHornHarvest(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSpecialHornHarvest(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void harvestByHorn(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import thaumcraft.api.crafting.IInfusionStabiliser;
|
||||
import vazkii.botania.api.item.IGrassHornExcempt;
|
||||
import vazkii.botania.api.item.IHornHarvestable;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
import vazkii.botania.common.block.BlockModFlower;
|
||||
import vazkii.botania.common.block.ModBlocks;
|
||||
@@ -27,7 +28,7 @@ import vazkii.botania.common.lib.LibBlockNames;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
@Optional.Interface(modid = "Thaumcraft", iface = "thaumcraft.api.crafting.IInfusionStabiliser", striprefs = true)
|
||||
public class BlockShinyFlower extends BlockModFlower implements IInfusionStabiliser, IGrassHornExcempt {
|
||||
public class BlockShinyFlower extends BlockModFlower implements IInfusionStabiliser, IHornHarvestable {
|
||||
|
||||
public BlockShinyFlower() {
|
||||
super(LibBlockNames.SHINY_FLOWER);
|
||||
@@ -66,8 +67,18 @@ public class BlockShinyFlower extends BlockModFlower implements IInfusionStabili
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUproot(World world, int x, int y, int z) {
|
||||
public boolean canHornHarvest(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSpecialHornHarvest(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void harvestByHorn(World world, int x, int y, int z, ItemStack stack, EnumHornType hornType) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
}
|
||||
@@ -112,9 +112,9 @@ public class BlockForestDrum extends BlockMod implements IManaTrigger, ILexicona
|
||||
return;
|
||||
|
||||
if(world.getBlockMetadata(x, y, z) == 0)
|
||||
ItemGrassHorn.breakGrass(world, 0, x, y, z);
|
||||
ItemGrassHorn.breakGrass(world, null, 0, x, y, z);
|
||||
else if(world.getBlockMetadata(x, y, z) == 2)
|
||||
ItemGrassHorn.breakGrass(world, 1, x, y, z);
|
||||
ItemGrassHorn.breakGrass(world, null, 1, x, y, z);
|
||||
else if(!world.isRemote) {
|
||||
int range = 10;
|
||||
List<EntityLiving> entities = world.getEntitiesWithinAABB(EntityLiving.class, AxisAlignedBB.getBoundingBox(x - range, y - range, z - range, x + range + 1, y + range + 1, z + range + 1));
|
||||
|
||||
@@ -29,6 +29,8 @@ import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.item.IGrassHornExcempt;
|
||||
import vazkii.botania.api.item.IHornHarvestable;
|
||||
import vazkii.botania.api.item.IHornHarvestable.EnumHornType;
|
||||
import vazkii.botania.api.subtile.ISpecialFlower;
|
||||
import vazkii.botania.client.core.helper.IconHelper;
|
||||
import vazkii.botania.common.core.handler.ConfigHandler;
|
||||
@@ -104,13 +106,14 @@ public class ItemGrassHorn extends ItemMod {
|
||||
@Override
|
||||
public void onUsingTick(ItemStack stack, EntityPlayer player, int time) {
|
||||
if(time != getMaxItemUseDuration(stack) && time % 5 == 0)
|
||||
breakGrass(player.worldObj, stack.getItemDamage(), (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
breakGrass(player.worldObj, stack, stack.getItemDamage(), (int) player.posX, (int) player.posY, (int) player.posZ);
|
||||
|
||||
if(!player.worldObj.isRemote)
|
||||
player.worldObj.playSoundAtEntity(player, "note.bassattack", 1F, 0.001F);
|
||||
}
|
||||
|
||||
public static void breakGrass(World world, int stackDmg, int srcx, int srcy, int srcz) {
|
||||
public static void breakGrass(World world, ItemStack stack, int stackDmg, int srcx, int srcy, int srcz) {
|
||||
EnumHornType type = EnumHornType.getTypeForMeta(stackDmg);
|
||||
Random rand = new Random(srcx ^ srcy ^ srcz);
|
||||
int range = 12 - stackDmg * 3;
|
||||
int rangeY = 3 + stackDmg * 4;
|
||||
@@ -124,7 +127,7 @@ public class ItemGrassHorn extends ItemMod {
|
||||
int z = srcz + j;
|
||||
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if(stackDmg == 0 && block instanceof BlockBush && !(block instanceof ISpecialFlower) && (!(block instanceof IGrassHornExcempt) || ((IGrassHornExcempt) block).canUproot(world, x, y, z)) || stackDmg == 1 && block.isLeaves(world, x, y, z) || stackDmg == 2 && block == Blocks.snow_layer)
|
||||
if(block instanceof IHornHarvestable ? ((IHornHarvestable) block).canHornHarvest(world, x, y, z, stack, type) : (stackDmg == 0 && block instanceof BlockBush && !(block instanceof ISpecialFlower) && (!(block instanceof IGrassHornExcempt) || ((IGrassHornExcempt) block).canUproot(world, x, y, z)) || stackDmg == 1 && block.isLeaves(world, x, y, z) || stackDmg == 2 && block == Blocks.snow_layer))
|
||||
coords.add(new ChunkCoordinates(x, y, z));
|
||||
}
|
||||
|
||||
@@ -138,7 +141,9 @@ public class ItemGrassHorn extends ItemMod {
|
||||
int meta = world.getBlockMetadata(currCoords.posX, currCoords.posY, currCoords.posZ);
|
||||
items.addAll(block.getDrops(world, currCoords.posX, currCoords.posY, currCoords.posZ, meta, 0));
|
||||
|
||||
if(!world.isRemote) {
|
||||
if(block instanceof IHornHarvestable && ((IHornHarvestable) block).hasSpecialHornHarvest(world, currCoords.posX, currCoords.posY, currCoords.posZ, stack, type))
|
||||
((IHornHarvestable) block).harvestByHorn(world, currCoords.posX, currCoords.posY, currCoords.posZ, stack, type);
|
||||
else if(!world.isRemote) {
|
||||
world.setBlockToAir(currCoords.posX, currCoords.posY, currCoords.posZ);
|
||||
if(ConfigHandler.blockBreakParticles)
|
||||
world.playAuxSFX(2001, currCoords.posX, currCoords.posY, currCoords.posZ, Block.getIdFromBlock(block) + (meta << 12));
|
||||
|
||||
Reference in new issue
Block a user