Miner Functionality

This commit is contained in:
Ellpeck 2015-12-09 16:54:25 +01:00
parent 2cac51952b
commit 99d0a413e9
2 changed files with 57 additions and 6 deletions

View file

@ -18,9 +18,11 @@ import ellpeck.actuallyadditions.util.ModUtil;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
@ -73,4 +75,17 @@ public class BlockMiner extends BlockContainerBase{
this.dropInventory(world, x, y, z);
super.breakBlock(world, x, y, z, block, par6);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
if(!world.isRemote){
TileEntity tile = world.getTileEntity(x, y, z);
if(tile != null && tile instanceof TileEntityMiner){
player.addChatComponentMessage(new ChatComponentText(((TileEntityMiner)tile).storage.getEnergyStored()+"/"+((TileEntityMiner)tile).storage.getMaxEnergyStored()+" RF"));
player.addChatComponentMessage(new ChatComponentText("Mining at Y "+((TileEntityMiner)tile).layerAt+"."));
}
return true;
}
return true;
}
}

View file

@ -12,52 +12,88 @@ package ellpeck.actuallyadditions.tile;
import cofh.api.energy.EnergyStorage;
import cofh.api.energy.IEnergyReceiver;
import ellpeck.actuallyadditions.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
public class TileEntityMiner extends TileEntityBase implements IEnergyReceiver{
public EnergyStorage storage = new EnergyStorage(800000);
public EnergyStorage storage = new EnergyStorage(1000000);
public static final int ENERGY_USE_PER_BLOCK = 300;
public int layerAt;
@Override
public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote){
this.mine(2);
if(this.ticksElapsed%350 == 0){
if(this.layerAt <= 0){
this.layerAt = this.yCoord-1;
}
if(this.mine(3)){
this.layerAt--;
}
}
}
}
private void mine(int range){
private boolean mine(int range){
TileEntity tileAbove = worldObj.getTileEntity(xCoord, yCoord+1, zCoord);
boolean mined = false;
for(int anX = -range; anX <= range; anX++){
for(int aZ = -range; aZ <= range; aZ++){
for(int y = this.yCoord-1; y > 0; y--){
if(this.storage.getEnergyStored() >= ENERGY_USE_PER_BLOCK){
int x = this.xCoord+anX;
int z = this.zCoord+aZ;
int y = this.layerAt;
Block block = this.worldObj.getBlock(x, y, z);
int meta = this.worldObj.getBlockMetadata(x, y, z);
if(block != null && !block.isAir(this.worldObj, x, y, z)){
if(block.getHarvestLevel(meta) <= 3){
if(block.getHarvestLevel(meta) <= 3F && block.getHarvestLevel(meta) >= 0F){
ArrayList<ItemStack> drops = new ArrayList<ItemStack>();
drops.addAll(block.getDrops(worldObj, x, y, z, meta, 0));
return;
if(tileAbove instanceof IInventory){
if(WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, false)){
worldObj.playAuxSFX(2001, x, y, z, Block.getIdFromBlock(block)+(meta << 12));
worldObj.setBlockToAir(x, y, z);
WorldUtil.addToInventory((IInventory)tileAbove, drops, ForgeDirection.DOWN, true);
tileAbove.markDirty();
this.storage.extractEnergy(ENERGY_USE_PER_BLOCK, false);
mined = true;
}
}
}
}
}
}
}
return mined;
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
super.writeSyncableNBT(compound, sync);
this.storage.writeToNBT(compound);
compound.setInteger("Layer", this.layerAt);
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
super.readSyncableNBT(compound, sync);
this.storage.readFromNBT(compound);
this.layerAt = compound.getInteger("Layer");
}
@Override