Skip to content

Commit

Permalink
Multi-Slot Hatches, Fixes (#667)
Browse files Browse the repository at this point in the history
* chore: bump version to 1.0.19

* refactor: extract tier ranges

* refactor: fluid hatch tank capacity in constructor

* refactor: remove redundant @Setter annotations in GTOreDefinition

* refactor: allow multiple slots in fluid hatches

* refactor: add back additional args to FluidHatchPartMachine hierarchy

Java limitation moment... Pain.

* docs: document why we actually need Object... args in the constructor

This is so cursed...

* feat: add 4x and 9x fluid hatches

* feat: textures for 4x and 9x fluid hatches

* chore: changelog

* fix: floating ore indicators

* feat(kjs): add miningToolTag API

* chore: run datagen

* style: reformat a part of GTItems

* fix: wrong background for fluid slots in multi-slot hatches

* chore: run datagen
  • Loading branch information
mikerooni authored Dec 31, 2023
1 parent e776203 commit b097f1e
Show file tree
Hide file tree
Showing 38 changed files with 663 additions and 161 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

Version: 1.0.19

- allow filling machines from EMI's recipe view
- add quadruple and nonuple fluid hatches
- add rock breaker recipes for basalt, blackstone and deepslate
- add compass pages for material items and improve layout
- allow filling machines from EMI's recipe view
- allow setting a mining tool tag for custom ores using KubeJS
- language fixes and improvements
- fix floating ore indicators being generated in certain situations
- fix connected textures for GCyM machines
- fix fluid pipes not selecting the best channel
- fix steam boilers not accepting creosote as a fuel
Expand Down
9 changes: 8 additions & 1 deletion common/src/main/java/com/gregtechceu/gtceu/api/GTValues.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.gregtechceu.gtceu.api;


import com.gregtechceu.gtceu.GTCEu;
import com.gregtechceu.gtceu.data.recipe.CraftingComponent;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.levelgen.LegacyRandomSource;
import net.minecraft.world.level.levelgen.SingleThreadedRandomSource;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Supplier;
Expand Down Expand Up @@ -90,7 +92,12 @@ public class GTValues {
public static final int OpV = 13;
public static final int MAX = 14;

public static final int TIER_COUNT = 15;
public static final int[] ALL_TIERS = new int[]{ULV, LV, MV, HV, EV, IV, LuV, ZPM, UV, UHV, UEV, UIV, UXV, OpV, MAX};
public static final int TIER_COUNT = ALL_TIERS.length;

public static int[] tiersBetween(int min, int max) {
return Arrays.stream(ALL_TIERS).dropWhile(tier -> tier < min).takeWhile(tier -> tier <= max).toArray();
}

public static final String
MODID_TOP = "theoneprobe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ public class GTOreDefinition {
private float density;
@Getter
private int weight;
@Getter @Setter
@Getter
private IWorldGenLayer layer;
@Getter @Setter
private Set<ResourceKey<Level>> dimensionFilter;
@Getter @Setter
private HeightRangePlacement range;
@Getter @Setter
private float discardChanceOnAirExposure;
@Getter @Setter
@Getter
private Supplier<HolderSet<Biome>> biomes;
@Getter @Setter
private BiomeWeightModifier biomeWeightModifier;

@Getter @Setter
@Getter
private VeinGenerator veinGenerator;

@Getter @Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ private OreIndicatorPlacer createPlacer(WorldGenLevel level, List<BlockPos> posi
if (!section.getBlockState(sectionX, sectionY, sectionZ).isAir())
return;

if (!blockState.canSurvive(level, pos))
return;

section.setBlockState(sectionX, sectionY, sectionZ, blockState, false);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ public static void generateMaterialItems() {
.color(() -> TagPrefixItem::tintColor)
.onRegister(GTItems::cauldronInteraction)
.onRegister(item -> {
switch(tagPrefix.name) {
case "buzzSawBlade", "screwDriverTip", "drillHead", "chainSawHead", "wrenchTip", "turbineBlade" -> CompassNode.getOrCreate(GTCompassSections.MATERIALS, "tool_heads").addItem(() -> item);
default ->
CompassNode.getOrCreate(GTCompassSections.MATERIALS, FormattingUtil.toLowerCaseUnderscore(tagPrefix.name))
.iconIfNull(() -> new ItemStackTexture(item)).addTag(tagPrefix.getItemParentTags());
}
})
switch (tagPrefix.name) {
case "buzzSawBlade", "screwDriverTip", "drillHead", "chainSawHead", "wrenchTip", "turbineBlade" ->
CompassNode.getOrCreate(GTCompassSections.MATERIALS, "tool_heads").addItem(() -> item);
default ->
CompassNode.getOrCreate(GTCompassSections.MATERIALS, FormattingUtil.toLowerCaseUnderscore(tagPrefix.name))
.iconIfNull(() -> new ItemStackTexture(item)).addTag(tagPrefix.getItemParentTags());
}
})
.register());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,18 @@
* @implNote GTMachines
*/
public class GTMachines {
public final static int[] ALL_TIERS = GTCEu.isHighTier() ?
new int[] {GTValues.ULV, GTValues.LV, GTValues.MV, GTValues.HV, GTValues.EV, GTValues.IV, GTValues.LuV, GTValues.ZPM, GTValues.UV, GTValues.UHV, GTValues.UEV, GTValues.UIV, GTValues.UXV, GTValues.OpV, GTValues.MAX} :
new int[] {GTValues.ULV, GTValues.LV, GTValues.MV, GTValues.HV, GTValues.EV, GTValues.IV, GTValues.LuV, GTValues.ZPM, GTValues.UV, GTValues.UHV};
public final static int[] ELECTRIC_TIERS = GTCEu.isHighTier() ?
new int[] {GTValues.LV, GTValues.MV, GTValues.HV, GTValues.EV, GTValues.IV, GTValues.LuV, GTValues.ZPM, GTValues.UV, GTValues.UHV, GTValues.UEV, GTValues.UIV, GTValues.UXV, GTValues.OpV} :
new int[] {GTValues.LV, GTValues.MV, GTValues.HV, GTValues.EV, GTValues.IV, GTValues.LuV, GTValues.ZPM, GTValues.UV};
public final static int[] LOW_TIERS = new int[] {GTValues.LV, GTValues.MV, GTValues.HV, GTValues.EV};
public final static int[] HIGH_TIERS = GTCEu.isHighTier() ?
new int[] {GTValues.IV, GTValues.LuV, GTValues.ZPM, GTValues.UV, GTValues.UHV, GTValues.UEV, GTValues.UIV, GTValues.UXV, GTValues.OpV} :
new int[] {GTValues.IV, GTValues.LuV, GTValues.ZPM, GTValues.UV, GTValues.UHV};
public final static int[] ALL_TIERS = GTValues.tiersBetween(ULV, GTCEu.isHighTier() ? MAX : UHV);
public final static int[] ELECTRIC_TIERS = GTValues.tiersBetween(LV, GTCEu.isHighTier() ? OpV : UV);
public final static int[] LOW_TIERS = GTValues.tiersBetween(LV, EV);
public final static int[] HIGH_TIERS = GTValues.tiersBetween(IV, GTCEu.isHighTier() ? OpV : UHV);
public final static int[] MULTI_HATCH_TIERS = GTValues.tiersBetween(EV, GTCEu.isHighTier() ? MAX : UHV);

public static final Int2LongFunction defaultTankSizeFunction = tier -> (tier <= GTValues.LV ? 8 : tier == GTValues.MV ? 12 : tier == GTValues.HV ? 16 : tier == GTValues.EV ? 32 : 64) * FluidHelper.getBucket();
public static final Int2LongFunction hvCappedTankSizeFunction = tier -> (tier <= GTValues.LV ? 8: tier == GTValues.MV ? 12 : 16) * FluidHelper.getBucket();
public static final Int2LongFunction largeTankSizeFunction = tier -> (tier <= GTValues.LV ? 32 : tier == GTValues.MV ? 48 : 64) * FluidHelper.getBucket();
public static final Int2LongFunction steamGeneratorTankSizeFunction = tier -> Math.min(16 * (1 << (tier - 1)), 64) * FluidHelper.getBucket();
public static final Int2LongFunction genericGeneratorTankSizeFunction = tier -> Math.min(4 * (1 << (tier - 1)), 16) * FluidHelper.getBucket();

public static Object2IntMap<MachineDefinition> DRUM_CAPACITY = new Object2IntArrayMap<>();

static {
Expand Down Expand Up @@ -496,31 +493,38 @@ public static BiConsumer<ItemStack, List<Component>> createTankTooltips(String n
.register(),
ALL_TIERS);

public final static MachineDefinition[] FLUID_IMPORT_HATCH = registerTieredMachines("input_hatch",
(holder, tier) -> new FluidHatchPartMachine(holder, tier, IO.IN),
(tier, builder) -> builder
.langValue(VNF[tier] + " Input Hatch")
.rotationState(RotationState.ALL)
.abilities(PartAbility.IMPORT_FLUIDS)
.overlayTieredHullRenderer("fluid_hatch.import")
.tooltips(Component.translatable("gtceu.machine.fluid_hatch.import.tooltip"),
Component.translatable("gtceu.universal.tooltip.fluid_storage_capacity", (8 * FluidHelper.getBucket()) * (1L << Math.min(9, tier))))
.compassNode("fluid_hatch")
.register(),
ALL_TIERS);

public final static MachineDefinition[] FLUID_EXPORT_HATCH = registerTieredMachines("output_hatch",
(holder, tier) -> new FluidHatchPartMachine(holder, tier, IO.OUT),
(tier, builder) -> builder
.langValue(VNF[tier] + " Output Hatch")
.rotationState(RotationState.ALL)
.abilities(PartAbility.EXPORT_FLUIDS)
.overlayTieredHullRenderer("fluid_hatch.export")
.tooltips(Component.translatable("gtceu.machine.fluid_hatch.export.tooltip"),
Component.translatable("gtceu.universal.tooltip.fluid_storage_capacity", (8 * FluidHelper.getBucket()) * (1L << Math.min(9, tier))))
.compassNode("fluid_hatch")
.register(),
ALL_TIERS);
public final static MachineDefinition[] FLUID_IMPORT_HATCH = registerFluidHatches(
"input_hatch", "Input Hatch", "fluid_hatch.import",
IO.IN, FluidHatchPartMachine.INITIAL_TANK_CAPACITY_1X, 1, ALL_TIERS
);

public final static MachineDefinition[] FLUID_IMPORT_HATCH_4X = registerFluidHatches(
"input_hatch_4x", "Quadruple Input Hatch", "fluid_hatch.import_4x",
IO.IN, FluidHatchPartMachine.INITIAL_TANK_CAPACITY_4X, 4, MULTI_HATCH_TIERS
);

public final static MachineDefinition[] FLUID_IMPORT_HATCH_9X = registerFluidHatches(
"input_hatch_9x", "Nonuple Input Hatch", "fluid_hatch.import_9x",
IO.IN, FluidHatchPartMachine.INITIAL_TANK_CAPACITY_9X, 9, MULTI_HATCH_TIERS
);


public final static MachineDefinition[] FLUID_EXPORT_HATCH = registerFluidHatches(
"output_hatch", " Output Hatch","fluid_hatch.export",
IO.OUT, FluidHatchPartMachine.INITIAL_TANK_CAPACITY_1X, 1, ALL_TIERS
);


public final static MachineDefinition[] FLUID_EXPORT_HATCH_4X = registerFluidHatches(
"output_hatch_4x", "Quadruple Output Hatch", "fluid_hatch.export_4x",
IO.OUT, FluidHatchPartMachine.INITIAL_TANK_CAPACITY_4X, 4, MULTI_HATCH_TIERS
);

public final static MachineDefinition[] FLUID_EXPORT_HATCH_9X = registerFluidHatches(
"output_hatch_9x", "Nonuple Output Hatch", "fluid_hatch.export_9x",
IO.OUT, FluidHatchPartMachine.INITIAL_TANK_CAPACITY_9X, 9, MULTI_HATCH_TIERS
);

public final static MachineDefinition[] ENERGY_INPUT_HATCH = registerTieredMachines("energy_input_hatch",
(holder, tier) -> new EnergyHatchPartMachine(holder, tier, IO.IN, 2),
Expand Down Expand Up @@ -730,7 +734,7 @@ public static BiConsumer<ItemStack, List<Component>> createTankTooltips(String n
ELECTRIC_TIERS);

public static final MachineDefinition[] FLUID_PASSTHROUGH_HATCH = registerTieredMachines("fluid_passthrough_hatch",
(holder, tier) -> new FluidHatchPartMachine(holder, tier, IO.BOTH),
(holder, tier) -> new FluidHatchPartMachine(holder, tier, IO.BOTH, FluidHatchPartMachine.INITIAL_TANK_CAPACITY_1X, 1),
(tier, builder) -> builder
.langValue("%s Fluid Passthrough Hatch".formatted(VNF[tier]))
.rotationState(RotationState.ALL)
Expand Down Expand Up @@ -1604,6 +1608,28 @@ public static MachineDefinition[] registerTieredMachines(String name,
return definitions;
}

private static MachineDefinition[] registerFluidHatches(String name, String displayname, String model, IO io, long initialCapacity, int slots, int[] tiers) {
return registerTieredMachines(name,
(holder, tier) -> new FluidHatchPartMachine(holder, tier, io, initialCapacity, slots),
(tier, builder) -> {
builder.langValue(VNF[tier] + ' ' + displayname)
.rotationState(RotationState.ALL)
.abilities(PartAbility.IMPORT_FLUIDS)
.overlayTieredHullRenderer(model)
.compassNode("fluid_hatch")
.tooltips(Component.translatable("gtceu.machine.fluid_hatch.import.tooltip"));

if (slots == 1) {
builder.tooltips(Component.translatable("gtceu.universal.tooltip.fluid_storage_capacity", FluidHatchPartMachine.getTankCapacity(initialCapacity, tier)));
} else {
builder.tooltips(Component.translatable("gtceu.universal.tooltip.fluid_storage_capacity_mult", slots, FluidHatchPartMachine.getTankCapacity(initialCapacity, tier)));
}

return builder.register();
},
tiers);
}

public static MachineDefinition[] registerTransformerMachines(String langName, int baseAmp) {
return registerTieredMachines("transformer_%da".formatted(baseAmp), (holder, tier) -> new TransformerMachine(holder, tier, baseAmp),
(tier, builder) -> builder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.gregtechceu.gtceu.common.machine.multiblock.part;

import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.multiblock.part.TieredIOPartMachine;
import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.TickableSubscription;
import com.gregtechceu.gtceu.api.machine.multiblock.part.TieredIOPartMachine;
import com.gregtechceu.gtceu.api.machine.trait.NotifiableFluidTank;
import com.lowdragmc.lowdraglib.gui.widget.*;
import com.lowdragmc.lowdraglib.side.fluid.FluidHelper;
Expand Down Expand Up @@ -32,17 +32,25 @@
public class FluidHatchPartMachine extends TieredIOPartMachine {

protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(FluidHatchPartMachine.class, TieredIOPartMachine.MANAGED_FIELD_HOLDER);
private static final long INITIAL_TANK_CAPACITY = 8 * FluidHelper.getBucket();

public static final long INITIAL_TANK_CAPACITY_1X = 8 * FluidHelper.getBucket();
public static final long INITIAL_TANK_CAPACITY_4X = 2 * FluidHelper.getBucket();
public static final long INITIAL_TANK_CAPACITY_9X = FluidHelper.getBucket();

@Persisted
public final NotifiableFluidTank tank;
private final int slots;
@Nullable
protected TickableSubscription autoIOSubs;
@Nullable
protected ISubscription tankSubs;

public FluidHatchPartMachine(IMachineBlockEntity holder, int tier, IO io, Object... args) {
// The `Object... args` parameter is necessary in case a superclass needs to pass any args along to createTank().
// We can't use fields here because those won't be available while createTank() is called.
public FluidHatchPartMachine(IMachineBlockEntity holder, int tier, IO io, long initialCapacity, int slots, Object... args) {
super(holder, tier, io);
this.tank = createTank(args);
this.slots = slots;
this.tank = createTank(initialCapacity, slots, args);
}

//////////////////////////////////////
Expand All @@ -53,12 +61,12 @@ public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}

protected long getTankCapacity() {
return INITIAL_TANK_CAPACITY * (1L << Math.min(9, getTier()));
protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) {
return new NotifiableFluidTank(this, slots, getTankCapacity(initialCapacity, getTier()), io);
}

protected NotifiableFluidTank createTank(Object... args) {
return new NotifiableFluidTank(this, 1, getTankCapacity(), io);
public static long getTankCapacity(long initialCapacity, int tier) {
return initialCapacity * (1L << Math.min(9, tier));
}

@Override
Expand Down Expand Up @@ -129,13 +137,47 @@ public void setWorkingEnabled(boolean workingEnabled) {
//////////////////////////////////////
@Override
public Widget createUIWidget() {

if (slots == 1) {
return createSingleSlotGUI();
} else {
return createMultiSlotGUI();
}
}

protected Widget createSingleSlotGUI() {
var group = new WidgetGroup(0, 0, 89, 63);

group.addWidget(new ImageWidget(4, 4, 81, 55, GuiTextures.DISPLAY))
.addWidget(new LabelWidget(8, 8, "gtceu.gui.fluid_amount"))
.addWidget(new LabelWidget(8, 18, () -> String.valueOf(tank.getFluidInTank(0).getAmount())).setTextColor(-1).setDropShadow(true))
.addWidget(new TankWidget(tank.storages[0], 67, 22, true, io.support(IO.IN))
.setBackground(GuiTextures.FLUID_SLOT));
.addWidget(new TankWidget(tank.storages[0], 67, 22, true, io.support(IO.IN)).setBackground(GuiTextures.FLUID_SLOT));

group.setBackground(GuiTextures.BACKGROUND_INVERSE);
return group;
}

protected Widget createMultiSlotGUI() {
int rowSize = (int) Math.sqrt(slots);
int colSize = rowSize;
if (slots == 8) {
rowSize = 4;
colSize = 2;
}

var group = new WidgetGroup(0, 0, 18 * rowSize + 16, 18 * colSize + 16);
var container = new WidgetGroup(4, 4, 18 * rowSize + 8, 18 * colSize + 8);

int index = 0;
for (int y = 0; y < colSize; y++) {
for (int x = 0; x < rowSize; x++) {
container.addWidget(new TankWidget(tank.storages[index++], 4 + x * 18, 4 + y * 18, true, io.support(IO.IN)).setBackground(GuiTextures.FLUID_SLOT));
}
}

container.setBackground(GuiTextures.BACKGROUND_INVERSE);
group.addWidget(container);

return group;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,12 @@
public class PumpHatchPartMachine extends FluidHatchPartMachine {

public PumpHatchPartMachine(IMachineBlockEntity holder, Object... args) {
super(holder, 0, IO.OUT, args);
super(holder, 0, IO.OUT, FluidHelper.getBucket(), 1, args);
}

@Override
protected NotifiableFluidTank createTank(Object... args) {
return super.createTank(args).setFilter(fluidStack -> fluidStack.getFluid() == GTMaterials.Water.getFluid());
}

@Override
protected long getTankCapacity() {
return FluidHelper.getBucket();
protected NotifiableFluidTank createTank(long initialCapacity, int slots, Object... args) {
return super.createTank(initialCapacity, slots).setFilter(fluidStack -> fluidStack.getFluid() == GTMaterials.Water.getFluid());
}

@Override
Expand Down
Loading

0 comments on commit b097f1e

Please sign in to comment.