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 1 commit
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,7 +46,7 @@ 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.matrixs.isEmpty()) {
if (!taip.matrices.isEmpty()) {
taip.unbindMatrixs();
}
taip.searchMatrix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 @@ -25,10 +24,12 @@
*/
public class TileAdvancedInfusionProvider extends TileInfusionProvider implements IAspectSource {

public List<TileInfusionMatrix> matrixs = new ArrayList<>();
private List<TileInfusionMatrix> waitToRemoveMatrix = new ArrayList<>();
public List<TileInfusionMatrix> matrices = new ArrayList<>();
private List<TileInfusionMatrix> matricesToRemove = new ArrayList<>();

private int tickCounter = 50;
public static final int HORIZONTAL_RADIUS = 12;
public static final int VERTICAL_RADIUS = 5;
private int currentZ = -HORIZONTAL_RADIUS;

public TileAdvancedInfusionProvider() {
super();
Expand All @@ -52,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.matrixs.isEmpty()) {
if (this.matrices.isEmpty()) {
// Can we extract the essentia from the network?
if (this.extractEssentiaFromNetwork(tag, amount, true) == amount) {
// Show partical FX
Expand All @@ -68,44 +69,43 @@ public boolean takeFromContainer(final Aspect tag, final int amount) {

public void searchMatrix() {

// If allready bind infusion matrix or worldObj is null
if ((this.matrixs != null && !this.matrixs.isEmpty()) || 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 = -12; dx <= 12; dx++) {
for (int dy = -5; dy <= 5; dy++) {
for (int dz = -12; dz <= 12; dz++) {
if (dx == 0 && dy == 0 && dz == 0) continue;
this.bindMatrixs(x + dx, y + dy, z + dz);
}
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 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.matrixs.add(tim);
this.matrices.add(tim);

this.markForUpdate();
this.saveChanges();
}
}

public void unbindMatrixs() {
this.matrixs.clear();
this.matrices.clear();

this.markForUpdate();
this.saveChanges();
}

public void grabAllAspects(final TileInfusionMatrix matrix) {
if (matrix.getAspects().size() != 0) {

AspectList aspectList = matrix.getAspects().copy();
for (Aspect aspect : aspectList.getAspects()) {
if (aspect != null) {
Expand All @@ -126,22 +126,10 @@ public void grabAllAspects(final TileInfusionMatrix matrix) {
}
}

@Override
@TileEvent(TileEventType.WORLD_NBT_WRITE)
public void onSaveNBT(final NBTTagCompound data) {
super.onSaveNBT(data);
}

@Override
@TileEvent(TileEventType.WORLD_NBT_READ)
public void onLoadNBT(final NBTTagCompound data) {
super.onLoadNBT(data);
}

@Override
public void addWailaInformation(List<String> tooltip) {
super.addWailaInformation(tooltip);
if (this.matrixs == null || (this.matrixs != null && this.matrixs.isEmpty())) {
if (this.matrices == null || (this.matrices != null && this.matrices.isEmpty())) {
MCTBL marked this conversation as resolved.
Show resolved Hide resolved
tooltip.add(
ThEStrings.Tooltip_AdvancedInfusionProviderWorkingMode.getLocalized() + ":"
+ ThEStrings.Tooltip_AdvancedInfusionProviderNormalMode.getLocalized());
Expand All @@ -152,32 +140,30 @@ public void addWailaInformation(List<String> tooltip) {
tooltip.add(
String.format(
ThEStrings.Tooltip_AdvancedInfusionProviderTotalBind.getLocalized(),
this.matrixs.size()));
this.matrices.size()));
}
}

@TileEvent(TileEventType.TICK)
public void onTick() {
// Try binding matrix every 5s
if (++tickCounter >= 100 && this.matrixs.isEmpty() && this.isActive) {
// Try binding matrix when is active
if (this.isActive) {
this.searchMatrix();

tickCounter = 0;
}

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

if (!this.waitToRemoveMatrix.isEmpty()) {
this.matrixs.removeAll(this.waitToRemoveMatrix);
this.waitToRemoveMatrix.clear();
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 @@ -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 multiple infusion matrixs in 25*25*11 area. All you need to do just put it down among those matrixs, that's it. Right click 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