mirror of
https://github.com/GTNewHorizons/Electro-Magic-Tools.git
synced 2026-11-18 19:29:29 +00:00
Research completer - added node draining
This commit is contained in:
1 parent
1e17a18e3f
commit
67b9369cd5
1 file changed
+102
-10
@@ -1,26 +1,53 @@
|
||||
package emt.tile;
|
||||
|
||||
import gregtech.api.GregTech_API;
|
||||
import gregtech.api.enums.Textures;
|
||||
import gregtech.api.interfaces.ITexture;
|
||||
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
|
||||
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
|
||||
import gregtech.api.metatileentity.BaseMetaTileEntity;
|
||||
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_MultiBlockBase;
|
||||
import gregtech.api.render.TextureFactory;
|
||||
import gregtech.api.util.GT_Recipe;
|
||||
import gregtech.api.util.GT_Utility;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import thaumcraft.api.ThaumcraftApi;
|
||||
import thaumcraft.api.aspects.Aspect;
|
||||
import thaumcraft.api.aspects.AspectList;
|
||||
import thaumcraft.api.nodes.INode;
|
||||
import thaumcraft.api.research.ResearchCategories;
|
||||
import thaumcraft.api.research.ResearchItem;
|
||||
import thaumcraft.common.Thaumcraft;
|
||||
import thaumcraft.common.config.ConfigBlocks;
|
||||
import thaumcraft.common.config.ConfigItems;
|
||||
import thaumcraft.common.lib.research.ResearchManager;
|
||||
import thaumcraft.common.lib.research.ResearchNoteData;
|
||||
import thaumcraft.common.tiles.TileNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static gregtech.api.enums.Textures.BlockIcons.*;
|
||||
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_FRONT_IMPLOSION_COMPRESSOR_GLOW;
|
||||
|
||||
//TODO make sure completed notes can't go back in
|
||||
public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_MultiBlockBase {
|
||||
private final int MAX_LENGTH = 13;
|
||||
|
||||
private int length;
|
||||
private int recipeAspectCost;
|
||||
private int aspectsAbsorbed;
|
||||
|
||||
private class Coordinates {
|
||||
public Coordinates() {}
|
||||
public Coordinates(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
@@ -37,9 +64,50 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
//TODO deplete nodes, stop if no nodes are available
|
||||
@Override
|
||||
public boolean onRunningTick(ItemStack aStack) {
|
||||
//TODO consider only doing this every x ticks and make sure it finishes x ticks before the end of the recipe
|
||||
float progressAmount = ((float) this.mProgresstime) / this.mMaxProgresstime;
|
||||
int requiredVis = (int)Math.ceil(progressAmount * recipeAspectCost - aspectsAbsorbed);
|
||||
|
||||
//Loop through node spaces and drain them from front to back
|
||||
IGregTechTileEntity aBaseMetaTileEntity = this.getBaseMetaTileEntity();
|
||||
int xDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetX;
|
||||
int zDir = ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()).offsetZ;
|
||||
int i = 1;
|
||||
while (i < this.length - 1 && requiredVis > 0) {
|
||||
Coordinates nodeCoordinates = new Coordinates(aBaseMetaTileEntity.getXCoord() + xDir * i, aBaseMetaTileEntity.getYCoord(), aBaseMetaTileEntity.getZCoord() + zDir * i);
|
||||
TileEntity tileEntity = aBaseMetaTileEntity.getWorld().getTileEntity(nodeCoordinates.x, nodeCoordinates.y, nodeCoordinates.z);
|
||||
if (tileEntity instanceof TileNode) {
|
||||
TileNode aNode = (TileNode)tileEntity;
|
||||
AspectList aspectsBase = aNode.getAspectsBase();
|
||||
|
||||
for (Aspect aspect : aspectsBase.getAspects()) {
|
||||
int aspectAmount = aspectsBase.getAmount(aspect);
|
||||
int drainAmount = Math.min(requiredVis, aspectAmount);
|
||||
aNode.setNodeVisBase(aspect, (short) (aspectAmount - drainAmount));
|
||||
aNode.takeFromContainer(aspect, drainAmount);
|
||||
requiredVis -= drainAmount;
|
||||
aspectsAbsorbed += drainAmount;
|
||||
if (requiredVis <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (aspectsBase.visSize() <= 0)
|
||||
aBaseMetaTileEntity.getWorld().setBlockToAir(nodeCoordinates.x, nodeCoordinates.y, nodeCoordinates.z);
|
||||
|
||||
aNode.markDirty();
|
||||
aBaseMetaTileEntity.getWorld().markBlockForUpdate(nodeCoordinates.x, nodeCoordinates.y, nodeCoordinates.z);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (requiredVis > 0)
|
||||
this.criticalStopMachine();
|
||||
|
||||
return super.onRunningTick(aStack);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCorrectMachinePart(ItemStack itemStack) {
|
||||
return true;
|
||||
@@ -51,7 +119,14 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
|
||||
for (ItemStack stack : tInputList) {
|
||||
if (GT_Utility.isStackValid(stack) && stack.stackSize > 0) {
|
||||
if (stack.getItem() == ConfigItems.itemResearchNotes) {
|
||||
if (stack.getItem() == ConfigItems.itemResearchNotes && !stack.stackTagCompound.getBoolean("complete")) {
|
||||
ResearchNoteData noteData = ResearchManager.getData(stack);
|
||||
if (noteData == null)
|
||||
continue;
|
||||
ResearchItem researchItem = ResearchCategories.getResearch(noteData.key);
|
||||
if (researchItem == null)
|
||||
continue;
|
||||
|
||||
this.mEfficiency = 10000 - (this.getIdealStatus() - this.getRepairStatus()) * 1000;
|
||||
this.mEfficiencyIncrease = 10000;
|
||||
this.calculateOverclockedNessMulti(120, 1200, 1, this.getMaxInputVoltage());
|
||||
@@ -67,7 +142,10 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
this.mOutputItems[0].stackTagCompound.setBoolean("complete", true);
|
||||
this.mOutputItems[0].setItemDamage(64);
|
||||
stack.stackSize -= 1;
|
||||
this.sendLoopStart((byte)20);
|
||||
this.aspectsAbsorbed = 0;
|
||||
this.recipeAspectCost = researchItem.tags.visSize();
|
||||
|
||||
this.sendLoopStart((byte) 20);
|
||||
this.updateSlots();
|
||||
return true;
|
||||
}
|
||||
@@ -82,14 +160,13 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
int xDir = ForgeDirection.getOrientation(iGregTechTileEntity.getBackFacing()).offsetX;
|
||||
int zDir = ForgeDirection.getOrientation(iGregTechTileEntity.getBackFacing()).offsetZ;
|
||||
|
||||
int length = findLength(iGregTechTileEntity, xDir, zDir);
|
||||
if (length < 2)
|
||||
this.length = findLength(iGregTechTileEntity, xDir, zDir);
|
||||
if (this.length < 2)
|
||||
return false;
|
||||
|
||||
//Do structure check
|
||||
boolean eastWest = xDir != 0;
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
for (int i = 0; i < this.length; i++) {
|
||||
for (int j = -1; j < 2; j++) {
|
||||
for (int h = -1; h < 2; h++) {
|
||||
int forwardsOffset = eastWest ? i * xDir : i * zDir;
|
||||
@@ -114,7 +191,7 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
return false;
|
||||
}
|
||||
} else { //Check for machine casings and buses etc.
|
||||
if (sidewaysOffset != 0 || forwardsOffset == 0 || Math.abs(forwardsOffset) == length - 1) { //Check ring shapes on top and bottom
|
||||
if (sidewaysOffset != 0 || forwardsOffset == 0 || Math.abs(forwardsOffset) == this.length - 1) { //Check ring shapes on top and bottom
|
||||
//TODO change casing index to correct for this multi
|
||||
if (!this.addMaintenanceToMachineList(tTileEntity, 16) && !this.addInputToMachineList(tTileEntity, 16) && !this.addOutputToMachineList(tTileEntity, 16) && !this.addEnergyInputToMachineList(tTileEntity, 16)) {
|
||||
if ((tBlock != GregTech_API.sBlockCasings2 || tMeta != 0))
|
||||
@@ -130,7 +207,7 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
}
|
||||
|
||||
private int findLength(final IGregTechTileEntity iGregTechTileEntity, final int xDir, final int zDir) {
|
||||
for (int i = 1; i < MAX_LENGTH; i++) {
|
||||
for (int i = 1; i < this.MAX_LENGTH; i++) {
|
||||
Block tBlock = iGregTechTileEntity.getBlockOffset(xDir * i, 0, zDir * i);
|
||||
byte tMeta = iGregTechTileEntity.getMetaIDOffset(xDir * i, 0, zDir * i);
|
||||
if (tBlock == ConfigBlocks.blockCosmeticOpaque && tMeta == 2) {
|
||||
@@ -153,7 +230,7 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaxEfficiency(ItemStack itemStack) {
|
||||
return 10000;
|
||||
@@ -189,8 +266,23 @@ public class TileEntityResearchMultiblockController extends GT_MetaTileEntity_Mu
|
||||
}
|
||||
|
||||
//TODO texture
|
||||
@Override
|
||||
/*@Override
|
||||
public ITexture[] getTexture(IGregTechTileEntity iGregTechTileEntity, byte b, byte b1, byte b2, boolean b3, boolean b4) {
|
||||
return new ITexture[0];
|
||||
}*/
|
||||
//Temp copied from implosion compressor
|
||||
@Override
|
||||
public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, byte aSide, byte aFacing, byte aColorIndex, boolean aActive, boolean aRedstone) {
|
||||
if (aSide == aFacing) {
|
||||
if (aActive) return new ITexture[]{
|
||||
Textures.BlockIcons.casingTexturePages[0][16],
|
||||
TextureFactory.of(OVERLAY_FRONT_IMPLOSION_COMPRESSOR_ACTIVE),
|
||||
TextureFactory.builder().addIcon(OVERLAY_FRONT_IMPLOSION_COMPRESSOR_ACTIVE_GLOW).glow().build()};
|
||||
return new ITexture[]{
|
||||
Textures.BlockIcons.casingTexturePages[0][16],
|
||||
TextureFactory.of(OVERLAY_FRONT_IMPLOSION_COMPRESSOR),
|
||||
TextureFactory.builder().addIcon(OVERLAY_FRONT_IMPLOSION_COMPRESSOR_GLOW).glow().build()};
|
||||
}
|
||||
return new ITexture[]{Textures.BlockIcons.casingTexturePages[0][16]};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user