Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Add scanner mode for research station #283

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -37,6 +37,8 @@
import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
Expand Down Expand Up @@ -83,6 +85,7 @@
import gregtech.api.recipe.check.SimpleCheckRecipeResult;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.shutdown.ShutDownReason;
import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_InputBus_ME;
import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_OutputBus_ME;
import gregtech.common.tileentities.machines.GT_MetaTileEntity_Hatch_Output_ME;
Expand Down Expand Up @@ -1381,8 +1384,8 @@ private void outputFailedChance() {
}

@Override
public void stopMachine() {
super.stopMachine();
public void stopMachine(@Nonnull ShutDownReason reason) {
super.stopMachine(reason);
destroyRenderBlock();
recipeRunning = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.Collections;
import java.util.List;

import javax.annotation.Nonnull;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -61,6 +63,7 @@
import gregtech.api.recipe.check.SimpleCheckRecipeResult;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.IGT_HatchAdder;
import gregtech.api.util.shutdown.ShutDownReason;

/**
* Created by danie_000 on 17.12.2016.
Expand Down Expand Up @@ -417,8 +420,8 @@ protected long getAvailableData_EM() {
}

@Override
public void stopMachine() {
super.stopMachine();
public void stopMachine(@Nonnull ShutDownReason reason) {
super.stopMachine(reason);
eAvailableData = 0;
for (GT_MetaTileEntity_Hatch_Rack rack : filterValidMTEs(eRacks)) {
rack.getBaseMetaTileEntity().setActive(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static com.gtnewhorizon.structurelib.structure.StructureUtility.transpose;
import static gregtech.api.enums.GT_HatchElement.Energy;
import static gregtech.api.enums.GT_HatchElement.Maintenance;
import static gregtech.api.recipe.RecipeMaps.scannerFakeRecipes;
import static gregtech.api.util.GT_StructureUtility.buildHatchAdder;
import static gregtech.api.util.GT_Utility.filterValidMTEs;
import static mcp.mobius.waila.api.SpecialChars.GREEN;
Expand All @@ -22,13 +23,16 @@
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Nonnull;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
Expand Down Expand Up @@ -58,11 +62,13 @@
import gregtech.api.recipe.check.CheckRecipeResult;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;
import gregtech.api.recipe.check.SimpleCheckRecipeResult;
import gregtech.api.util.GT_AssemblyLineUtils;
import gregtech.api.util.GT_LanguageManager;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.IGT_HatchAdder;
import gregtech.api.util.shutdown.ShutDownReason;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;

Expand All @@ -78,8 +84,9 @@ public class GT_MetaTileEntity_EM_research extends GT_MetaTileEntity_MultiblockB
// region variables
private final ArrayList<GT_MetaTileEntity_Hatch_Holder> eHolders = new ArrayList<>();
private GT_Recipe.GT_Recipe_AssemblyLine tRecipe;
private String machineType;
private static final String assembly = "Assembly line";
private static final String scanner = "Scanner";
private String machineType = assembly;
private ItemStack holdItem;
private long computationRemaining, computationRequired;

Expand Down Expand Up @@ -350,12 +357,44 @@ protected CheckRecipeResult checkProcessing_EM() {
if (!eHolders.isEmpty() && eHolders.get(0).mInventory[0] != null) {
holdItem = eHolders.get(0).mInventory[0].copy();
if (ItemList.Tool_DataStick.isStackEqual(controllerStack, false, true)) {
for (GT_Recipe.GT_Recipe_AssemblyLine assRecipe : TecTechRecipeMaps.researchableALRecipeList) {
if (GT_Utility.areStacksEqual(assRecipe.mResearchItem, holdItem, true)) {
machineType = assembly;
tRecipe = assRecipe;
// if found
if (iterateRecipes()) return SimpleCheckRecipeResult.ofSuccess("researching");
switch (machineType) {
case scanner -> {
for (GT_Recipe.GT_Recipe_AssemblyLine assRecipe : GT_Recipe.GT_Recipe_AssemblyLine.sAssemblylineRecipes) {
if (GT_Utility.areStacksEqual(assRecipe.mResearchItem, holdItem, true)) {
boolean failScanner = true;
for (GT_Recipe scannerRecipe : scannerFakeRecipes.getAllRecipes()) {
if (GT_Utility.areStacksEqual(scannerRecipe.mInputs[0], holdItem, true)) {
failScanner = false;
break;
}
}
if (failScanner) {
return SimpleCheckRecipeResult.ofFailure("wrongRequirements");
}
this.tRecipe = assRecipe;
// Scanner mode should consume item first
eHolders.get(0).mInventory[0] = null;
mInventory[1] = null;
// Set property
computationRequired = computationRemaining = assRecipe.mResearchTime;
mMaxProgresstime = 20;
mEfficiencyIncrease = 10000;
eRequiredData = 1;
eAmpereFlow = 1;
mEUt = -524288;
eHolders.get(0).getBaseMetaTileEntity().setActive(true);
return SimpleCheckRecipeResult.ofSuccess("scanning");
}
}
}
case assembly -> {
for (GT_Recipe.GT_Recipe_AssemblyLine assRecipe : TecTechRecipeMaps.researchableALRecipeList) {
if (GT_Utility.areStacksEqual(assRecipe.mResearchItem, holdItem, true)) {
tRecipe = assRecipe;
// if found
if (iterateRecipes()) return SimpleCheckRecipeResult.ofSuccess("researching");
}
}
}
}
} else {
Expand All @@ -373,18 +412,27 @@ protected CheckRecipeResult checkProcessing_EM() {
@Override
public void outputAfterRecipe_EM() {
if (!eHolders.isEmpty()) {
if (tRecipe != null && ItemList.Tool_DataStick.isStackEqual(mInventory[1], false, true)) {
eHolders.get(0).getBaseMetaTileEntity().setActive(false);
eHolders.get(0).mInventory[0] = null;
if (lServerNames == null) {
makeStick();
} else {
try {
makeStick2();
} catch (NoSuchFieldError e) {
makeStick();
switch (machineType) {
case assembly -> {
if (tRecipe != null && ItemList.Tool_DataStick.isStackEqual(mInventory[1], false, true)) {
eHolders.get(0).getBaseMetaTileEntity().setActive(false);
eHolders.get(0).mInventory[0] = null;
if (lServerNames == null) {
makeStick();
} else {
try {
makeStick2();
} catch (NoSuchFieldError e) {
makeStick();
}
}
}
}
case scanner -> {
mInventory[1] = ItemList.Tool_DataStick.get(1);
GT_AssemblyLineUtils.setAssemblyLineRecipeOnDataStick(mInventory[1], tRecipe);
eHolders.get(0).getBaseMetaTileEntity().setActive(false);
}
}
}
computationRequired = computationRemaining = 0;
Expand Down Expand Up @@ -551,6 +599,7 @@ public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setLong("eComputationRemaining", computationRemaining);
aNBT.setLong("eComputationRequired", computationRequired);
aNBT.setString("eMachineType", machineType);
if (holdItem != null) {
aNBT.setTag("eHold", holdItem.writeToNBT(new NBTTagCompound()));
} else {
Expand All @@ -563,6 +612,7 @@ public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
computationRemaining = aNBT.getLong("eComputationRemaining");
computationRequired = aNBT.getLong("eComputationRequired");
machineType = aNBT.hasKey("eMachineType") ? aNBT.getString("eMachineType") : assembly;
if (aNBT.hasKey("eHold")) {
holdItem = ItemStack.loadItemStackFromNBT(aNBT.getCompoundTag("eHold"));
} else {
Expand All @@ -571,8 +621,8 @@ public void loadNBTData(NBTTagCompound aNBT) {
}

@Override
public void stopMachine() {
super.stopMachine();
public void stopMachine(@Nonnull ShutDownReason reason) {
super.stopMachine(reason);
for (GT_MetaTileEntity_Hatch_Holder r : eHolders) {
r.getBaseMetaTileEntity().setActive(false);
}
Expand All @@ -591,7 +641,6 @@ public void onFirstTick_EM(IGregTechTileEntity aBaseMetaTileEntity) {
for (GT_Recipe.GT_Recipe_AssemblyLine tRecipe : TecTechRecipeMaps.researchableALRecipeList) {
if (GT_Utility.areStacksEqual(tRecipe.mResearchItem, holdItem, true)) {
this.tRecipe = tRecipe;
machineType = assembly;
break;
}
}
Expand Down Expand Up @@ -655,12 +704,25 @@ public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlaye
return true;
}

@Override
public final void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, float aX, float aY, float aZ) {
super.onScrewdriverRightClick(side, aPlayer, aX, aY, aZ);
switch (machineType) {
case scanner -> machineType = assembly;
case assembly -> machineType = scanner;
}
aPlayer.addChatComponentMessage(
new ChatComponentTranslation(
"gt.blockmachines.multimachine.em.research.mode." + machineType.replace(" ", "_")));
}

@Override
public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompound tag, World world, int x, int y,
int z) {
tag.setBoolean("hasProblems", (getIdealStatus() - getRepairStatus()) > 0);
tag.setFloat("efficiency", mEfficiency / 100.0F);
tag.setBoolean("incompleteStructure", (getBaseMetaTileEntity().getErrorDisplayID() & 64) != 0);
tag.setString("machineType", machineType);
tag.setLong("computation", (computationRequired - computationRemaining) / 20L);
tag.setLong("computationRequired", computationRequired / 20L);
}
Expand All @@ -678,7 +740,7 @@ public void getWailaBody(ItemStack itemStack, List<String> currentTip, IWailaDat
+ " Efficiency: "
+ tag.getFloat("efficiency")
+ "%");

currentTip.add("Mode: " + tag.getString("machineType"));
currentTip.add(
String.format(
"Computation: %,d / %,d",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.ArrayList;
import java.util.HashSet;

import javax.annotation.Nonnull;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
Expand Down Expand Up @@ -48,6 +50,7 @@
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.shutdown.ShutDownReason;

/**
* Created by danie_000 on 17.12.2016.
Expand Down Expand Up @@ -294,8 +297,8 @@ protected void parametersInstantiation_EM() {
}

@Override
public void stopMachine() {
super.stopMachine();
public void stopMachine(@Nonnull ShutDownReason reason) {
super.stopMachine(reason);
remainingTime.set(timerSetting.get());
timerValue.set(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import javax.annotation.Nonnull;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
Expand Down Expand Up @@ -108,6 +110,7 @@
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import gregtech.api.util.IGT_HatchAdder;
import gregtech.api.util.shutdown.ShutDownReason;
import gregtech.common.blocks.GT_Item_Machines;

public class GT_MetaTileEntity_TM_teslaCoil extends GT_MetaTileEntity_MultiblockBase_EM
Expand Down Expand Up @@ -810,8 +813,8 @@ public void loadNBTData(NBTTagCompound aNBT) {
}

@Override
public void stopMachine() {
super.stopMachine();
public void stopMachine(@Nonnull ShutDownReason reason) {
super.stopMachine(reason);
for (GT_MetaTileEntity_Hatch_Capacitor cap : eCapacitorHatches) {
cap.getBaseMetaTileEntity().setActive(false);
}
Expand Down
Loading