mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 00:38:35 +01:00
Made harvestdropevents be posted when mining blocks automatically
This commit is contained in:
parent
4b0ef298da
commit
a8365724f8
4 changed files with 50 additions and 33 deletions
|
@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile;
|
|||
|
||||
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
||||
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
|
@ -21,8 +22,9 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityBreaker extends TileEntityInventoryBase implements IRedstoneToggle{
|
||||
|
||||
|
@ -83,16 +85,18 @@ public class TileEntityBreaker extends TileEntityInventoryBase implements IRedst
|
|||
Block blockToBreak = PosUtil.getBlock(coordsBlock, this.worldObj);
|
||||
IBlockState stateToBreak = this.worldObj.getBlockState(coordsBlock);
|
||||
if(!this.isPlacer && blockToBreak != null && !(blockToBreak instanceof BlockAir) && blockToBreak.getBlockHardness(stateToBreak, this.worldObj, coordsBlock) > -1.0F){
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
drops.addAll(blockToBreak.getDrops(this.worldObj, coordsBlock, stateToBreak, 0));
|
||||
List<ItemStack> drops = blockToBreak.getDrops(this.worldObj, coordsBlock, stateToBreak, 0);
|
||||
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.worldObj, coordsBlock, this.worldObj.getBlockState(coordsBlock), 0, 1, false, null);
|
||||
|
||||
if(WorldUtil.addToInventory(this, drops, false, true)){
|
||||
if(!ConfigValues.lessBlockBreakingEffects){
|
||||
this.worldObj.playAuxSFX(2001, coordsBlock, Block.getStateId(stateToBreak));
|
||||
if(Util.RANDOM.nextFloat() <= chance){
|
||||
if(WorldUtil.addToInventory(this, drops, false, true)){
|
||||
if(!ConfigValues.lessBlockBreakingEffects){
|
||||
this.worldObj.playAuxSFX(2001, coordsBlock, Block.getStateId(stateToBreak));
|
||||
}
|
||||
WorldUtil.breakBlockAtSide(sideToManipulate, this.worldObj, this.pos);
|
||||
WorldUtil.addToInventory(this, drops, true, true);
|
||||
this.markDirty();
|
||||
}
|
||||
WorldUtil.breakBlockAtSide(sideToManipulate, this.worldObj, this.pos);
|
||||
WorldUtil.addToInventory(this, drops, true, true);
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
else if(this.isPlacer){
|
||||
|
|
|
@ -14,6 +14,7 @@ import cofh.api.energy.EnergyStorage;
|
|||
import cofh.api.energy.IEnergyReceiver;
|
||||
import de.ellpeck.actuallyadditions.mod.config.ConfigValues;
|
||||
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockAir;
|
||||
|
@ -21,10 +22,12 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implements IEnergyReceiver, IEnergySaver, IRedstoneToggle{
|
||||
|
||||
|
@ -86,17 +89,19 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
|
|||
if(coordsBlock != null){
|
||||
Block blockToBreak = PosUtil.getBlock(coordsBlock, this.worldObj);
|
||||
if(blockToBreak != null && !(blockToBreak instanceof BlockAir) && blockToBreak.getBlockHardness(this.worldObj.getBlockState(coordsBlock), this.worldObj, this.pos) > -1.0F){
|
||||
ArrayList<ItemStack> drops = new ArrayList();
|
||||
drops.addAll(blockToBreak.getDrops(this.worldObj, coordsBlock, this.worldObj.getBlockState(coordsBlock), 0));
|
||||
List<ItemStack> drops = blockToBreak.getDrops(this.worldObj, coordsBlock, this.worldObj.getBlockState(coordsBlock), 0);
|
||||
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.worldObj, coordsBlock, this.worldObj.getBlockState(coordsBlock), 0, 1, false, null);
|
||||
|
||||
if(WorldUtil.addToInventory(this, drops, false, true)){
|
||||
if(!ConfigValues.lessBlockBreakingEffects){
|
||||
this.worldObj.playAuxSFX(2001, coordsBlock, Block.getStateId(this.worldObj.getBlockState(coordsBlock)));
|
||||
if(Util.RANDOM.nextFloat() <= chance){
|
||||
if(WorldUtil.addToInventory(this, drops, false, true)){
|
||||
if(!ConfigValues.lessBlockBreakingEffects){
|
||||
this.worldObj.playAuxSFX(2001, coordsBlock, Block.getStateId(this.worldObj.getBlockState(coordsBlock)));
|
||||
}
|
||||
WorldUtil.breakBlockAtSide(sideToManipulate, this.worldObj, this.getPos(), i);
|
||||
WorldUtil.addToInventory(this, drops, true, true);
|
||||
this.storage.extractEnergy(ENERGY_USE, false);
|
||||
this.markDirty();
|
||||
}
|
||||
WorldUtil.breakBlockAtSide(sideToManipulate, this.worldObj, this.getPos(), i);
|
||||
WorldUtil.addToInventory(this, drops, true, true);
|
||||
this.storage.extractEnergy(ENERGY_USE, false);
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
|
|||
import de.ellpeck.actuallyadditions.mod.network.PacketParticle;
|
||||
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
||||
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
|
||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
|
@ -25,6 +26,9 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
|
@ -32,6 +36,7 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
|||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyReceiver, IButtonReactor, IEnergySaver, IEnergyDisplay{
|
||||
|
||||
|
@ -98,20 +103,22 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyR
|
|||
int meta = PosUtil.getMetadata(pos, this.worldObj);
|
||||
if(block != null && !block.isAir(this.worldObj.getBlockState(pos), this.worldObj, pos)){
|
||||
if(block.getHarvestLevel(this.worldObj.getBlockState(pos)) <= 3F && block.getBlockHardness(this.worldObj.getBlockState(pos), this.worldObj, pos) >= 0F && !(block instanceof BlockLiquid) && !(block instanceof IFluidBlock) && this.isMinable(block, meta)){
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
|
||||
drops.addAll(block.getDrops(this.worldObj, pos, this.worldObj.getBlockState(pos), 0));
|
||||
List<ItemStack> drops = block.getDrops(this.worldObj, pos, this.worldObj.getBlockState(pos), 0);
|
||||
float chance = ForgeEventFactory.fireBlockHarvesting(drops, this.worldObj, pos, this.worldObj.getBlockState(pos), 0, 1, false, null);
|
||||
|
||||
if(WorldUtil.addToInventory(this, drops, false, true)){
|
||||
if(!ConfigValues.lessBlockBreakingEffects){
|
||||
this.worldObj.playAuxSFX(2001, pos, Block.getStateId(this.worldObj.getBlockState(pos)));
|
||||
if(Util.RANDOM.nextFloat() <= chance){
|
||||
if(WorldUtil.addToInventory(this, drops, false, true)){
|
||||
if(!ConfigValues.lessBlockBreakingEffects){
|
||||
this.worldObj.playAuxSFX(2001, pos, Block.getStateId(this.worldObj.getBlockState(pos)));
|
||||
}
|
||||
this.worldObj.setBlockToAir(pos);
|
||||
|
||||
WorldUtil.addToInventory(this, drops, true, true);
|
||||
this.markDirty();
|
||||
|
||||
this.storage.extractEnergy(actualUse, false);
|
||||
this.shootParticles(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
this.worldObj.setBlockToAir(pos);
|
||||
|
||||
WorldUtil.addToInventory(this, drops, true, true);
|
||||
this.markDirty();
|
||||
|
||||
this.storage.extractEnergy(actualUse, false);
|
||||
this.shootParticles(pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import net.minecraftforge.common.IPlantable;
|
|||
import net.minecraftforge.fluids.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WorldUtil{
|
||||
|
||||
|
@ -249,11 +250,11 @@ public class WorldUtil{
|
|||
return blocks;
|
||||
}
|
||||
|
||||
public static boolean addToInventory(IInventory inventory, ArrayList<ItemStack> stacks, boolean actuallyDo, boolean shouldAlwaysWork){
|
||||
public static boolean addToInventory(IInventory inventory, List<ItemStack> stacks, boolean actuallyDo, boolean shouldAlwaysWork){
|
||||
return addToInventory(inventory, stacks, EnumFacing.UP, actuallyDo, shouldAlwaysWork);
|
||||
}
|
||||
|
||||
public static boolean addToInventory(IInventory inventory, ArrayList<ItemStack> stacks, EnumFacing side, boolean actuallyDo, boolean shouldAlwaysWork){
|
||||
public static boolean addToInventory(IInventory inventory, List<ItemStack> stacks, EnumFacing side, boolean actuallyDo, boolean shouldAlwaysWork){
|
||||
return addToInventory(inventory, 0, inventory.getSizeInventory(), stacks, side, actuallyDo, shouldAlwaysWork);
|
||||
}
|
||||
|
||||
|
@ -266,7 +267,7 @@ public class WorldUtil{
|
|||
* @param actuallyDo Do it or just test if it works?
|
||||
* @return Does it work?
|
||||
*/
|
||||
public static boolean addToInventory(IInventory inventory, int start, int end, ArrayList<ItemStack> stacks, EnumFacing side, boolean actuallyDo, boolean shouldAlwaysWork){
|
||||
public static boolean addToInventory(IInventory inventory, int start, int end, List<ItemStack> stacks, EnumFacing side, boolean actuallyDo, boolean shouldAlwaysWork){
|
||||
//Copy the slots if just testing to later load them again
|
||||
ItemStack[] backupSlots = null;
|
||||
if(!actuallyDo){
|
||||
|
|
Loading…
Reference in a new issue