mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Closes #1044
This commit is contained in:
parent
8bb71ad796
commit
8cd9c6a095
1 changed files with 82 additions and 85 deletions
|
@ -10,12 +10,12 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
|
@ -63,8 +63,7 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
|
||||||
if (this.currentTime <= 0) {
|
if (this.currentTime <= 0) {
|
||||||
this.doWork();
|
this.doWork();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
this.currentTime = 15;
|
this.currentTime = 15;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,30 +76,28 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doWork() {
|
private void doWork() {
|
||||||
IBlockState state = this.world.getBlockState(this.pos);
|
EnumFacing side = WorldUtil.getDirectionByPistonRotation(world.getBlockState(pos));
|
||||||
EnumFacing sideToManipulate = WorldUtil.getDirectionByPistonRotation(state);
|
BlockPos breakCoords = pos.offset(side);
|
||||||
|
IBlockState stateToBreak = world.getBlockState(breakCoords);
|
||||||
BlockPos coordsBlock = this.pos.offset(sideToManipulate);
|
|
||||||
IBlockState stateToBreak = this.world.getBlockState(coordsBlock);
|
|
||||||
Block blockToBreak = stateToBreak.getBlock();
|
Block blockToBreak = stateToBreak.getBlock();
|
||||||
if(!this.isPlacer && blockToBreak != null && !this.world.isAirBlock(coordsBlock) && !(blockToBreak instanceof BlockLiquid) && !(blockToBreak instanceof IFluidBlock) && stateToBreak.getBlockHardness(this.world, coordsBlock) >= 0.0F){
|
|
||||||
NonNullList<ItemStack> drops = NonNullList.create();
|
|
||||||
blockToBreak.getDrops(drops, world, coordsBlock, stateToBreak, 0);
|
|
||||||
float chance = WorldUtil.fireFakeHarvestEventsForDropChance(drops, this.world, coordsBlock);
|
|
||||||
|
|
||||||
if(chance > 0 && this.world.rand.nextFloat() <= chance){
|
if (!this.isPlacer && blockToBreak != Blocks.AIR && !(blockToBreak instanceof BlockLiquid) && !(blockToBreak instanceof IFluidBlock) && stateToBreak.getBlockHardness(this.world, breakCoords) >= 0.0F) {
|
||||||
if(WorldUtil.addToInventory(this.slots, drops, false)){
|
NonNullList<ItemStack> drops = NonNullList.create();
|
||||||
this.world.playEvent(2001, coordsBlock, Block.getStateId(stateToBreak));
|
blockToBreak.getDrops(drops, world, breakCoords, stateToBreak, 0);
|
||||||
this.world.setBlockToAir(coordsBlock);
|
float chance = WorldUtil.fireFakeHarvestEventsForDropChance(drops, world, breakCoords);
|
||||||
WorldUtil.addToInventory(this.slots, drops, true);
|
|
||||||
|
if (chance > 0 && world.rand.nextFloat() <= chance) {
|
||||||
|
if (WorldUtil.addToInventory(slots, drops, false)) {
|
||||||
|
this.world.playEvent(2001, breakCoords, Block.getStateId(stateToBreak));
|
||||||
|
this.world.setBlockToAir(breakCoords);
|
||||||
|
WorldUtil.addToInventory(slots, drops, true);
|
||||||
this.markDirty();
|
this.markDirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (this.isPlacer) {
|
||||||
else if(this.isPlacer){
|
int theSlot = WorldUtil.findFirstFilledSlot(slots);
|
||||||
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
|
this.slots.setStackInSlot(theSlot, WorldUtil.useItemAtSide(side, world, pos, slots.getStackInSlot(theSlot)));
|
||||||
this.slots.setStackInSlot(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.world, this.pos, this.slots.getStackInSlot(theSlot)));
|
if (!StackUtil.isValid(slots.getStackInSlot(theSlot))) {
|
||||||
if(!StackUtil.isValid(this.slots.getStackInSlot(theSlot))){
|
|
||||||
this.slots.setStackInSlot(theSlot, StackUtil.getEmpty());
|
this.slots.setStackInSlot(theSlot, StackUtil.getEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue