Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make advanced provider can bind to multi matrix #77

Merged
merged 4 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public BlockAdvancedInfusionProvider() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +13,7 @@
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
Expand All @@ -23,13 +24,17 @@
*/
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?
Expand All @@ -48,7 +53,7 @@ protected ItemStack getItemFromTile(final Object obj) {
@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
Expand All @@ -64,59 +69,44 @@ public boolean takeFromContainer(final Aspect tag, final int amount) {

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);
Expand All @@ -136,32 +126,10 @@ public void grabAllAspects() {
}
}

@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 == null || (this.matrices != null && this.matrices.isEmpty())) {
tooltip.add(
ThEStrings.Tooltip_AdvancedInfusionProviderWorkingMode.getLocalized() + ":"
+ ThEStrings.Tooltip_AdvancedInfusionProviderNormalMode.getLocalized());
Expand All @@ -171,27 +139,33 @@ public void addWailaInformation(List<String> tooltip) {
+ 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();
// Try binding matrix when is active
if (this.isActive) {
this.searchMatrix();
}

if (!this.matrices.isEmpty() && this.isActive) {
for (TileInfusionMatrix matrix : this.matrices) {
if (matrix == null) {
this.matricesToRemove.add(matrix);
} else {
this.grabAllAspects(matrix);
}
}
tickCounter = 0;
}

if (this.isActive && this.matrix != null) {
this.grabAllAspects();
if (!this.matricesToRemove.isEmpty()) {
this.matrices.removeAll(this.matricesToRemove);
this.matricesToRemove.clear();
this.markForUpdate();
this.saveChanges();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -538,14 +538,17 @@ public boolean orderSomeEssentia(final Aspect aspect, final int amount) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ public ImmutableSet<ICraftingLink> getRequestedJobs() {
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++) {
Expand Down Expand Up @@ -130,7 +144,6 @@ void cancel() {
l.cancel();
}
}

this.links = null;
}

Expand All @@ -140,7 +153,6 @@ void cancel() {
l.cancel(true);
}
}

this.jobs = null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/assets/thaumicenergistics/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/assets/thaumicenergistics/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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=要素中继接口
Expand Down