This commit is contained in:
Shadows_of_Fire 2018-03-19 12:05:28 -04:00
parent 8bb71ad796
commit 8cd9c6a095

View file

@ -10,12 +10,12 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
@ -23,48 +23,47 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fluids.IFluidBlock;
public class TileEntityBreaker extends TileEntityInventoryBase{
public class TileEntityBreaker extends TileEntityInventoryBase {
public boolean isPlacer;
private int currentTime;
public TileEntityBreaker(int slots, String name){
public TileEntityBreaker(int slots, String name) {
super(slots, name);
}
public TileEntityBreaker(){
public TileEntityBreaker() {
super(9, "breaker");
this.isPlacer = false;
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
public void writeSyncableNBT(NBTTagCompound compound, NBTType type) {
super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
if (type != NBTType.SAVE_BLOCK) {
compound.setInteger("CurrentTime", this.currentTime);
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
public void readSyncableNBT(NBTTagCompound compound, NBTType type) {
super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
if (type != NBTType.SAVE_BLOCK) {
this.currentTime = compound.getInteger("CurrentTime");
}
}
@Override
public void updateEntity(){
public void updateEntity() {
super.updateEntity();
if(!this.world.isRemote){
if(!this.isRedstonePowered && !this.isPulseMode){
if(this.currentTime > 0){
if (!this.world.isRemote) {
if (!this.isRedstonePowered && !this.isPulseMode) {
if (this.currentTime > 0) {
this.currentTime--;
if(this.currentTime <= 0){
if (this.currentTime <= 0) {
this.doWork();
}
}
else{
} else {
this.currentTime = 15;
}
}
@ -72,52 +71,50 @@ public class TileEntityBreaker extends TileEntityInventoryBase{
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
public boolean isItemValidForSlot(int i, ItemStack stack) {
return this.isPlacer;
}
private void doWork(){
IBlockState state = this.world.getBlockState(this.pos);
EnumFacing sideToManipulate = WorldUtil.getDirectionByPistonRotation(state);
BlockPos coordsBlock = this.pos.offset(sideToManipulate);
IBlockState stateToBreak = this.world.getBlockState(coordsBlock);
private void doWork() {
EnumFacing side = WorldUtil.getDirectionByPistonRotation(world.getBlockState(pos));
BlockPos breakCoords = pos.offset(side);
IBlockState stateToBreak = world.getBlockState(breakCoords);
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(WorldUtil.addToInventory(this.slots, drops, false)){
this.world.playEvent(2001, coordsBlock, Block.getStateId(stateToBreak));
this.world.setBlockToAir(coordsBlock);
WorldUtil.addToInventory(this.slots, drops, true);
if (!this.isPlacer && blockToBreak != Blocks.AIR && !(blockToBreak instanceof BlockLiquid) && !(blockToBreak instanceof IFluidBlock) && stateToBreak.getBlockHardness(this.world, breakCoords) >= 0.0F) {
NonNullList<ItemStack> drops = NonNullList.create();
blockToBreak.getDrops(drops, world, breakCoords, stateToBreak, 0);
float chance = WorldUtil.fireFakeHarvestEventsForDropChance(drops, world, breakCoords);
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();
}
}
}
else if(this.isPlacer){
int theSlot = WorldUtil.findFirstFilledSlot(this.slots);
this.slots.setStackInSlot(theSlot, WorldUtil.useItemAtSide(sideToManipulate, this.world, this.pos, this.slots.getStackInSlot(theSlot)));
if(!StackUtil.isValid(this.slots.getStackInSlot(theSlot))){
} else if (this.isPlacer) {
int theSlot = WorldUtil.findFirstFilledSlot(slots);
this.slots.setStackInSlot(theSlot, WorldUtil.useItemAtSide(side, world, pos, slots.getStackInSlot(theSlot)));
if (!StackUtil.isValid(slots.getStackInSlot(theSlot))) {
this.slots.setStackInSlot(theSlot, StackUtil.getEmpty());
}
}
}
@Override
public boolean canExtractItem(int slot, ItemStack stack){
public boolean canExtractItem(int slot, ItemStack stack) {
return true;
}
@Override
public boolean isRedstoneToggle(){
public boolean isRedstoneToggle() {
return true;
}
@Override
public void activateOnPulse(){
public void activateOnPulse() {
this.doWork();
}