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,9 +85,10 @@ 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(Util.RANDOM.nextFloat() <= chance){
|
||||
if(WorldUtil.addToInventory(this, drops, false, true)){
|
||||
if(!ConfigValues.lessBlockBreakingEffects){
|
||||
this.worldObj.playAuxSFX(2001, coordsBlock, Block.getStateId(stateToBreak));
|
||||
|
@ -95,6 +98,7 @@ public class TileEntityBreaker extends TileEntityInventoryBase implements IRedst
|
|||
this.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(this.isPlacer){
|
||||
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
||||
this.setInventorySlotContents(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.worldObj, this.pos, this.slots[theSlot]));
|
||||
|
|
|
@ -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,9 +89,10 @@ 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(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)));
|
||||
|
@ -102,6 +106,7 @@ public class TileEntityDirectionalBreaker extends TileEntityInventoryBase implem
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack stack){
|
||||
|
|
|
@ -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,9 +103,10 @@ 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(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)));
|
||||
|
@ -113,6 +119,7 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IEnergyR
|
|||
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