2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("ItemLeafBlower.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
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;
|
2015-12-03 20:15:07 +01:00
|
|
|
import ellpeck.actuallyadditions.items.base.ItemBase;
|
2015-08-28 22:18:46 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
|
|
|
import ellpeck.actuallyadditions.util.WorldPos;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockBush;
|
|
|
|
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.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-09-29 16:16:53 +02:00
|
|
|
import java.util.Collections;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public class ItemLeafBlower extends ItemBase{
|
2015-03-29 15:29:05 +02:00
|
|
|
|
|
|
|
private final boolean isAdvanced;
|
|
|
|
|
2015-12-03 20:15:07 +01:00
|
|
|
public ItemLeafBlower(boolean isAdvanced, String name){
|
|
|
|
super(name);
|
2015-03-29 15:29:05 +02:00
|
|
|
this.isAdvanced = isAdvanced;
|
|
|
|
this.setMaxStackSize(1);
|
|
|
|
}
|
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){
|
|
|
|
player.setItemInUse(stack, this.getMaxItemUseDuration(stack));
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumAction getItemUseAction(ItemStack stack){
|
|
|
|
return EnumAction.bow;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxItemUseDuration(ItemStack stack){
|
|
|
|
//Cuz you won't hold it for that long right-clicking anyways
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
|
|
|
return this.isAdvanced ? EnumRarity.epic : EnumRarity.rare;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public void registerIcons(IIconRegister iconReg){
|
2015-12-03 20:15:07 +01:00
|
|
|
this.itemIcon = iconReg.registerIcon(ModUtil.MOD_ID_LOWER+":"+this.getBaseName());
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2015-03-29 15:29:05 +02:00
|
|
|
@Override
|
|
|
|
public void onUsingTick(ItemStack stack, EntityPlayer player, int time){
|
|
|
|
if(!player.worldObj.isRemote){
|
2015-10-02 16:48:01 +02:00
|
|
|
if(time <= getMaxItemUseDuration(stack) && (this.isAdvanced || time%3 == 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-10-02 16:48:01 +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
|
2015-10-02 16:48:01 +02:00
|
|
|
*
|
2015-07-17 07:59:06 +02:00
|
|
|
* @param world The World
|
2015-10-02 16:48:01 +02:00
|
|
|
* @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-07-17 07:59:06 +02:00
|
|
|
*/
|
2015-03-29 15:29:05 +02:00
|
|
|
public void breakStuff(World world, int x, int y, int z){
|
2015-09-29 16:16:53 +02:00
|
|
|
ArrayList<WorldPos> breakPositions = new ArrayList<WorldPos>();
|
|
|
|
|
2015-11-28 19:02:01 +01:00
|
|
|
int rangeSides = 5;
|
|
|
|
int rangeUp = 1;
|
|
|
|
for(int reachX = -rangeSides; reachX < rangeSides+1; reachX++){
|
|
|
|
for(int reachZ = -rangeSides; reachZ < rangeSides+1; reachZ++){
|
|
|
|
for(int reachY = (this.isAdvanced ? -rangeSides : -rangeUp); reachY < (this.isAdvanced ? rangeSides : rangeUp)+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);
|
2015-08-31 01:53:23 +02:00
|
|
|
if(block != null && (block instanceof BlockBush || (this.isAdvanced && block.isLeaves(world, x+reachX, y+reachY, z+reachZ)))){
|
2015-09-29 16:16:53 +02:00
|
|
|
breakPositions.add(new WorldPos(world, x+reachX, y+reachY, z+reachZ));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-24 19:22:03 +02:00
|
|
|
|
2015-09-29 16:16:53 +02:00
|
|
|
if(!breakPositions.isEmpty()){
|
|
|
|
Collections.shuffle(breakPositions);
|
2015-04-24 19:22:03 +02:00
|
|
|
|
2015-09-29 16:16:53 +02:00
|
|
|
WorldPos theCoord = breakPositions.get(0);
|
|
|
|
Block theBlock = world.getBlock(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
2015-07-27 08:26:13 +02:00
|
|
|
|
2015-09-29 16:16:53 +02:00
|
|
|
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
|
|
|
int meta = world.getBlockMetadata(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
|
|
|
//Gets all of the Drops the Block should have
|
|
|
|
drops.addAll(theBlock.getDrops(world, theCoord.getX(), theCoord.getY(), theCoord.getZ(), meta, 0));
|
|
|
|
|
|
|
|
//Deletes the Block
|
|
|
|
world.setBlockToAir(theCoord.getX(), theCoord.getY(), theCoord.getZ());
|
|
|
|
//Plays the Breaking Sound
|
|
|
|
world.playAuxSFX(2001, theCoord.getX(), theCoord.getY(), theCoord.getZ(), Block.getIdFromBlock(theBlock)+(meta << 12));
|
|
|
|
|
|
|
|
for(ItemStack theDrop : drops){
|
|
|
|
//Drops the Items into the World
|
2015-10-02 16:48:01 +02:00
|
|
|
world.spawnEntityInWorld(new EntityItem(world, theCoord.getX()+0.5, theCoord.getY()+0.5, theCoord.getZ()+0.5, theDrop));
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-10-28 14:46:04 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-03-29 15:29:05 +02:00
|
|
|
public IIcon getIcon(ItemStack stack, int pass){
|
|
|
|
return this.itemIcon;
|
|
|
|
}
|
|
|
|
}
|