2015-03-29 15:29:05 +02:00
|
|
|
package ellpeck.actuallyadditions.items;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-04-24 19:22:03 +02:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-06-18 13:14:57 +02:00
|
|
|
import ellpeck.actuallyadditions.util.*;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockBush;
|
|
|
|
import net.minecraft.block.BlockLeavesBase;
|
|
|
|
import net.minecraft.client.renderer.texture.IIconRegister;
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.IIcon;
|
2015-08-01 19:04:45 +02:00
|
|
|
import net.minecraft.util.MathHelper;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-06-18 13:14:57 +02:00
|
|
|
import java.util.List;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2015-04-04 05:20:19 +02:00
|
|
|
public class ItemLeafBlower extends Item implements INameableItem{
|
2015-03-29 15:29:05 +02:00
|
|
|
|
|
|
|
private final boolean isAdvanced;
|
|
|
|
|
|
|
|
public ItemLeafBlower(boolean isAdvanced){
|
|
|
|
this.isAdvanced = isAdvanced;
|
|
|
|
this.setMaxStackSize(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onUsingTick(ItemStack stack, EntityPlayer player, int time){
|
|
|
|
if(!player.worldObj.isRemote){
|
|
|
|
if(time <= getMaxItemUseDuration(stack) && time % 2 == 0){
|
2015-07-17 07:59:06 +02:00
|
|
|
//Breaks the Blocks
|
2015-08-01 19:04:45 +02:00
|
|
|
this.breakStuff(player.worldObj, MathHelper.floor_double(player.posX), MathHelper.floor_double(player.posY), MathHelper.floor_double(player.posZ));
|
2015-07-17 07:59:06 +02:00
|
|
|
//Plays a Minecart sounds (It really sounds like a Leaf Blower!)
|
2015-08-15 20:41:45 +02:00
|
|
|
if(ConfigBoolValues.LEAF_BLOWER_SOUND.isEnabled()) player.worldObj.playSoundAtEntity(player, "minecart.base", 0.3F, 0.001F);
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 07:59:06 +02:00
|
|
|
/**
|
|
|
|
* Breaks (harvests) Grass and Leaves around
|
|
|
|
* @param world The World
|
|
|
|
* @param x The X Position of the Player
|
|
|
|
* @param y The Y Position of the Player
|
|
|
|
* @param z The Z Position of the Player
|
|
|
|
*/
|
2015-03-29 15:29:05 +02:00
|
|
|
public void breakStuff(World world, int x, int y, int z){
|
2015-08-15 20:41:45 +02:00
|
|
|
for(int reachX = -ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue(); reachX < ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue()+1; reachX++){
|
|
|
|
for(int reachZ = -ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue(); reachZ < ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue()+1; reachZ++){
|
|
|
|
for(int reachY = (this.isAdvanced ? -ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue() : -ConfigIntValues.LEAF_BLOWER_RANGE_UP.getValue()); reachY < (this.isAdvanced ? ConfigIntValues.LEAF_BLOWER_RANGE_SIDES.getValue()+1 : ConfigIntValues.LEAF_BLOWER_RANGE_UP.getValue()+1); reachY++){
|
2015-07-17 07:59:06 +02:00
|
|
|
//The current Block to break
|
2015-03-29 15:29:05 +02:00
|
|
|
Block block = world.getBlock(x+reachX, y+reachY, z+reachZ);
|
|
|
|
if(block != null && (block instanceof BlockBush || (this.isAdvanced && block instanceof BlockLeavesBase))){
|
2015-07-07 11:56:38 +02:00
|
|
|
WorldPos theCoord = new WorldPos(world, x+reachX, y+reachY, z+reachZ);
|
2015-07-07 11:51:05 +02:00
|
|
|
Block theBlock = world.getBlock(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
2015-07-17 23:22:10 +02:00
|
|
|
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
2015-07-07 11:51:05 +02:00
|
|
|
int meta = world.getBlockMetadata(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
2015-07-17 07:59:06 +02:00
|
|
|
//Gets all of the Drops the Block should have
|
2015-07-07 11:51:05 +02:00
|
|
|
drops.addAll(theBlock.getDrops(world, theCoord.getX(), theCoord.getY(), theCoord.getZ(), meta, 0));
|
2015-04-24 19:22:03 +02:00
|
|
|
|
2015-07-17 07:59:06 +02:00
|
|
|
//Deletes the Block
|
2015-07-07 11:51:05 +02:00
|
|
|
world.setBlockToAir(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
2015-07-17 07:59:06 +02:00
|
|
|
//Plays the Breaking Sound
|
2015-07-27 08:26:13 +02:00
|
|
|
world.playAuxSFX(2001, theCoord.getX(), theCoord.getY(), theCoord.getZ(), Block.getIdFromBlock(theBlock)+(meta << 12));
|
2015-04-24 19:22:03 +02:00
|
|
|
|
2015-07-27 08:26:13 +02:00
|
|
|
for(ItemStack theDrop : drops){
|
|
|
|
//Drops the Items into the World
|
|
|
|
world.spawnEntityInWorld(new EntityItem(world, theCoord.getX() + 0.5, theCoord.getY() + 0.5, theCoord.getZ() + 0.5, theDrop));
|
2015-04-24 19:22:03 +02:00
|
|
|
}
|
2015-07-27 08:26:13 +02:00
|
|
|
|
2015-04-24 19:22:03 +02:00
|
|
|
return;
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxItemUseDuration(ItemStack stack){
|
2015-07-17 07:59:06 +02:00
|
|
|
//Cuz you won't hold it for that long right-clicking anyways
|
|
|
|
return Integer.MAX_VALUE;
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumAction getItemUseAction(ItemStack stack){
|
2015-04-04 05:20:19 +02:00
|
|
|
return EnumAction.bow;
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
|
|
|
|
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return this.isAdvanced ? EnumRarity.epic : EnumRarity.rare;
|
|
|
|
}
|
|
|
|
|
2015-06-18 13:14:57 +02:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean isHeld) {
|
|
|
|
if(KeyUtil.isShiftPressed()){
|
2015-08-01 00:40:29 +02:00
|
|
|
list.add(StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+"."+this.getName()+".desc."+1));
|
|
|
|
list.add(StringUtil.ITALIC + StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".itemLeafBlower.desc.2"));
|
|
|
|
list.add(StringUtil.ITALIC + StringUtil.localize("tooltip."+ModUtil.MOD_ID_LOWER+".itemLeafBlower.desc.3"));
|
2015-06-18 13:14:57 +02:00
|
|
|
}
|
|
|
|
else list.add(ItemUtil.shiftForInfo());
|
|
|
|
}
|
|
|
|
|
2015-03-29 15:29:05 +02:00
|
|
|
@Override
|
|
|
|
public IIcon getIcon(ItemStack stack, int pass){
|
|
|
|
return this.itemIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconReg){
|
|
|
|
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER + ":" + this.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return this.isAdvanced ? "itemLeafBlowerAdvanced" : "itemLeafBlower";
|
|
|
|
}
|
|
|
|
}
|