make advanced provider can bind to multi matrix (#77)

* make advanced provider can bind to mutil matrix

and can request 16 crafting job max

* update research description

* fix something point out by @OneEyeMaker

* remove unnecessary null check
This commit is contained in:
MCTBL authored and GitHub committed 2024-10-13 17:53:52 +02:00
1 parent b0c25425ef
commit 501e0249bb
7 files changed
+84 -95

No files matched your search

@@ -46,8 +46,8 @@ public class BlockAdvancedInfusionProvider extends AbstractBlockProviderBase {
protected boolean onBlockActivated(final World world, final int x, final int y, final int z,
final EntityPlayer player) {
if (world.getTileEntity(x, y, z) instanceof TileAdvancedInfusionProvider taip && taip.isActive()) {
if (taip.matrix != null) {
taip.unbindMatrix();
if (!taip.matrices.isEmpty()) {
taip.unbindMatrixs();
}
taip.searchMatrix();
return true;
@@ -79,7 +79,7 @@ public enum ThEStrings {
Tooltip_AdvancedInfusionProviderWorkingMode("tooltip.advanced.infusion.provider.working.on", false),
Tooltip_AdvancedInfusionProviderNormalMode("tooltip.advanced.infusion.provider.normal", false),
Tooltip_AdvancedInfusionProviderAdvancedMode("tooltip.advanced.infusion.provider.advanced", false),
Tooltip_AdvancedInfusionProviderBindTo("tooltip.advanced.infusion.provider.bindto", false),
Tooltip_AdvancedInfusionProviderTotalBind("tooltip.advanced.infusion.provider.totalbind", false),
// Button Tooltips
TooltipButton_VoidHeader("tooltip.button.void", false),
@@ -1,9 +1,9 @@
package thaumicenergistics.common.tiles;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
@@ -13,6 +13,7 @@ import thaumcraft.api.aspects.IAspectSource;
import thaumcraft.common.tiles.TileInfusionMatrix;
import thaumicenergistics.api.ThEApi;
import thaumicenergistics.common.registries.ThEStrings;
import thaumicenergistics.implementaion.ThEMultiCraftingTracker;
/**
* Upgrade version of {@link TileInfusionProvider} works like intercepter and old provider can auto order essential it
@@ -23,13 +24,17 @@ import thaumicenergistics.common.registries.ThEStrings;
*/
public class TileAdvancedInfusionProvider extends TileInfusionProvider implements IAspectSource {
private static final String NBT_MATRIX_X = "MatrixX", NBT_MATRIX_Y = "MatrixY", NBT_MATRIX_Z = "MatrixZ";
public List<TileInfusionMatrix> matrices = new ArrayList<>();
private List<TileInfusionMatrix> matricesToRemove = new ArrayList<>();
public TileInfusionMatrix matrix = null;
public static final int HORIZONTAL_RADIUS = 12;
public static final int VERTICAL_RADIUS = 5;
private int currentZ = -HORIZONTAL_RADIUS;
private Integer matrixX = null, matrixY = null, matrixZ = null;
private int tickCounter = 0;
public TileAdvancedInfusionProvider() {
super();
this.craftingTracker = new ThEMultiCraftingTracker(this, 16);
}
/**
* How much power does this require just to be active?
@@ -48,7 +53,7 @@ public class TileAdvancedInfusionProvider extends TileInfusionProvider implement
@Override
public boolean takeFromContainer(final Aspect tag, final int amount) {
// Not in advanced mode
if (this.matrix == null) {
if (this.matrices.isEmpty()) {
// Can we extract the essentia from the network?
if (this.extractEssentiaFromNetwork(tag, amount, true) == amount) {
// Show partical FX
@@ -64,59 +69,44 @@ public class TileAdvancedInfusionProvider extends TileInfusionProvider implement
public void searchMatrix() {
// If allready bind infusion matrix or worldObj is null
if (this.matrix != null || this.worldObj == null) {
// If worldObj is null
if (this.worldObj == null) {
// Do nothing
return;
}
int x = this.xCoord;
int y = this.yCoord;
int z = this.zCoord;
for (int dx = -4; dx <= 4; dx++) {
for (int dy = -4; dy <= 4; dy++) {
for (int dz = -4; dz <= 4; dz++) {
if (dx == 0 && dy == 0 && dz == 0) continue;
if (this.bindMatrix(x + dx, y + dy, z + dz)) {
this.matrixX = x + dx;
this.matrixY = y + dy;
this.matrixZ = z + dz;
return;
}
}
for (int dx = -HORIZONTAL_RADIUS; dx <= HORIZONTAL_RADIUS; dx++) {
for (int dy = -VERTICAL_RADIUS; dy <= VERTICAL_RADIUS; dy++) {
if (dx == 0 && dy == 0 && currentZ == 0) continue;
this.bindMatrixs(this.xCoord + dx, this.yCoord + dy, this.zCoord + this.currentZ);
}
}
if (++this.currentZ > HORIZONTAL_RADIUS) {
this.currentZ = -HORIZONTAL_RADIUS;
}
}
public boolean bindMatrix(final int x, final int y, final int z) {
public void bindMatrixs(final int x, final int y, final int z) {
if (this.worldObj != null && this.worldObj.getTileEntity(x, y, z) instanceof TileInfusionMatrix tim) {
this.matrix = tim;
this.matrices.add(tim);
this.markForUpdate();
this.saveChanges();
return true;
} else {
return false;
}
}
public boolean bindMatrix() {
return this.bindMatrix(this.matrixX, this.matrixY, this.matrixZ);
}
public void unbindMatrix() {
this.matrix = null;
this.matrixX = null;
this.matrixY = null;
this.matrixZ = null;
public void unbindMatrixs() {
this.matrices.clear();
this.markForUpdate();
this.saveChanges();
}
public void grabAllAspects() {
if (this.matrix.getAspects().size() != 0) {
AspectList aspectList = this.matrix.getAspects().copy();
public void grabAllAspects(final TileInfusionMatrix matrix) {
if (matrix.getAspects().size() != 0) {
AspectList aspectList = matrix.getAspects().copy();
for (Aspect aspect : aspectList.getAspects()) {
if (aspect != null) {
int needAspectsAmount = aspectList.getAmount(aspect);
@@ -136,32 +126,10 @@ public class TileAdvancedInfusionProvider extends TileInfusionProvider implement
}
}
@Override
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public void onSaveNBT(final NBTTagCompound data) {
if (this.matrix != null) {
data.setInteger(NBT_MATRIX_X, this.matrix.xCoord);
data.setInteger(NBT_MATRIX_Y, this.matrix.yCoord);
data.setInteger(NBT_MATRIX_Z, this.matrix.zCoord);
}
super.onSaveNBT(data);
}
@Override
@TileEvent(TileEventType.WORLD_NBT_READ)
public void onLoadNBT(final NBTTagCompound data) {
if (data.hasKey(NBT_MATRIX_X) && data.hasKey(NBT_MATRIX_Y) && data.hasKey(NBT_MATRIX_Z)) {
this.matrixX = data.getInteger(NBT_MATRIX_X);
this.matrixY = data.getInteger(NBT_MATRIX_Y);
this.matrixZ = data.getInteger(NBT_MATRIX_Z);
}
super.onLoadNBT(data);
}
@Override
public void addWailaInformation(List<String> tooltip) {
super.addWailaInformation(tooltip);
if (this.matrix == null) {
if (this.matrices.isEmpty()) {
tooltip.add(
ThEStrings.Tooltip_AdvancedInfusionProviderWorkingMode.getLocalized() + ":"
+ ThEStrings.Tooltip_AdvancedInfusionProviderNormalMode.getLocalized());
@@ -171,27 +139,33 @@ public class TileAdvancedInfusionProvider extends TileInfusionProvider implement
+ ThEStrings.Tooltip_AdvancedInfusionProviderAdvancedMode.getLocalized());
tooltip.add(
String.format(
ThEStrings.Tooltip_AdvancedInfusionProviderBindTo.getLocalized(),
this.matrixX,
this.matrixY,
this.matrixZ));
ThEStrings.Tooltip_AdvancedInfusionProviderTotalBind.getLocalized(),
this.matrices.size()));
}
}
@TileEvent(TileEventType.TICK)
public void onTick() {
// Try binding matrix every 20 tick
if (++tickCounter % 20 == 0 && this.matrix == null && this.isActive) {
if (this.matrixX == null || this.matrixY == null || this.matrixZ == null) {
this.searchMatrix();
} else if (!this.bindMatrix()) {
this.unbindMatrix();
}
tickCounter = 0;
// Try binding matrix when is active
if (this.isActive) {
this.searchMatrix();
}
if (this.isActive && this.matrix != null) {
this.grabAllAspects();
if (!this.matrices.isEmpty() && this.isActive) {
for (TileInfusionMatrix matrix : this.matrices) {
if (matrix == null) {
this.matricesToRemove.add(matrix);
} else {
this.grabAllAspects(matrix);
}
}
}
if (!this.matricesToRemove.isEmpty()) {
this.matrices.removeAll(this.matricesToRemove);
this.matricesToRemove.clear();
this.markForUpdate();
this.saveChanges();
}
}
@@ -87,7 +87,7 @@ public abstract class TileProviderBase extends AENetworkTile
*/
protected boolean isColorForced = false;
protected final ThEMultiCraftingTracker craftingTracker = new ThEMultiCraftingTracker(this, 1);
protected ThEMultiCraftingTracker craftingTracker = new ThEMultiCraftingTracker(this, 1);
public TileProviderBase() {
// Create the source
@@ -538,14 +538,17 @@ public abstract class TileProviderBase extends AENetworkTile
IAEItemStack itemStack = AEApi.instance().storage()
.createItemStack(ItemCraftingAspect.createStackForAspect(aspect, 1));
if (!craftingGrid.isRequesting(itemStack)) {
return this.craftingTracker.handleCrafting(
0,
amount,
itemStack,
this.getWorldObj(),
grid,
craftingGrid,
this.getMachineSource());
int index = this.craftingTracker.getFirstEmptySlot();
if (index >= 0) {
return this.craftingTracker.handleCrafting(
index,
amount,
itemStack,
this.getWorldObj(),
grid,
craftingGrid,
this.getMachineSource());
}
}
} catch (Exception e) {}
return false;
@@ -100,6 +100,20 @@ public class ThEMultiCraftingTracker {
return ImmutableSet.copyOf(result);
}
public int getFirstEmptySlot() {
if (this.links == null) {
this.links = new ICraftingLink[this.size];
}
for (int index = 0; index < this.size; index++) {
ICraftingLink link = this.links[index];
if (link == null || link.isDone() || link.isCanceled()) {
return index;
}
}
return -1;
}
public void jobStateChange(final ICraftingLink link) {
if (this.links != null) {
for (int x = 0; x < this.links.length; x++) {
@@ -130,7 +144,6 @@ public class ThEMultiCraftingTracker {
l.cancel();
}
}
this.links = null;
}
@@ -140,7 +153,6 @@ public class ThEMultiCraftingTracker {
l.cancel(true);
}
}
this.jobs = null;
}
}
@@ -82,7 +82,7 @@ thaumicenergistics.tooltip.button.reset.aspect.description=Reset the left-hand a
thaumicenergistics.tooltip.advanced.infusion.provider.working.on=Workig Mode
thaumicenergistics.tooltip.advanced.infusion.provider.normal=Normal Provider
thaumicenergistics.tooltip.advanced.infusion.provider.advanced=Advanced Provider
thaumicenergistics.tooltip.advanced.infusion.provider.bindto=Bind to %s %s %s matrix
thaumicenergistics.tooltip.advanced.infusion.provider.totalbind=Total binded to %d matrixs
#GUI
@@ -148,7 +148,7 @@ thaumicenergistics.research_page.TEINFPROV.1=By researching the process of essen
# Research Advanced Infusion Provider
tc.research_name.thaumicenergistics.TEADVINFPROV=Advanced Infusion Provider
tc.research_text.thaumicenergistics.TEADVINFPROV=Easiest Infusion.
thaumicenergistics.research_page.TEADVINFPROV.1=As you continue to optimize your ME network autocrafting, you've been stumped by infusion recipes countless times.<BR>Now you have a new idea, why not leave the task of preparing essentia to your ME network?<BR>So you've developed a new infusion provider that incorporates the functionality of the Interceptor and automatically orders the missing essentia. It can also bind infusion matrix in a 9*9*9 area. Right-clicking allows him to search the area for matrix and rebind it.
thaumicenergistics.research_page.TEADVINFPROV.1=As you continue to optimize your ME network autocrafting, you've been stumped by infusion recipes countless times.<BR>Now you have a new idea, why not leave the task of preparing essentia to your ME network?<BR>So you've developed a new infusion provider that incorporates the functionality of the Interceptor and automatically orders the missing essentia. It can also bind multiple infusion matrices in 25*25*11 area. All you need to do is just put it down among those matrices, that's it. Right-click allows him to search the area for matrix and rebind it.
# Research Vis Interface
tc.research_name.thaumicenergistics.TEVISINT=Vis Relay Interface
@@ -82,7 +82,7 @@ thaumicenergistics.tooltip.button.reset.aspect.description=重置左侧源质表
thaumicenergistics.tooltip.advanced.infusion.provider.working.on=工作模式
thaumicenergistics.tooltip.advanced.infusion.provider.normal=普通供应器
thaumicenergistics.tooltip.advanced.infusion.provider.advanced=进阶供应器
thaumicenergistics.tooltip.advanced.infusion.provider.bindto=绑定至 %s %s %s 矩阵
thaumicenergistics.tooltip.advanced.infusion.provider.totalbind=已绑定 %d 个矩阵
#GUI
@@ -148,7 +148,7 @@ thaumicenergistics.research_page.TEINFPROV.1=通过研究源质注魔的过程,
# Research Advanced Infusion Provider
tc.research_name.thaumicenergistics.TEADVINFPROV=进阶注魔供应器
tc.research_text.thaumicenergistics.TEADVINFPROV=极简化注魔.
thaumicenergistics.research_page.TEADVINFPROV.1=当你不断的优化自己的网络合成自动化时,你无数次的被注魔时需要的要素源质的制作给难住了.<BR>现在,你有了全新的想法,不如把计算源质合成的任务交给ME网络来做?<BR>于是你开发出了新的注魔供应器,包含截流者的功能,且能自动下单缺失的源质,会在自身为中心9*9*9空间搜索矩阵自动绑定.右键可以让他重新搜索区域内的矩阵并重新绑定.
thaumicenergistics.research_page.TEADVINFPROV.1=当你不断的优化自己的网络合成自动化时,你无数次的被注魔时需要的要素源质的制作给难住了.<BR>现在,你有了全新的想法,不如把计算源质合成的任务交给ME网络来做?<BR>于是你试着使用自己的魔法技巧,将截流者与原有的供应器进行结合,经过你的不懈努力得到了这个进阶注魔供应器,它会在自身为中心25*25*11的空间内搜索所有的注魔矩阵并自动绑定,且当他发现源质缺失时会自动进行下单,你需要做的只有把他放在多个矩阵的中间,就是这么简单.<BR>右键可以让他重新搜索区域内的矩阵并重新绑定.
# Research Vis Interface
tc.research_name.thaumicenergistics.TEVISINT=要素中继接口