Skip to content

Commit

Permalink
Allow the PRASS to use all 5 casings yet and improve its JEI preview (#…
Browse files Browse the repository at this point in the history
…11)

* Use all 5 casings and have a better JEI preview

* Erm, add ULV casings to the CoAL
Remove some stuff I don't think I need
Make the PRASS use machine casings and have a tier based on them

* It works, weird bug with spamming buttons

* Fix the PRASS being able so somehow do precise recipes on normal mode
  • Loading branch information
Zorbatron authored Sep 9, 2024
1 parent f224af7 commit a66a7d1
Show file tree
Hide file tree
Showing 39 changed files with 592 additions and 156 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/zorbatron/zbgt/ZBGTCore.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.zorbatron.zbgt;

import static com.zorbatron.zbgt.api.ZBGTAPI.CoAL_CASINGS;
import static com.zorbatron.zbgt.api.ZBGTAPI.PRECISE_CASINGS;
import static com.zorbatron.zbgt.api.ZBGTAPI.*;
import static com.zorbatron.zbgt.common.block.ZBGTMetaBlocks.CoAL_CASING;
import static com.zorbatron.zbgt.common.block.ZBGTMetaBlocks.PRECISE_CASING;

Expand All @@ -19,6 +18,8 @@
import com.zorbatron.zbgt.common.block.blocks.PreciseCasing;

import gregtech.GTInternalTags;
import gregtech.common.blocks.BlockMachineCasing;
import gregtech.common.blocks.MetaBlocks;

@Mod(modid = ZBGTCore.MODID,
version = ZBGTCore.VERSION,
Expand Down Expand Up @@ -56,6 +57,10 @@ public void preInit(FMLPreInitializationEvent event) {
PRECISE_CASINGS.put(PRECISE_CASING.getState(type), type);
}

for (BlockMachineCasing.MachineCasingType type : BlockMachineCasing.MachineCasingType.values()) {
MACHINE_CASINGS.put(MetaBlocks.MACHINE_CASING.getState(type), type);
}

proxy.preInit();
}
}
11 changes: 7 additions & 4 deletions src/main/java/com/zorbatron/zbgt/api/ZBGTAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import net.minecraft.block.state.IBlockState;

import com.zorbatron.zbgt.api.block.ICoALTier;
import com.zorbatron.zbgt.api.block.IPreciseTier;
import com.zorbatron.zbgt.common.block.blocks.CoALCasing;
import com.zorbatron.zbgt.common.block.blocks.PreciseCasing;

import gregtech.common.blocks.BlockMachineCasing;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;

public class ZBGTAPI {

public static final Object2ObjectMap<IBlockState, ICoALTier> CoAL_CASINGS = new Object2ObjectOpenHashMap<>();
public static final Object2ObjectMap<IBlockState, CoALCasing.CasingType> CoAL_CASINGS = new Object2ObjectOpenHashMap<>();

public static final Object2ObjectMap<IBlockState, IPreciseTier> PRECISE_CASINGS = new Object2ObjectOpenHashMap<>();
public static final Object2ObjectMap<IBlockState, PreciseCasing.CasingType> PRECISE_CASINGS = new Object2ObjectOpenHashMap<>();

public static final Object2ObjectMap<IBlockState, BlockMachineCasing.MachineCasingType> MACHINE_CASINGS = new Object2ObjectOpenHashMap<>();
}
6 changes: 0 additions & 6 deletions src/main/java/com/zorbatron/zbgt/api/block/ICoALTier.java

This file was deleted.

6 changes: 0 additions & 6 deletions src/main/java/com/zorbatron/zbgt/api/block/IPreciseTier.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

public class ZBGTDataCodes {

public static final int MULTIBLOCK_TIER_CHANGE = GregtechDataCodes.assignId();
public static final int MULTIBLOCK_TIER_CHANGE_1 = GregtechDataCodes.assignId();
public static final int MULTIBLOCK_TIER_CHANGE_2 = GregtechDataCodes.assignId();
public static final int MULTIBLOCK_TIER_CHANGE_3 = GregtechDataCodes.assignId();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.zorbatron.zbgt.api.metatileentity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.minecraft.util.ResourceLocation;

import com.zorbatron.zbgt.ZBGTConfig;

import gregtech.api.capability.IEnergyContainer;
import gregtech.api.capability.impl.EnergyContainerList;
import gregtech.api.metatileentity.multiblock.MultiMapMultiblockController;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.recipes.RecipeMap;

public abstract class LaserCapableMultiMapMultiblockController extends MultiMapMultiblockController {

private final boolean allowSubstationHatches;

public LaserCapableMultiMapMultiblockController(ResourceLocation metaTileEntityId, RecipeMap<?>[] recipeMaps) {
this(metaTileEntityId, recipeMaps, true);
}

public LaserCapableMultiMapMultiblockController(ResourceLocation metaTileEntityId, RecipeMap<?>[] recipeMaps,
boolean allowSubstationHatches) {
super(metaTileEntityId, recipeMaps);
this.allowSubstationHatches = allowSubstationHatches;
}

public boolean allowsSubstationHatches() {
return this.allowSubstationHatches && ZBGTConfig.multiblockSettings.allowSubstationHatches;
}

@Override
protected void initializeAbilities() {
super.initializeAbilities();

List<IEnergyContainer> list = new ArrayList<>();
list.addAll(getAbilities(MultiblockAbility.INPUT_ENERGY));
list.addAll(getAbilities(MultiblockAbility.INPUT_LASER));
if (allowsSubstationHatches()) {
list.addAll(getAbilities(MultiblockAbility.SUBSTATION_INPUT_ENERGY));
}

this.energyContainer = new EnergyContainerList(Collections.unmodifiableList(list));
}

@Override
public TraceabilityPredicate autoAbilities(boolean checkEnergyIn, boolean checkMaintenance, boolean checkItemIn,
boolean checkItemOut, boolean checkFluidIn, boolean checkFluidOut,
boolean checkMuffler) {
TraceabilityPredicate predicate = super.autoAbilities(false, checkMaintenance, checkItemIn, checkItemOut,
checkFluidIn, checkFluidOut, checkMuffler);

if (checkEnergyIn) {
predicate = predicate.or(autoEnergyInputs());
}

return predicate;
}

public TraceabilityPredicate autoEnergyInputs(int min, int max, int previewCount) {
if (allowsSubstationHatches()) {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER,
MultiblockAbility.SUBSTATION_INPUT_ENERGY)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
} else {
return new TraceabilityPredicate(abilities(MultiblockAbility.INPUT_ENERGY, MultiblockAbility.INPUT_LASER)
.setMinGlobalLimited(min).setMaxGlobalLimited(max).setPreviewCount(previewCount));
}
}

public TraceabilityPredicate autoEnergyInputs(int min, int max) {
return autoEnergyInputs(min, max, 2);
}

public TraceabilityPredicate autoEnergyInputs() {
return autoEnergyInputs(1, 3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import net.minecraft.block.state.IBlockState;

import com.zorbatron.zbgt.api.ZBGTAPI;
import com.zorbatron.zbgt.api.block.ICoALTier;
import com.zorbatron.zbgt.api.block.IPreciseTier;
import com.zorbatron.zbgt.common.block.blocks.CoALCasing;
import com.zorbatron.zbgt.common.block.blocks.PreciseCasing;

import gregicality.multiblocks.api.capability.IParallelMultiblock;
import gregicality.multiblocks.api.metatileentity.GCYMMultiblockAbility;
Expand All @@ -20,30 +20,35 @@
import gregtech.api.pattern.TraceabilityPredicate;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.util.BlockInfo;
import gregtech.common.blocks.BlockMachineCasing;

public class TraceabilityPredicates {

private static final Supplier<TraceabilityPredicate> CoAL_PREDICATE = () -> new TraceabilityPredicate(
blockWorldState -> {
IBlockState blockState = blockWorldState.getBlockState();
if (ZBGTAPI.CoAL_CASINGS.containsKey(blockState)) {
ICoALTier tier = ZBGTAPI.CoAL_CASINGS.get(blockState);
CoALCasing.CasingType tier = ZBGTAPI.CoAL_CASINGS.get(blockState);
Object casing = blockWorldState.getMatchContext().getOrPut("CoALTier", tier);

if (!casing.equals(tier)) {
blockWorldState.setError(
new PatternStringError("gregtech.multiblock.pattern.error.component_al_tier"));
new PatternStringError("gregtech.multiblock.pattern.error.coal_tier"));
return false;
}

blockWorldState.getMatchContext().getOrPut("VBlock", new LinkedList<>())
.add(blockWorldState.getPos());

return true;
}

return false;
}, () -> ZBGTAPI.CoAL_CASINGS.entrySet().stream()
.sorted(Comparator.comparingInt(entry -> entry.getValue().getTier()))
.sorted(Comparator.comparingInt(entry -> entry.getValue().ordinal()))
.map(entry -> new BlockInfo(entry.getKey(), null))
.toArray(BlockInfo[]::new))
.addTooltips("gcyl.multiblock.pattern.error.component_al_casings");
.addTooltips("zbgt.multiblock.pattern.error.casings");

public static TraceabilityPredicate coALCasings() {
return CoAL_PREDICATE.get();
Expand All @@ -53,27 +58,60 @@ public static TraceabilityPredicate coALCasings() {
blockWorldState -> {
IBlockState blockState = blockWorldState.getBlockState();
if (ZBGTAPI.PRECISE_CASINGS.containsKey(blockState)) {
IPreciseTier tier = ZBGTAPI.PRECISE_CASINGS.get(blockState);
PreciseCasing.CasingType tier = ZBGTAPI.PRECISE_CASINGS.get(blockState);
Object casing = blockWorldState.getMatchContext().getOrPut("PreciseTier", tier);

if (!casing.equals(tier)) {
blockWorldState.setError(
new PatternStringError("gregtech.multiblock.pattern.error.precise_tier"));
return false;
}

blockWorldState.getMatchContext().getOrPut("VBlock", new LinkedList<>())
.add(blockWorldState.getPos());

return true;
}

return false;
}, () -> ZBGTAPI.PRECISE_CASINGS.entrySet().stream()
.sorted(Comparator.comparingInt(entry -> entry.getValue().getTier()))
.sorted(Comparator.comparingInt(entry -> entry.getValue().ordinal()))
.map(entry -> new BlockInfo(entry.getKey(), null))
.toArray(BlockInfo[]::new)).addTooltips("gcyl.multiblock.pattern.error.precise_casings");
.toArray(BlockInfo[]::new)).addTooltips("zbgt.multiblock.pattern.error.casings");

public static TraceabilityPredicate preciseCasings() {
return PRECISE_PREDICATE.get();
}

private static final Supplier<TraceabilityPredicate> MACHINE_CASING_PREDICATE = () -> new TraceabilityPredicate(
blockWorldState -> {
IBlockState blockState = blockWorldState.getBlockState();
if (ZBGTAPI.MACHINE_CASINGS.containsKey(blockState)) {
BlockMachineCasing.MachineCasingType tier = ZBGTAPI.MACHINE_CASINGS.get(blockState);
Object casing = blockWorldState.getMatchContext().getOrPut("MachineCasingTier", tier);

if (!casing.equals(tier)) {
blockWorldState.setError(
new PatternStringError("gregtech.multiblock.pattern.error.machine_casing_tier"));
return false;
}

blockWorldState.getMatchContext().getOrPut("VBlock", new LinkedList<>())
.add(blockWorldState.getPos());

return true;
}

return false;
}, () -> ZBGTAPI.MACHINE_CASINGS.entrySet().stream()
.sorted(Comparator.comparingInt(entry -> entry.getValue().ordinal()))
.map(entry -> new BlockInfo(entry.getKey(), null))
.toArray(BlockInfo[]::new)).addTooltip("zbgt.multiblock.pattern.error.machine_casings");

public static TraceabilityPredicate machineCasings() {
return MACHINE_CASING_PREDICATE.get();
}

public static TraceabilityPredicate autoBusesAndHatches(RecipeMap<?>[] recipeMaps) {
boolean checkedItemIn = false, checkedItemOut = false, checkedFluidIn = false, checkedFluidOut = false;
TraceabilityPredicate predicate = new TraceabilityPredicate();
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/zorbatron/zbgt/api/recipes/ITier.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@
import java.util.List;

import com.zorbatron.zbgt.api.recipes.builders.CoALRecipeBuilder;
import com.zorbatron.zbgt.api.recipes.builders.PreciseAssemblerRecipeBuilder;
import com.zorbatron.zbgt.api.recipes.helpers.RecipeIOMod;
import com.zorbatron.zbgt.api.recipes.maps.RecipeMapCoAL;
import com.zorbatron.zbgt.api.recipes.maps.RecipeMapPreciseAssembler;

import gregtech.api.recipes.RecipeMap;

public final class ZBGTRecipeMaps {

private ZBGTRecipeMaps() {}

public static final RecipeMap<CoALRecipeBuilder> CoAL_RECIPES = new RecipeMapCoAL<>(
"coal_recipes",
new CoALRecipeBuilder());

public static final RecipeMap<PreciseAssemblerRecipeBuilder> PRECISE_ASSEMBLER_RECIPES = new RecipeMapPreciseAssembler<>(
"precise_assembler_recipes",
new PreciseAssemblerRecipeBuilder());

public static void modifyMaps() {
List<RecipeIOMod> recipeModList = new ArrayList<>();
recipeModList.add(new RecipeIOMod(POLARIZER_RECIPES, 0, 0, 1, 1));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.zorbatron.zbgt.api.recipes.builders;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.jetbrains.annotations.NotNull;

import com.zorbatron.zbgt.api.recipes.properties.PreciseAssemblerProperty;
import com.zorbatron.zbgt.api.util.ZBGTLog;

import gregtech.api.recipes.Recipe;
import gregtech.api.recipes.RecipeBuilder;
import gregtech.api.recipes.RecipeMap;
import gregtech.api.util.EnumValidationResult;

public class PreciseAssemblerRecipeBuilder extends RecipeBuilder<PreciseAssemblerRecipeBuilder> {

public PreciseAssemblerRecipeBuilder() {}

public PreciseAssemblerRecipeBuilder(Recipe recipe, RecipeMap<PreciseAssemblerRecipeBuilder> recipeMap) {
super(recipe, recipeMap);
}

public PreciseAssemblerRecipeBuilder(RecipeBuilder<PreciseAssemblerRecipeBuilder> recipeBuilder) {
super(recipeBuilder);
}

@Override
public PreciseAssemblerRecipeBuilder copy() {
return new PreciseAssemblerRecipeBuilder(this);
}

@Override
public boolean applyProperty(@NotNull String key, Object value) {
if (key.equals(PreciseAssemblerProperty.KEY)) {
this.CasingTier(((Number) value).intValue());
return true;
}

return super.applyProperty(key, value);
}

public PreciseAssemblerRecipeBuilder CasingTier(int tier) {
if (tier < 0) {
ZBGTLog.logger.error("Casing tier cannot be less than 0!", new IllegalArgumentException());
this.recipeStatus = EnumValidationResult.INVALID;
}

this.applyProperty(PreciseAssemblerProperty.getInstance(), tier);

return this;
}

public int getCasingTier() {
return this.recipePropertyStorage == null ? 0 :
this.recipePropertyStorage.getRecipePropertyValue(PreciseAssemblerProperty.getInstance(), 0);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.append(super.toString())
.append(PreciseAssemblerProperty.getInstance().getKey(), getCasingTier())
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zorbatron.zbgt.api.recipes;
package com.zorbatron.zbgt.api.recipes.maps;

import net.minecraftforge.items.IItemHandlerModifiable;

Expand Down Expand Up @@ -26,7 +26,7 @@ public RecipeMapCoAL(@NotNull String unlocalizedName, @NotNull R defaultRecipeBu
public ModularUI.Builder createJeiUITemplate(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems,
FluidTankList importFluids, FluidTankList exportFluids, int yOffset) {
ModularUI.Builder builder = ModularUI.builder(GuiTextures.BACKGROUND, 176, 176)
.widget(new ProgressWidget(100, 62, 0, 72, 20, ZBGTTextures.PROGRESS_BAR_COMPONENT_AL,
.widget(new ProgressWidget(100, 62, 0, 72, 20, ZBGTTextures.PROGRESS_BAR_CoAL,
ProgressWidget.MoveType.HORIZONTAL));
this.addInventorySlotGroup(builder, importItems, importFluids, false, yOffset);
this.addInventorySlotGroup(builder, exportItems, exportFluids, true, yOffset);
Expand Down
Loading

0 comments on commit a66a7d1

Please sign in to comment.