Skip to content

Commit

Permalink
fix miscellaneous issues with research (#1076)
Browse files Browse the repository at this point in the history
* fix coil machine OC not applying correctly when using multi amp hatches

* fix HPCA part rendering

* fix CWU text being slightly offset

* try to fix ore pages moving around by using a LinkedHashMap for order.

* fix JEI crash that can happen with invalid ingredients.

* fix HPCA part inventory render
  • Loading branch information
screret authored Apr 8, 2024
1 parent da68cb4 commit 79681ad
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public Integer copyWithModifier(Integer content, ContentModifier modifier) {
}

@Override
public void addXEIInfo(WidgetGroup group, List<Content> contents, boolean perTick, boolean isInput, MutableInt yOffset) {
public void addXEIInfo(WidgetGroup group, int xOffset, List<Content> contents, boolean perTick, boolean isInput, MutableInt yOffset) {
if (perTick && isInput) {
int cwu = contents.stream().map(Content::getContent).mapToInt(CWURecipeCapability.CAP::of).sum();
group.addWidget(new LabelWidget(3, yOffset.addAndGet(10), LocalizationUtils.format("gtceu.recipe.computation_per_tick", cwu)));
group.addWidget(new LabelWidget(3 - xOffset, yOffset.getAndAdd(10), LocalizationUtils.format("gtceu.recipe.computation_per_tick", cwu)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean doAddGuiSlots() {
return isRecipeSearchFilter();
}

public void addXEIInfo(WidgetGroup group, List<Content> contents, boolean perTick, boolean isInput, MutableInt yOffset) {
public void addXEIInfo(WidgetGroup group, int xOffset, List<Content> contents, boolean perTick, boolean isInput, MutableInt yOffset) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.mojang.serialization.DataResult;
import it.unimi.dsi.fastutil.objects.Object2FloatMap;
import it.unimi.dsi.fastutil.objects.Object2FloatOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
Expand Down Expand Up @@ -62,7 +63,7 @@
public class TagPrefix {

public final static Map<String, TagPrefix> PREFIXES = new HashMap<>();
public static final Map<TagPrefix, OreType> ORES = new IdentityHashMap<>();
public static final Map<TagPrefix, OreType> ORES = new Object2ObjectLinkedOpenHashMap<>();

public static final Codec<TagPrefix> CODEC = Codec.STRING.flatXmap(str -> Optional.ofNullable(get(str)).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "invalid TagPrefix: " + str)), prefix -> DataResult.success(prefix.name));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,23 @@ public HPCAPartRenderer(boolean isAdvanced, ResourceLocation texture, ResourceLo
this.damagedActiveEmissiveTexture = damagedActiveTexture.withSuffix("_emissive");
}

public HPCAPartRenderer(boolean isAdvanced,
ResourceLocation texture,
@Nullable ResourceLocation activeTexture,
@Nullable ResourceLocation activeEmissiveTexture,
@Nullable ResourceLocation damagedTexture,
@Nullable ResourceLocation damagedActiveTexture,
@Nullable ResourceLocation damagedActiveEmissiveTexture) {
super(GTValues.ZPM, isAdvanced ? GTCEu.id("block/computer_casing") : GTCEu.id("block/advanced_computer_casing"));
this.isAdvanced = isAdvanced;
this.texture = texture;
this.activeTexture = activeTexture;
this.activeEmissiveTexture = activeEmissiveTexture;
this.damagedTexture = damagedTexture;
this.damagedActiveTexture = damagedActiveTexture;
this.damagedActiveEmissiveTexture = damagedActiveEmissiveTexture;
}

@Override
public void renderMachine(List<BakedQuad> quads, MachineDefinition definition, @Nullable MetaMachine machine, Direction frontFacing, @Nullable Direction side, RandomSource rand, @Nullable Direction modelFacing, ModelState modelState) {
super.renderMachine(quads, definition, machine, frontFacing, side, rand, modelFacing, modelState);
Expand All @@ -61,23 +78,26 @@ public void renderMachine(List<BakedQuad> quads, MachineDefinition definition, @
texture = this.texture;
}
}
if (ModelFactory.getBlockSprite(texture).atlasLocation().equals(MissingTextureAtlasSprite.getLocation())) {
if (texture == null) {
texture = this.texture;
}
if (texture != null && !ModelFactory.getBlockSprite(texture).atlasLocation().equals(MissingTextureAtlasSprite.getLocation())) {
if (side == frontFacing) {
Direction facing = frontFacing;
// Always render this outwards in the HPCA, in case it is not placed outwards in structure.
// Check for HPCA specifically since these components could potentially be used in other multiblocks.
if (controller instanceof HPCAMachine hpca) {
facing = RelativeDirection.RIGHT.getRelativeFacing(hpca.getFrontFacing(), Direction.NORTH, false);
}
facing = ModelFactory.modelFacing(side, facing);
quads.add(FaceQuad.bakeFace(FaceQuad.BLOCK, facing, ModelFactory.getBlockSprite(texture), modelState, -1, 0, true, true));
if (emissiveTexture != null && !ModelFactory.getBlockSprite(emissiveTexture).atlasLocation().equals(MissingTextureAtlasSprite.getLocation())) {
quads.add(FaceQuad.bakeFace(FaceQuad.BLOCK, facing, ModelFactory.getBlockSprite(emissiveTexture), modelState, -101, 15, true, false));
}
if (texture != null) {
Direction facing = frontFacing;
// Always render this outwards in the HPCA, in case it is not placed outwards in structure.
// Check for HPCA specifically since these components could potentially be used in other multiblocks.
if (controller instanceof HPCAMachine hpca) {
facing = RelativeDirection.RIGHT.getRelativeFacing(hpca.getFrontFacing(), Direction.NORTH, false);
}
facing = ModelFactory.modelFacing(frontFacing, facing);
quads.add(FaceQuad.bakeFace(FaceQuad.BLOCK, facing, ModelFactory.getBlockSprite(texture), modelState, -1, 0, true, true));
if (emissiveTexture != null) {
quads.add(FaceQuad.bakeFace(FaceQuad.BLOCK, facing, ModelFactory.getBlockSprite(emissiveTexture), modelState, -101, 15, true, false));
}
}
} else {
ResourceLocation texture = this.texture;
if (texture != null) {
quads.add(FaceQuad.bakeFace(FaceQuad.BLOCK, Direction.NORTH, ModelFactory.getBlockSprite(texture), modelState, -1, 0, true, true));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static GTRecipe crackerOverclock(MetaMachine machine, @NotNull GTRecipe r
pair.first((long) Math.max(1, eu));
}
return pair;
}), recipe, coilMachine.getMaxVoltage());
}), recipe, coilMachine.getOverclockVoltage());
}
return null;
}
Expand All @@ -153,7 +153,7 @@ public static GTRecipe ebfOverclock(MetaMachine machine, @NotNull GTRecipe recip
amountOC,
blastFurnaceTemperature,
recipe.data.contains("ebf_temp") ? recipe.data.getInt("ebf_temp") : 0
)), recipe, coilMachine.getMaxVoltage());
)), recipe, coilMachine.getOverclockVoltage());
}
return null;
}
Expand All @@ -172,7 +172,7 @@ public static GTRecipe pyrolyseOvenOverclock(MetaMachine machine, @NotNull GTRec
}
pair.second(Math.max(1, pair.secondInt()));
return pair;
}), recipe, coilMachine.getMaxVoltage());
}), recipe, coilMachine.getOverclockVoltage());
}
return null;
}
Expand All @@ -181,7 +181,7 @@ public static GTRecipe multiSmelterOverclock(MetaMachine machine, @NotNull GTRec
if (machine instanceof CoilWorkableElectricMultiblockMachine coilMachine) {
var energyCost = Math.max(1L, 16 / coilMachine.getCoilType().getEnergyDiscount());
var maxParallel = 32 * coilMachine.getCoilType().getLevel();
var parallelLimit = Math.min(maxParallel, (int) (coilMachine.getMaxVoltage() / energyCost));
var parallelLimit = Math.min(maxParallel, (int) (coilMachine.getOverclockVoltage() / energyCost));

var result = GTRecipeModifiers.accurateParallel(machine, recipe, parallelLimit, false);
recipe = result.getA() == recipe ? result.getA().copy() : result.getA();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import com.gregtechceu.gtceu.utils.FormattingUtil;
import net.minecraft.core.Direction;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -350,7 +352,7 @@ public class GTResearchMachines {

public static final MachineDefinition HPCA_EMPTY_COMPONENT = registerHPCAPart(
"hpca_empty_component", "Empty HPCA Component",
HPCAEmptyPartMachine::new, "empty", false
HPCAEmptyPartMachine::new, "empty", null, null, false
).register();
public static final MachineDefinition HPCA_COMPUTATION_COMPONENT = registerHPCAPart(
"hpca_computation_component", "HPCA Computation Component",
Expand All @@ -372,7 +374,7 @@ public class GTResearchMachines {
.register();
public static final MachineDefinition HPCA_HEAT_SINK_COMPONENT = registerHPCAPart(
"hpca_heat_sink_component", "HPCA Heat Sink Component",
holder -> new HPCACoolerPartMachine(holder, false), "heat_sink", false
holder -> new HPCACoolerPartMachine(holder, false), "heat_sink", null, null, false
).tooltips(Component.translatable("gtceu.machine.hpca.component_type.cooler_passive"),
Component.translatable("gtceu.machine.hpca.component_type.cooler_cooling", 1))
.register();
Expand Down Expand Up @@ -415,6 +417,29 @@ private static MachineBuilder<MachineDefinition> registerHPCAPart(String name, S
));
}

@SuppressWarnings("SameParameterValue")
private static MachineBuilder<MachineDefinition> registerHPCAPart(String name,
String displayName,
Function<IMachineBlockEntity, MetaMachine> constructor,
String texture,
@Nullable String activeTexture,
@Nullable String damagedTexture,
boolean isAdvanced) {
return REGISTRATE.machine(name, constructor)
.langValue(displayName)
.rotationState(RotationState.ALL)
.abilities(PartAbility.HPCA_COMPONENT)
.renderer(() -> new HPCAPartRenderer(
isAdvanced,
GTCEu.id("block/overlay/machine/hpca/" + texture),
activeTexture == null ? null : GTCEu.id("block/overlay/machine/hpca/" + activeTexture),
activeTexture == null ? null : GTCEu.id("block/overlay/machine/hpca/" + activeTexture + "_emissive"),
damagedTexture == null ? null : GTCEu.id("block/overlay/machine/hpca/" + damagedTexture),
damagedTexture == null ? null : GTCEu.id("block/overlay/machine/hpca/" + damagedTexture + "_active"),
damagedTexture == null ? null : GTCEu.id("block/overlay/machine/hpca/" + damagedTexture + "_emissive")
));
}

public static void init() {

}
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/gregtechceu/gtceu/integration/GTRecipeWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public class GTRecipeWidget extends WidgetGroup {
private LabelWidget voltageTextWidget;

public GTRecipeWidget(GTRecipe recipe) {
super(getXOffSet(recipe), 0, recipe.recipeType.getRecipeUI().getJEISize().width, recipe.recipeType.getRecipeUI().getJEISize().height);
super(getXOffset(recipe), 0, recipe.recipeType.getRecipeUI().getJEISize().width, recipe.recipeType.getRecipeUI().getJEISize().height);
this.recipe = recipe;
this.xOffset = getXOffSet(recipe);
this.xOffset = getXOffset(recipe);
setRecipeWidget();
setTierToMin();
initializeRecipeTextWidget();
addButtons();
}

private static int getXOffSet(GTRecipe recipe) {
private static int getXOffset(GTRecipe recipe) {
if (recipe.recipeType.getRecipeUI().getOriginalWidth() != recipe.recipeType.getRecipeUI().getJEISize().width) {
return (recipe.recipeType.getRecipeUI().getJEISize().width - recipe.recipeType.getRecipeUI().getOriginalWidth()) / 2;
}
Expand Down Expand Up @@ -247,16 +247,16 @@ private void setRecipeWidget() {
/// add text based on i/o's
MutableInt yOff = new MutableInt(yOffset);
for (var capability : recipe.inputs.entrySet()) {
capability.getKey().addXEIInfo(this, capability.getValue(), false, true, yOff);
capability.getKey().addXEIInfo(this, xOffset, capability.getValue(), false, true, yOff);
}
for (var capability : recipe.tickInputs.entrySet()) {
capability.getKey().addXEIInfo(this, capability.getValue(), true, true, yOff);
capability.getKey().addXEIInfo(this, xOffset, capability.getValue(), true, true, yOff);
}
for (var capability : recipe.outputs.entrySet()) {
capability.getKey().addXEIInfo(this, capability.getValue(), false, false, yOff);
capability.getKey().addXEIInfo(this, xOffset, capability.getValue(), false, false, yOff);
}
for (var capability : recipe.tickOutputs.entrySet()) {
capability.getKey().addXEIInfo(this, capability.getValue(), true, false, yOff);
capability.getKey().addXEIInfo(this, xOffset, capability.getValue(), true, false, yOff);
}

yOffset = yOff.getValue();
Expand Down Expand Up @@ -420,9 +420,7 @@ private void setTierToMin() {
private static Either<List<Pair<TagKey<Item>, Integer>>, List<ItemStack>> mapItem(Ingredient ingredient) {
if (ingredient instanceof SizedIngredient sizedIngredient) {
final int amount = sizedIngredient.getAmount();
if (((IngredientAccessor)sizedIngredient.getInner()).getValues()[0] instanceof Ingredient.TagValue tagValue) {
return Either.left(List.of(Pair.of(((TagValueAccessor)tagValue).getTag(), amount)));
} else if (sizedIngredient.getInner() instanceof IntersectionIngredient intersection) {
if (sizedIngredient.getInner() instanceof IntersectionIngredient intersection) {
List<Ingredient> children = ((IntersectionIngredientAccessor)intersection).getChildren();
if (children.isEmpty()) {
return Either.right(null);
Expand Down Expand Up @@ -460,6 +458,8 @@ private static Either<List<Pair<TagKey<Item>, Integer>>, List<ItemStack>> mapIte
}
return items;
}));
} else if (((IngredientAccessor)sizedIngredient.getInner()).getValues().length > 0 && ((IngredientAccessor)sizedIngredient.getInner()).getValues()[0] instanceof Ingredient.TagValue tagValue) {
return Either.left(List.of(Pair.of(((TagValueAccessor)tagValue).getTag(), amount)));
}
} else if (ingredient instanceof IntersectionIngredient intersection) {
// Map intersection ingredients to the items inside, as recipe viewers don't support them.
Expand Down

0 comments on commit 79681ad

Please sign in to comment.