Skip to content

Commit

Permalink
initial steam support
Browse files Browse the repository at this point in the history
  • Loading branch information
PrototypeTrousers committed Mar 15, 2021
1 parent 636815b commit 3d8e3ef
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 16 deletions.
54 changes: 54 additions & 0 deletions src/main/java/gregtech/api/capability/impl/RecipeLogicSteam.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gregtech.api.capability.impl;

import gregtech.api.GTValues;
import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.damagesources.DamageSources;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.recipes.Recipe;
Expand All @@ -9,6 +10,7 @@
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.EntitySelectors;
Expand All @@ -18,7 +20,13 @@
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.items.IItemHandler;

import java.util.Arrays;

import static gregtech.api.situation.Situations.*;

public class RecipeLogicSteam extends AbstractRecipeLogic {

Expand Down Expand Up @@ -143,10 +151,56 @@ public void update() {
return;
if (this.needsVenting && metaTileEntity.getTimer() % 10 == 0) {
tryDoVenting();
if (isVentingStuck()){
metaTileEntity.setSituation(BLOCKED_VENT);
}
}
super.update();
}

protected boolean checkRecipeInputsDirty(IItemHandler inputs, IMultipleTankHandler fluidInputs) {
boolean shouldRecheckRecipe = false;
this.isInputsEmpty = true;
if (lastItemInputs == null || lastItemInputs.length != inputs.getSlots()) {
this.lastItemInputs = new ItemStack[inputs.getSlots()];
Arrays.fill(lastItemInputs, ItemStack.EMPTY);
}
if (lastFluidInputs == null || lastFluidInputs.length != fluidInputs.getTanks()) {
this.lastFluidInputs = new FluidStack[fluidInputs.getTanks()];
}
for (int i = 0; i < lastItemInputs.length; i++) {
ItemStack currentStack = inputs.getStackInSlot(i);
ItemStack lastStack = lastItemInputs[i];
if (!areItemStacksEqual(currentStack, lastStack)) {
this.lastItemInputs[i] = currentStack.isEmpty() ? ItemStack.EMPTY : currentStack.copy();
shouldRecheckRecipe = true;
} else if (currentStack.getCount() != lastStack.getCount()) {
lastStack.setCount(currentStack.getCount());
shouldRecheckRecipe = true;
} else if (!currentStack.isEmpty()) {
this.isInputsEmpty = false;
}
}
for (int i = 0; i < lastFluidInputs.length; i++) {
if (fluidInputs.getTankAt(i) == steamFluidTank)
continue;
FluidStack currentStack = fluidInputs.getTankAt(i).getFluid();
FluidStack lastStack = lastFluidInputs[i];
if ((currentStack == null && lastStack != null) ||
(currentStack != null && !currentStack.isFluidEqual(lastStack))) {
this.lastFluidInputs[i] = currentStack == null ? null : currentStack.copy();
shouldRecheckRecipe = true;
} else if (currentStack != null && lastStack != null &&
currentStack.amount != lastStack.amount) {
lastStack.amount = currentStack.amount;
shouldRecheckRecipe = true;
} else if (currentStack != null) {
this.isInputsEmpty = false;
}
}
return shouldRecheckRecipe;
}

@Override
protected boolean setupAndConsumeRecipeInputs(Recipe recipe) {
return !this.needsVenting && super.setupAndConsumeRecipeInputs(recipe);
Expand Down
77 changes: 75 additions & 2 deletions src/main/java/gregtech/api/gui/widgets/SituationWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
public class SituationWidget extends Widget {

private final Supplier<Situation> currentSituationSupplier;
private boolean isHighPressure = false;
private boolean steam = false;
private Situation currentSituation;
protected String tooltipHoverString;
protected int currentId;
Expand All @@ -31,22 +33,93 @@ public <T extends Situation> SituationWidget(int xPosition, int yPosition, int w
setImage();
}

public SituationWidget(int xPosition, int yPosition, int width, int height, Supplier<Situation> getSituation, boolean isHighPressure) {
super(new Position(xPosition, yPosition), new Size(width, height));
this.steam = true;
this.isHighPressure = isHighPressure;
this.currentSituationSupplier = getSituation;
this.currentSituation = getSituation.get();
setTooltipHoverString();
setImage();
}

public void setTooltipHoverString() {
if (this.currentSituation != null) {
this.tooltipHoverString = I18n.format(this.currentSituation.situationLocaleName);
String situationLocaleName = this.currentSituation.situationLocaleName;
if (steam && situationLocaleName.contains("_power_")) {
situationLocaleName = situationLocaleName.replace("_power_","_steam_");
}
this.tooltipHoverString = I18n.format(situationLocaleName);
} else {
this.tooltipHoverString = null;
}
}

public SituationWidget setImage() {
if (this.currentSituation == null) {
this.area = null;
return this;
}
if (isHighPressure)
setImageSteamHighPressure();
else if (steam)
setImageSteam();
else {
setImageElectric();
}
return this;
}

public SituationWidget setImageSteamHighPressure() {
SituationTypes iconTextures = this.currentSituation.situationTypes;
switch (iconTextures) {
case INFO:
this.area = GuiTextures.STATUS_IDLING;
break;
case WORKING:
this.area = GuiTextures.STATUS_WORKING;
break;
case WARNING:
this.area = GuiTextures.STATUS_WARNING;
break;
case ERROR:
this.area = GuiTextures.STATUS_ERROR;
break;
default:
this.area = null;
}
return this;
}

public SituationWidget setImageSteam() {
SituationTypes iconTextures = this.currentSituation.situationTypes;
switch (iconTextures) {
case INFO:
this.area = GuiTextures.STATUS_IDLING;
break;
case WORKING:
this.area = GuiTextures.STATUS_WORKING;
break;
case WARNING:
this.area = GuiTextures.STATUS_WARNING;
break;
case ERROR:
this.area = GuiTextures.STATUS_ERROR;
break;
default:
this.area = null;
}
return this;
}

public SituationWidget setImageElectric() {
if (this.currentSituation == null) {
this.area = null;
return this;
}
SituationTypes iconTextures = this.currentSituation.situationTypes;
switch (iconTextures) {
case IDLE:
case INFO:
this.area = GuiTextures.STATUS_IDLING;
break;
case WORKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import gregtech.api.capability.impl.RecipeLogicSteam;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.gui.widgets.ImageWidget;
import gregtech.api.gui.widgets.LabelWidget;
import gregtech.api.gui.widgets.SituationWidget;
import gregtech.api.recipes.ModHandler;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.render.OrientedOverlayRenderer;
Expand Down Expand Up @@ -116,8 +116,7 @@ protected TextureArea getFullGuiTexture(String pathTemplate) {
public ModularUI.Builder createUITemplate(EntityPlayer player) {
return ModularUI.builder(BRONZE_BACKGROUND_TEXTURE, 176, 166)
.widget(new LabelWidget(6, 6, getMetaFullName()))
.widget(new ImageWidget(79, 42, 18, 18, getFullGuiTexture("not_enough_steam_%s"))
.setPredicate(() -> workableHandler.isHasNotEnoughEnergy()))
.widget(new SituationWidget(79,42,18,18,this::getSituation, isHighPressure))
.bindPlayerInventory(player.inventory, BRONZE_SLOT_BACKGROUND_TEXTURE);
}
}
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/situation/SituationTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public enum SituationTypes implements IStringSerializable {
WORKING("gregtech.situation.level.warning"),
IDLE("gregtech.situation.level.idle"),
INFO("gregtech.situation.level.idle"),
ERROR("gregtech.situation.level.error"),
WARNING("gregtech.situation.level.warning");

Expand Down
22 changes: 12 additions & 10 deletions src/main/java/gregtech/api/situation/Situations.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
public class Situations {
public static Situation WORKING = new Situation(1, "working", SituationTypes.WORKING);

public static Situation IDLE = new Situation(2, "idle", SituationTypes.IDLE);
public static Situation DISABLED_BY_CONTROLLER = new Situation(3, "disabled_by_controller", SituationTypes.IDLE);
public static Situation IDLE = new Situation(2, "idle", SituationTypes.INFO);
public static Situation DISABLED_BY_CONTROLLER = new Situation(3, "disabled_by_controller", SituationTypes.INFO);

public static Situation EMPTY_SOURCE = new Situation(100, "empty_source", SituationTypes.WARNING);
public static Situation INSUFFICIENT_POWER = new Situation(101, "insufficient_power", SituationTypes.WARNING);
Expand All @@ -17,14 +17,16 @@ public class Situations {
public static Situation OUTPUT_INVENTORY_FULL = new Situation(106, "output_inventory_full", SituationTypes.WARNING);
public static Situation TARGET_INVENTORY_FULL = new Situation(107, "target_inventory_full", SituationTypes.WARNING);

public static Situation NO_IMPORT_INVENTORY = new Situation(201, "no_import_inventory", SituationTypes.ERROR);
public static Situation NO_EXPORT_INVENTORY = new Situation(202, "no_export_inventory", SituationTypes.ERROR);
public static Situation NO_IMPORT_TANK = new Situation(203, "no_import_tank", SituationTypes.ERROR);
public static Situation NO_EXPORT_TANK = new Situation(204, "no_export_tank", SituationTypes.ERROR);
public static Situation EXPECTED_CAPABILITY_UNAVAILABLE = new Situation(205, "null_capability", SituationTypes.ERROR);
public static Situation WATER_CHECK_FAILED = new Situation(206, "water_check_failed", SituationTypes.ERROR);
public static Situation BLOCKED_INTAKES = new Situation(207, "blocked_intakes", SituationTypes.ERROR);
public static Situation DIMENSION_LACKS_ATMOSPHERE = new Situation(208, "dimension_lacks_atmosphere", SituationTypes.ERROR);
public static Situation NO_IMPORT_INVENTORY = new Situation(1001, "no_import_inventory", SituationTypes.ERROR);
public static Situation NO_EXPORT_INVENTORY = new Situation(1002, "no_export_inventory", SituationTypes.ERROR);
public static Situation NO_IMPORT_TANK = new Situation(1003, "no_import_tank", SituationTypes.ERROR);
public static Situation NO_EXPORT_TANK = new Situation(1004, "no_export_tank", SituationTypes.ERROR);
public static Situation EXPECTED_CAPABILITY_UNAVAILABLE = new Situation(1005, "null_capability", SituationTypes.ERROR);
public static Situation WATER_CHECK_FAILED = new Situation(1006, "water_check_failed", SituationTypes.ERROR);
public static Situation BLOCKED_INTAKES = new Situation(1007, "blocked_intakes", SituationTypes.ERROR);
public static Situation BLOCKED_VENT = new Situation(1008, "blocked_vent", SituationTypes.ERROR);
public static Situation DIMENSION_LACKS_ATMOSPHERE = new Situation(1009, "dimension_lacks_atmosphere", SituationTypes.ERROR);


public static void init() {
GTLog.logger.info("Registering situations...");
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@ gregtech.situation.null_capability=Error accessing inventory from this side
gregtech.situation.empty_source=This inventory is empty
gregtech.situation.insufficient_power=Not enough power to run this recipe
gregtech.situation.insufficient_power_to_start=Not enough power to start this recipe
gregtech.situation.insufficient_steam=Not enough steam to run this recipe
gregtech.situation.insufficient_steam_to_start=Not enough steam to start this recipe
gregtech.situation.no_matching_recipe=No recipe found
gregtech.situation.target_inventory_full=The target inventory is full
gregtech.situation.output_slots_full=Output slots are full
Expand All @@ -778,6 +780,7 @@ gregtech.situation.no_export_inventory=Cant access inventory to export to
gregtech.situation.no_import_tank=Cant access tank to import from
gregtech.situation.no_export_tank=Cant access tank to export to
gregtech.situation.blocked_intakes=Blocked intakes
gregtech.situation.blocked_vent=Blocked vent
gregtech.situation.dimension_lacks_atmosphere=Dimension lacks atmosphere

# %s is a localized material name
Expand Down

0 comments on commit 3d8e3ef

Please sign in to comment.