2015-08-29 14:33:25 +02:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("ItemLeafBlower.java") is part of the Actually Additions mod for Minecraft.
|
2015-08-29 14:33:25 +02:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-08-29 14:33:25 +02:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.items;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2016-06-06 21:27:09 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem;
|
2016-01-05 04:47:35 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockBush;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2016-05-01 22:26:26 +02:00
|
|
|
import net.minecraft.init.SoundEvents;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.EnumRarity;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-06-06 21:27:09 +02:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
import net.minecraft.util.EnumActionResult;
|
|
|
|
import net.minecraft.util.EnumHand;
|
2016-05-01 22:26:26 +02:00
|
|
|
import net.minecraft.util.SoundCategory;
|
2016-03-18 23:47:22 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.MathHelper;
|
2015-03-29 15:29:05 +02:00
|
|
|
import net.minecraft.world.World;
|
2016-12-06 13:40:51 +01:00
|
|
|
import net.minecraftforge.common.IShearable;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2015-09-29 16:16:53 +02:00
|
|
|
import java.util.Collections;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
2016-06-06 21:27:09 +02:00
|
|
|
public class ItemLeafBlower extends ItemBase implements IDisplayStandItem{
|
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);
|
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
2016-11-19 21:11:17 +01:00
|
|
|
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand){
|
2016-03-18 23:47:22 +01:00
|
|
|
player.setActiveHand(hand);
|
2016-11-19 21:11:17 +01:00
|
|
|
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public EnumAction getItemUseAction(ItemStack stack){
|
2016-01-07 21:41:28 +01:00
|
|
|
return EnumAction.BOW;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxItemUseDuration(ItemStack stack){
|
|
|
|
//Cuz you won't hold it for that long right-clicking anyways
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2015-10-03 10:19:40 +02:00
|
|
|
@Override
|
|
|
|
public EnumRarity getRarity(ItemStack stack){
|
2016-01-07 21:41:28 +01:00
|
|
|
return this.isAdvanced ? EnumRarity.EPIC : EnumRarity.RARE;
|
2015-10-03 10:19:40 +02:00
|
|
|
}
|
|
|
|
|
2015-03-29 15:29:05 +02:00
|
|
|
@Override
|
2016-03-18 23:47:22 +01:00
|
|
|
public void onUsingTick(ItemStack stack, EntityLivingBase player, int time){
|
2016-11-26 21:32:27 +01:00
|
|
|
this.doUpdate(player.world, MathHelper.floor(player.posX), MathHelper.floor(player.posY), MathHelper.floor(player.posZ), time, stack);
|
2016-06-06 21:27:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean doUpdate(World world, int x, int y, int z, int time, ItemStack stack){
|
|
|
|
if(!world.isRemote){
|
2016-05-02 17:46:53 +02:00
|
|
|
if(time <= this.getMaxItemUseDuration(stack) && (this.isAdvanced || time%3 == 0)){
|
2015-07-17 07:59:06 +02:00
|
|
|
//Breaks the Blocks
|
2016-06-06 21:27:09 +02:00
|
|
|
boolean broke = this.breakStuff(world, x, y, z);
|
2015-07-17 07:59:06 +02:00
|
|
|
//Plays a Minecart sounds (It really sounds like a Leaf Blower!)
|
2016-11-07 19:58:34 +01:00
|
|
|
world.playSound(null, x, y, z, SoundEvents.ENTITY_MINECART_RIDING, SoundCategory.PLAYERS, 0.3F, 0.001F);
|
2016-06-06 21:27:09 +02:00
|
|
|
return broke;
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-06 21:27:09 +02:00
|
|
|
return false;
|
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
|
|
|
*/
|
2016-06-06 21:27:09 +02:00
|
|
|
public boolean breakStuff(World world, int x, int y, int z){
|
2016-01-08 13:31:58 +01:00
|
|
|
ArrayList<BlockPos> breakPositions = new ArrayList<BlockPos>();
|
2015-09-29 16:16:53 +02:00
|
|
|
|
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
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos pos = new BlockPos(x+reachX, y+reachY, z+reachZ);
|
2016-07-04 20:15:41 +02:00
|
|
|
Block block = world.getBlockState(pos).getBlock();
|
2016-12-06 13:40:51 +01:00
|
|
|
|
|
|
|
if(block != null && ((block instanceof BlockBush || block instanceof IShearable) && (this.isAdvanced || !block.isLeaves(world.getBlockState(pos), world, pos)))){
|
2016-01-07 21:41:28 +01:00
|
|
|
breakPositions.add(pos);
|
2015-09-29 16:16:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2016-01-08 13:31:58 +01:00
|
|
|
BlockPos theCoord = breakPositions.get(0);
|
2016-07-04 20:15:41 +02:00
|
|
|
Block theBlock = world.getBlockState(theCoord).getBlock();
|
2015-07-27 08:26:13 +02:00
|
|
|
|
2015-09-29 16:16:53 +02:00
|
|
|
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
|
|
|
//Gets all of the Drops the Block should have
|
2016-01-08 13:31:58 +01:00
|
|
|
drops.addAll(theBlock.getDrops(world, theCoord, world.getBlockState(theCoord), 0));
|
2015-09-29 16:16:53 +02:00
|
|
|
|
|
|
|
//Plays the Breaking Sound
|
2016-11-07 19:58:34 +01:00
|
|
|
world.playEvent(2001, theCoord, Block.getStateId(world.getBlockState(theCoord)));
|
2015-09-29 16:16:53 +02:00
|
|
|
|
2016-01-23 23:29:19 +01:00
|
|
|
//Deletes the Block
|
|
|
|
world.setBlockToAir(theCoord);
|
|
|
|
|
2015-09-29 16:16:53 +02:00
|
|
|
for(ItemStack theDrop : drops){
|
|
|
|
//Drops the Items into the World
|
2016-11-26 21:32:27 +01:00
|
|
|
world.spawnEntity(new EntityItem(world, theCoord.getX()+0.5, theCoord.getY()+0.5, theCoord.getZ()+0.5, theDrop));
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
2016-06-06 21:27:09 +02:00
|
|
|
return true;
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
2016-06-06 21:27:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean update(ItemStack stack, TileEntity tile, int elapsedTicks){
|
|
|
|
return this.doUpdate(tile.getWorld(), tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), elapsedTicks, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getUsePerTick(ItemStack stack, TileEntity tile, int elapsedTicks){
|
|
|
|
return 60;
|
2015-03-29 15:29:05 +02:00
|
|
|
}
|
|
|
|
}
|