Skip to content

Commit

Permalink
assign unique ids to hatches on splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
NotAPenguin0 committed Aug 30, 2024
1 parent 3127a0b commit c005595
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/enums/ItemList.java
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@ public enum ItemList implements IItemContainer {
NanoChipModule_EtchingArray,
NanoChipModule_CuttingChamber,
NanoChipModule_WireTracer,
NanoChipModule_Splitter,
Machine_Multi_Autoclave,
Casing_Autoclave,

Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/enums/MetaTileEntityIDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ public enum MetaTileEntityIDs {
NANOCHIP_MODULE_ETCHING_ARRAY(9507),
NANOCHIP_MODULE_CUTTING_CHAMBER(9508),
NANOCHIP_MODULE_WIRE_TRACER(9509),
NANOCHIP_MODULE_SPLITTER(9510),
PLASMA_GENERATOR_ZPM(10752),
PLASMA_GENERATOR_UV(10753),
ALLOY_SMELTER_LuV(10760),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public abstract class GT_MetaTileEntity_Hatch_VacuumConveyor extends GT_MetaTile

public CircuitComponentPacket contents;

// Identifier used to identify this hatch uniquely inside a multiblock.
public String identifier = null;

protected GT_MetaTileEntity_Hatch_VacuumConveyor(int aID, String aName, String aNameRegional, int aTier,
String[] descr) {
super(aID, aName, aNameRegional, aTier, 0, descr);
Expand Down Expand Up @@ -148,6 +151,9 @@ public void loadNBTData(NBTTagCompound aNBT) {
public String[] getInfoData() {
ArrayList<String> info = new ArrayList<>(Arrays.asList(super.getInfoData()));
info.add("Contents: ");
if (identifier != null) {
info.add("Hatch ID: " + identifier);
}
if (contents != null) {
// TODO: Would be neat to get a gui that displays these in item form I suppose (using some fake items or
// something)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package gregtech.common.tileentities.machines.multi.nanochip.modules;

import static com.gtnewhorizon.structurelib.structure.StructureUtility.ofBlock;
import static gregtech.api.util.GT_RecipeBuilder.SECONDS;

import java.util.ArrayList;
import java.util.Map;

import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;

import org.jetbrains.annotations.NotNull;

import com.gtnewhorizon.structurelib.structure.IStructureDefinition;
import com.gtnewhorizon.structurelib.structure.ISurvivalBuildEnvironment;

import gregtech.api.GregTech_API;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.common.tileentities.machines.multi.nanochip.GT_MetaTileEntity_NanochipAssemblyModuleBase;
import gregtech.common.tileentities.machines.multi.nanochip.hatches.GT_MetaTileEntity_Hatch_VacuumConveyor_Input;
import gregtech.common.tileentities.machines.multi.nanochip.hatches.GT_MetaTileEntity_Hatch_VacuumConveyor_Output;
import gregtech.common.tileentities.machines.multi.nanochip.util.ModuleStructureDefinition;

public class Splitter extends GT_MetaTileEntity_NanochipAssemblyModuleBase<Splitter> {

protected static final int STRUCTURE_OFFSET_X = 3;
protected static final int STRUCTURE_OFFSET_Y = 3;
protected static final int STRUCTURE_OFFSET_Z = -2;

protected static final String STRUCTURE_PIECE_MAIN = "main";
private static final String[][] structure = new String[][] { { " AAA ", " AAA ", " AAA " },
{ " AAA ", " A A ", " AAA " }, { " AAA ", " AAA ", " AAA " } };

public static final IStructureDefinition<Splitter> STRUCTURE_DEFINITION = ModuleStructureDefinition
.<Splitter>builder()
.addShape(STRUCTURE_PIECE_MAIN, structure)
.addElement('A', ofBlock(GregTech_API.sBlockCasings4, 0))
.build();

public Splitter(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}

protected Splitter(String aName) {
super(aName);
}

@Override
public IStructureDefinition<Splitter> getStructureDefinition() {
return STRUCTURE_DEFINITION;
}

@Override
public void construct(ItemStack trigger, boolean hintsOnly) {
// Should only construct the main structure, since the base structure is built by the nanochip assembly complex.
buildPiece(
STRUCTURE_PIECE_MAIN,
trigger,
hintsOnly,
STRUCTURE_OFFSET_X,
STRUCTURE_OFFSET_Y,
STRUCTURE_OFFSET_Z);
}

@Override
public int survivalConstruct(ItemStack trigger, int elementBudget, ISurvivalBuildEnvironment env) {
// Should only construct the main structure, since the base structure is built by the nanochip assembly complex.
return survivialBuildPiece(
STRUCTURE_PIECE_MAIN,
trigger,
STRUCTURE_OFFSET_X,
STRUCTURE_OFFSET_Y,
STRUCTURE_OFFSET_Z,
elementBudget,
env,
false,
true);
}

private static EnumChatFormatting getPrefixColor(byte color) {
return switch (color) {
case 0 -> EnumChatFormatting.BLACK;
case 1 -> EnumChatFormatting.RED;
case 2 -> EnumChatFormatting.DARK_GREEN;
case 3 -> EnumChatFormatting.DARK_RED;
case 4 -> EnumChatFormatting.DARK_BLUE;
case 5 -> EnumChatFormatting.DARK_AQUA;
case 6 -> EnumChatFormatting.AQUA;
case 7 -> EnumChatFormatting.GRAY;
case 8 -> EnumChatFormatting.DARK_GRAY;
case 9 -> EnumChatFormatting.LIGHT_PURPLE;
case 10 -> EnumChatFormatting.GREEN;
case 11 -> EnumChatFormatting.YELLOW;
case 12 -> EnumChatFormatting.BLUE;
case 13 -> EnumChatFormatting.DARK_PURPLE;
case 14 -> EnumChatFormatting.GOLD;
case 15 -> EnumChatFormatting.WHITE;
default -> EnumChatFormatting.RESET;
};
}

private void assignHatchIdentifiers() {
// Assign ID of all hatches based on their color, index and whether they are an input or an output hatch.

int hatchID = 0;
for (Map.Entry<Byte, ArrayList<GT_MetaTileEntity_Hatch_VacuumConveyor_Input>> inputList : this.vacuumConveyorInputs
.hatchMap()
.entrySet()) {
byte color = inputList.getKey();
EnumChatFormatting colorFormat = getPrefixColor(color);
ArrayList<GT_MetaTileEntity_Hatch_VacuumConveyor_Input> hatches = inputList.getValue();
for (GT_MetaTileEntity_Hatch_VacuumConveyor_Input hatch : hatches) {
hatch.identifier = colorFormat + "In/" + hatchID;
hatchID += 1;
}
}

hatchID = 0;
for (Map.Entry<Byte, ArrayList<GT_MetaTileEntity_Hatch_VacuumConveyor_Output>> outputList : this.vacuumConveyorOutputs
.hatchMap()
.entrySet()) {
byte color = outputList.getKey();
EnumChatFormatting colorFormat = getPrefixColor(color);
ArrayList<GT_MetaTileEntity_Hatch_VacuumConveyor_Output> hatches = outputList.getValue();
for (GT_MetaTileEntity_Hatch_VacuumConveyor_Output hatch : hatches) {
hatch.identifier = colorFormat + "Out/" + hatchID;
hatchID += 1;
}
}
}

@Override
public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) {
// Check base structure
if (!super.checkMachine(aBaseMetaTileEntity, aStack)) return false;
// Now check module structure
if (!checkPiece(STRUCTURE_PIECE_MAIN, STRUCTURE_OFFSET_X, STRUCTURE_OFFSET_Y, STRUCTURE_OFFSET_Z)) {
return false;
}
assignHatchIdentifiers();
return true;
}

@Override
protected GT_Multiblock_Tooltip_Builder createTooltip() {
return new GT_Multiblock_Tooltip_Builder().toolTipFinisher("GregTech");
}

@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new Splitter(this.mName);
}

@Override
public @NotNull CheckRecipeResult checkProcessing() {
// Always keep the machine running, it doesn't run recipes directly.
if (isAllowedToWork()) {
mEfficiencyIncrease = 10000;
mMaxProgresstime = 1 * SECONDS;

return CheckRecipeResultRegistry.SUCCESSFUL;
}

mEfficiencyIncrease = 0;
mMaxProgresstime = 0;
return CheckRecipeResultRegistry.NO_RECIPE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public Collection<ArrayList<T>> allHatches() {
return conveyorsByColor.values();
}

public Map<Byte, ArrayList<T>> hatchMap() {
return this.conveyorsByColor;
}

// Count all hatches in the map
public int size() {
return totalNumHatches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,7 @@
import gregtech.common.tileentities.machines.multi.nanochip.modules.CuttingChamber;
import gregtech.common.tileentities.machines.multi.nanochip.modules.EtchingArray;
import gregtech.common.tileentities.machines.multi.nanochip.modules.SMDProcessor;
import gregtech.common.tileentities.machines.multi.nanochip.modules.Splitter;
import gregtech.common.tileentities.machines.multi.nanochip.modules.WireTracer;
import gregtech.common.tileentities.machines.multi.purification.GT_MetaTileEntity_Hatch_DegasifierControlHatch;
import gregtech.common.tileentities.machines.multi.purification.GT_MetaTileEntity_LensHousing;
Expand Down Expand Up @@ -1675,6 +1676,9 @@ private static void registerMultiblockControllers() {
NANOCHIP_MODULE_WIRE_TRACER.ID,
"multimachine.nanochipmodule.wiretracer",
"Nanoprecision Wire Tracer").getStackForm(1));
ItemList.NanoChipModule_Splitter.set(
new Splitter(NANOCHIP_MODULE_SPLITTER.ID, "multimachine.nanochipmodule.splitter", "Nanopart Splitter")
.getStackForm(1));
ItemList.Machine_Multi_Autoclave.set(
new GT_MetaTileEntity_MultiAutoclave(
MULTI_AUTOCLAVE_CONTROLLER.ID,
Expand Down

0 comments on commit c005595

Please sign in to comment.