mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58:34 +01:00
Made the miner a little less resource heavy
This commit is contained in:
parent
935e928f22
commit
f937673483
3 changed files with 69 additions and 41 deletions
|
@ -75,7 +75,8 @@ public class BlockMiner extends BlockContainerBase implements IHudDisplay{
|
||||||
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
|
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
|
||||||
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
|
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
|
||||||
if(tile instanceof TileEntityMiner){
|
if(tile instanceof TileEntityMiner){
|
||||||
String info = ((TileEntityMiner)tile).layerAt <= 0 ? "Done Mining!" : "Mining at Y = "+((TileEntityMiner)tile).layerAt+".";
|
TileEntityMiner miner = (TileEntityMiner)tile;
|
||||||
|
String info = miner.checkY == 0 ? "Done Mining!" : (miner.checkY == -1 ? "Calculating positions..." : "Mining at "+(miner.getPos().getX()+miner.checkX)+", "+miner.checkY+", "+(miner.getPos().getZ()+miner.checkZ)+".");
|
||||||
minecraft.fontRendererObj.drawStringWithShadow(info, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2-20, StringUtil.DECIMAL_COLOR_WHITE);
|
minecraft.fontRendererObj.drawStringWithShadow(info, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2-20, StringUtil.DECIMAL_COLOR_WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if(type != NBTType.SAVE_BLOCK){
|
||||||
compound.setInteger("WaitTime", this.waitTime);
|
compound.setInteger("WaitTime", this.waitTime);
|
||||||
|
}
|
||||||
|
if(type == NBTType.SAVE_TILE){
|
||||||
compound.setInteger("CheckX", this.checkX);
|
compound.setInteger("CheckX", this.checkX);
|
||||||
compound.setInteger("CheckY", this.checkY);
|
compound.setInteger("CheckY", this.checkY);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +57,8 @@ public class TileEntityFarmer extends TileEntityInventoryBase implements IFarmer
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if(type != NBTType.SAVE_BLOCK){
|
||||||
this.waitTime = compound.getInteger("WaitTime");
|
this.waitTime = compound.getInteger("WaitTime");
|
||||||
|
}
|
||||||
|
if(type == NBTType.SAVE_TILE){
|
||||||
this.checkX = compound.getInteger("CheckX");
|
this.checkX = compound.getInteger("CheckX");
|
||||||
this.checkY = compound.getInteger("CheckY");
|
this.checkY = compound.getInteger("CheckY");
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,17 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
|
||||||
public static final int ENERGY_USE_PER_BLOCK = 650;
|
public static final int ENERGY_USE_PER_BLOCK = 650;
|
||||||
public static final int DEFAULT_RANGE = 2;
|
public static final int DEFAULT_RANGE = 2;
|
||||||
public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 2000, 0);
|
public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 2000, 0);
|
||||||
public int layerAt = -1;
|
|
||||||
public boolean onlyMineOres;
|
public boolean onlyMineOres;
|
||||||
private int oldLayerAt;
|
|
||||||
private int oldEnergy;
|
private int oldEnergy;
|
||||||
|
|
||||||
|
public int checkX;
|
||||||
|
public int checkY = -1;
|
||||||
|
public int checkZ;
|
||||||
|
private int oldCheckX;
|
||||||
|
private int oldCheckY;
|
||||||
|
private int oldCheckZ;
|
||||||
|
|
||||||
public TileEntityMiner(){
|
public TileEntityMiner(){
|
||||||
super(9, "miner");
|
super(9, "miner");
|
||||||
}
|
}
|
||||||
|
@ -50,7 +56,9 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
|
||||||
super.writeSyncableNBT(compound, type);
|
super.writeSyncableNBT(compound, type);
|
||||||
this.storage.writeToNBT(compound);
|
this.storage.writeToNBT(compound);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if(type != NBTType.SAVE_BLOCK){
|
||||||
compound.setInteger("Layer", this.layerAt);
|
compound.setInteger("CheckX", this.checkX);
|
||||||
|
compound.setInteger("CheckY", this.checkY);
|
||||||
|
compound.setInteger("CheckZ", this.checkZ);
|
||||||
}
|
}
|
||||||
if(type != NBTType.SAVE_BLOCK || this.onlyMineOres){
|
if(type != NBTType.SAVE_BLOCK || this.onlyMineOres){
|
||||||
compound.setBoolean("OnlyOres", this.onlyMineOres);
|
compound.setBoolean("OnlyOres", this.onlyMineOres);
|
||||||
|
@ -62,7 +70,9 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
|
||||||
super.readSyncableNBT(compound, type);
|
super.readSyncableNBT(compound, type);
|
||||||
this.storage.readFromNBT(compound);
|
this.storage.readFromNBT(compound);
|
||||||
if(type != NBTType.SAVE_BLOCK){
|
if(type != NBTType.SAVE_BLOCK){
|
||||||
this.layerAt = compound.getInteger("Layer");
|
this.checkX = compound.getInteger("CheckX");
|
||||||
|
this.checkY = compound.getInteger("CheckY");
|
||||||
|
this.checkZ = compound.getInteger("CheckZ");
|
||||||
}
|
}
|
||||||
this.onlyMineOres = compound.getBoolean("OnlyOres");
|
this.onlyMineOres = compound.getBoolean("OnlyOres");
|
||||||
}
|
}
|
||||||
|
@ -71,32 +81,45 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
|
||||||
public void updateEntity(){
|
public void updateEntity(){
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
if(!this.world.isRemote){
|
if(!this.world.isRemote){
|
||||||
if(this.layerAt == -1){
|
|
||||||
this.layerAt = this.getPos().getY()-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!this.isRedstonePowered && this.ticksElapsed%5 == 0){
|
if(!this.isRedstonePowered && this.ticksElapsed%5 == 0){
|
||||||
|
if(this.checkY != 0){
|
||||||
|
int range = TileEntityPhantomface.upgradeRange(DEFAULT_RANGE, this.world, this.pos);
|
||||||
|
if(this.checkY < 0){
|
||||||
|
this.checkY = this.pos.getY()-1;
|
||||||
|
this.checkX = -range;
|
||||||
|
this.checkZ = -range;
|
||||||
|
}
|
||||||
|
|
||||||
if(this.layerAt > 0){
|
if(this.checkY > 0){
|
||||||
if(this.mine(TileEntityPhantomface.upgradeRange(DEFAULT_RANGE, this.world, this.pos))){
|
if(this.mine()){
|
||||||
this.layerAt--;
|
this.checkX++;
|
||||||
|
if(this.checkX > range){
|
||||||
|
this.checkX = -range;
|
||||||
|
this.checkZ++;
|
||||||
|
if(this.checkZ > range){
|
||||||
|
this.checkZ = -range;
|
||||||
|
this.checkY--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if((this.oldEnergy != this.storage.getEnergyStored() || this.oldLayerAt != this.layerAt) && this.sendUpdateWithInterval()){
|
if((this.oldEnergy != this.storage.getEnergyStored() || this.oldCheckX != this.checkX || this.oldCheckY != this.checkY || this.oldCheckZ != this.checkZ) && this.sendUpdateWithInterval()){
|
||||||
this.oldEnergy = this.storage.getEnergyStored();
|
this.oldEnergy = this.storage.getEnergyStored();
|
||||||
this.oldLayerAt = this.layerAt;
|
this.oldCheckX = this.checkX;
|
||||||
|
this.oldCheckY = this.checkY;
|
||||||
|
this.oldCheckZ = this.checkZ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mine(int range){
|
private boolean mine(){
|
||||||
for(int anX = -range; anX <= range; anX++){
|
|
||||||
for(int aZ = -range; aZ <= range; aZ++){
|
|
||||||
int actualUse = ENERGY_USE_PER_BLOCK*(this.onlyMineOres ? 3 : 1);
|
int actualUse = ENERGY_USE_PER_BLOCK*(this.onlyMineOres ? 3 : 1);
|
||||||
if(this.storage.getEnergyStored() >= actualUse){
|
if(this.storage.getEnergyStored() >= actualUse){
|
||||||
BlockPos pos = new BlockPos(this.pos.getX()+anX, this.layerAt, this.pos.getZ()+aZ);
|
BlockPos pos = new BlockPos(this.pos.getX()+this.checkX, this.checkY, this.pos.getZ()+this.checkZ);
|
||||||
|
|
||||||
IBlockState state = this.world.getBlockState(pos);
|
IBlockState state = this.world.getBlockState(pos);
|
||||||
Block block = state.getBlock();
|
Block block = state.getBlock();
|
||||||
|
@ -117,18 +140,16 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
|
||||||
this.storage.extractEnergyInternal(actualUse, false);
|
this.storage.extractEnergyInternal(actualUse, false);
|
||||||
this.shootParticles(pos.getX(), pos.getY(), pos.getZ());
|
this.shootParticles(pos.getX(), pos.getY(), pos.getZ());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isMinable(Block block, int meta){
|
private boolean isMinable(Block block, int meta){
|
||||||
if(block != null){
|
if(block != null){
|
||||||
|
@ -196,7 +217,9 @@ public class TileEntityMiner extends TileEntityInventoryBase implements IButtonR
|
||||||
this.sendUpdate();
|
this.sendUpdate();
|
||||||
}
|
}
|
||||||
else if(buttonID == 1){
|
else if(buttonID == 1){
|
||||||
this.layerAt = -1;
|
this.checkX = 0;
|
||||||
|
this.checkY = -1;
|
||||||
|
this.checkZ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue