Skip to content

Commit beefe01

Browse files
authored
Readd KJS vein events & rework registration so other mods can hopefully launch. (GregTechCEu#3136)
1 parent 3413949 commit beefe01

File tree

71 files changed

+1182
-892
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1182
-892
lines changed

dependencies.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ dependencies {
6666
// runtimeOnly(forge.bundles.rei.runtime)
6767

6868
//////////////////////////////////////////////////////
69-
// Runtime s for dev testing with unclean client //
69+
// Runtime mods for dev testing with unclean client //
7070
//////////////////////////////////////////////////////
7171
extraRuntimeOnly(forge.javd)
7272
extraRuntimeOnly(forge.trenzalore)
@@ -79,16 +79,18 @@ dependencies {
7979
extraRuntimeOnly(forge.ftbteams)
8080
extraRuntimeOnly(forge.ftbquests)
8181

82-
extraRuntimeOnly(forge.heracles)
82+
// extraRuntimeOnly(forge.heracles)
8383
extraRuntimeOnly(forge.resourcefullib)
8484

8585
// extraRuntimeOnly(forge.xaerosminimap)
8686
// extraRuntimeOnly(forge.xaerosworldmap)
8787
// extraRuntimeOnly(forge.journeymap.forge)
8888
// extraRuntimeOnly(forge.ftbchunks)
8989

90-
extraRuntimeOnly(forge.gamestages)
91-
extraRuntimeOnly(forge.bookshelf)
90+
// extraRuntimeOnly(forge.gamestages)
91+
extraRuntimeOnly(forge.bookshelf) {
92+
transitive = false
93+
}
9294

9395
extraRuntimeOnly(forge.spark)
9496
extraRuntimeOnly(forge.observable)

gradle/scripts/moddevgradle.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ neoForge {
116116
// Recommended logging level for the console
117117
// You can set various levels here.
118118
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
119-
logLevel = org.slf4j.event.Level.DEBUG
119+
logLevel = org.slf4j.event.Level.INFO
120120
}
121121
}
122122
}

lombok.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
lombok.copyableAnnotations += dev.latvian.mods.rhino.util.HideFromJS
2+
lombok.copyableAnnotations += org.jetbrains.annotations.ApiStatus.Internal

src/generated/resources/assets/gtceu/lang/en_ud.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,6 +3616,7 @@
36163616
"item.gtceu.brick_wooden_form": "ɯɹoℲ uǝpooM ʞɔıɹᗺ",
36173617
"item.gtceu.brown_dye_spray_can": ")uʍoɹᗺ( uɐƆ ʎɐɹdS",
36183618
"item.gtceu.brown_glass_lens": ")uʍoɹᗺ( suǝꞀ ssɐן⅁",
3619+
"item.gtceu.bucket": "ʇǝʞɔnᗺ %s",
36193620
"item.gtceu.capacitor": "ɹoʇıɔɐdɐƆ",
36203621
"item.gtceu.capacitor.tooltip": "ʇuǝuodɯoƆ ɔıuoɹʇɔǝןƎ ɔısɐᗺㄥ§",
36213622
"item.gtceu.carbon_fiber_mesh": "ɥsǝW ɹǝqıℲ uoqɹɐƆ",

src/generated/resources/assets/gtceu/lang/en_us.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,6 +3616,7 @@
36163616
"item.gtceu.brick_wooden_form": "Brick Wooden Form",
36173617
"item.gtceu.brown_dye_spray_can": "Spray Can (Brown)",
36183618
"item.gtceu.brown_glass_lens": "Glass Lens (Brown)",
3619+
"item.gtceu.bucket": "%s Bucket",
36193620
"item.gtceu.capacitor": "Capacitor",
36203621
"item.gtceu.capacitor.tooltip": "§7Basic Electronic Component",
36213622
"item.gtceu.carbon_fiber_mesh": "Carbon Fiber Mesh",

src/main/java/com/gregtechceu/gtceu/api/gui/misc/ProspectorMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public static FluidInfo fromVeinWorldEntry(@NotNull FluidVeinWorldEntry savedDat
186186
if (savedData.getDefinition() == null) {
187187
return null;
188188
}
189-
return new FluidInfo(savedData.getDefinition().value().getStoredFluid().get(),
189+
return new FluidInfo(savedData.getDefinition().value().getStoredFluid(),
190190
savedData.getFluidYield(),
191191
100 * savedData.getOperationsRemaining() / BedrockFluidVeinSavedData.MAXIMUM_VEIN_OPERATIONS);
192192
}

src/main/java/com/gregtechceu/gtceu/api/item/datacomponents/ToolBehaviors.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.gregtechceu.gtceu.utils.codec.StreamCodecUtils;
77

88
import net.minecraft.network.RegistryFriendlyByteBuf;
9+
import net.minecraft.network.codec.ByteBufCodecs;
910
import net.minecraft.network.codec.StreamCodec;
1011

1112
import com.mojang.serialization.Codec;
@@ -22,17 +23,18 @@
2223
public record ToolBehaviors(@Unmodifiable Map<ToolBehaviorType<?>, IToolBehavior<?>> behaviors) {
2324

2425
public static final ToolBehaviors EMPTY = new ToolBehaviors(Map.of());
25-
26-
public static final Codec<ToolBehaviors> CODEC = Codec
27-
.dispatchedMap(GTRegistries.TOOL_BEHAVIORS.byNameCodec(), type -> (Codec<IToolBehavior<?>>) type.getCodec())
28-
.xmap(ToolBehaviors::new, ToolBehaviors::behaviors);
29-
public static final StreamCodec<RegistryFriendlyByteBuf, ToolBehaviors> STREAM_CODEC = StreamCodecUtils
30-
.dispatchMap(
31-
size -> (Map<ToolBehaviorType<?>, IToolBehavior<?>>) new HashMap<ToolBehaviorType<?>, IToolBehavior<?>>(
32-
size),
33-
GTRegistries.TOOL_BEHAVIORS.streamCodec(),
34-
type -> (StreamCodec<? super RegistryFriendlyByteBuf, IToolBehavior<?>>) type.getStreamCodec())
26+
// spotless:off
27+
public static final Codec<Map<ToolBehaviorType<?>, IToolBehavior<?>>> MAP_CODEC = Codec
28+
.dispatchedMap(GTRegistries.TOOL_BEHAVIORS.byNameCodec(), ToolBehaviorType::getCodec);
29+
public static final Codec<ToolBehaviors> CODEC = MAP_CODEC.xmap(ToolBehaviors::new, ToolBehaviors::behaviors);
30+
31+
public static final StreamCodec<RegistryFriendlyByteBuf, Map<ToolBehaviorType<?>, IToolBehavior<?>>> MAP_STREAM_CODEC = StreamCodecUtils.dispatchMap(
32+
HashMap::new,
33+
ByteBufCodecs.registry(GTRegistries.TOOL_BEHAVIOR_REGISTRY),
34+
type -> (StreamCodec<? super RegistryFriendlyByteBuf, IToolBehavior<?>>) type.getStreamCodec());
35+
public static final StreamCodec<RegistryFriendlyByteBuf, ToolBehaviors> STREAM_CODEC = MAP_STREAM_CODEC
3536
.map(ToolBehaviors::new, ToolBehaviors::behaviors);
37+
// spotless:on
3638

3739
public ToolBehaviors(List<IToolBehavior<?>> behaviors) {
3840
this(behaviors.stream().collect(Collectors.toMap(IToolBehavior::getType, Function.identity())));

src/main/java/com/gregtechceu/gtceu/api/machine/MetaMachine.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ public void applyImplicitComponents(MetaMachineBlockEntity.ExDataComponentInput
216216

217217
public void collectImplicitComponents(DataComponentMap.Builder components) {}
218218

219-
public void removeItemComponentsFromTag(CompoundTag tag) {}
219+
public void removeItemComponentsFromTag(CompoundTag tag) {
220+
// Just clear the tag by default.
221+
Set.copyOf(tag.getAllKeys()).forEach(tag::remove);
222+
}
220223

221224
//////////////////////////////////////
222225
// ***** Tickable Manager ****//

src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamBoilerMachine.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ public abstract class SteamBoilerMachine extends SteamWorkableMachine
8282
public SteamBoilerMachine(IMachineBlockEntity holder, boolean isHighPressure, Object... args) {
8383
super(holder, isHighPressure, args);
8484
this.waterTank = createWaterTank(args);
85-
this.waterTank.setFilter(fluid -> fluid.getFluid().is(GTMaterials.Water.getFluidTag()));
85+
this.waterTank.setFilter(fluid -> fluid.is(GTMaterials.Water.getFluidTag()));
8686
}
8787

8888
//////////////////////////////////////
8989
// ***** Initialization *****//
9090
//////////////////////////////////////
9191
@Override
92-
public ManagedFieldHolder getFieldHolder() {
92+
public @NotNull ManagedFieldHolder getFieldHolder() {
9393
return MANAGED_FIELD_HOLDER;
9494
}
9595

@@ -172,19 +172,22 @@ protected void updateSteamSubscription() {
172172
protected void updateCurrentTemperature() {
173173
if (recipeLogic.isWorking()) {
174174
if (getOffsetTimer() % 12 == 0) {
175-
if (currentTemperature < getMaxTemperature())
175+
if (currentTemperature < getMaxTemperature()) {
176176
if (isHighPressure) {
177177
currentTemperature++;
178178
} else if (getOffsetTimer() % 24 == 0) {
179179
currentTemperature++;
180180
}
181+
}
181182
}
182183
} else if (timeBeforeCoolingDown == 0) {
183184
if (currentTemperature > 0) {
184185
currentTemperature -= getCoolDownRate();
185186
timeBeforeCoolingDown = getCooldownInterval();
186187
}
187-
} else--timeBeforeCoolingDown;
188+
} else {
189+
--timeBeforeCoolingDown;
190+
}
188191

189192
if (getOffsetTimer() % 10 == 0) {
190193
if (currentTemperature >= 100) {
@@ -198,7 +201,9 @@ protected void updateCurrentTemperature() {
198201
}
199202
if (this.hasNoWater && hasDrainedWater) {
200203
doExplosion(2.0f);
201-
} else this.hasNoWater = !hasDrainedWater;
204+
} else {
205+
this.hasNoWater = !hasDrainedWater;
206+
}
202207
if (filledSteam == 0 && hasDrainedWater && getLevel() instanceof ServerLevel serverLevel) {
203208
final float x = getPos().getX() + 0.5F;
204209
final float y = getPos().getY() + 0.5F;
@@ -221,7 +226,9 @@ protected void updateCurrentTemperature() {
221226
// bypass capability check for special case behavior
222227
steamTank.drainInternal(FluidType.BUCKET_VOLUME * 4, FluidAction.EXECUTE);
223228
}
224-
} else this.hasNoWater = false;
229+
} else {
230+
this.hasNoWater = false;
231+
}
225232
}
226233
updateSteamSubscription();
227234
}
@@ -287,8 +294,7 @@ public void afterWorking() {
287294

288295
@Override
289296
protected ItemInteractionResult onSoftMalletClick(Player playerIn, InteractionHand hand, ItemStack held,
290-
Direction gridSide,
291-
BlockHitResult hitResult) {
297+
Direction gridSide, BlockHitResult hitResult) {
292298
return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
293299
}
294300

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.gregtechceu.gtceu.api.machine.trait.customlogic;
2+
3+
import com.gregtechceu.gtceu.GTCEu;
4+
import com.gregtechceu.gtceu.api.capability.recipe.IO;
5+
import com.gregtechceu.gtceu.api.capability.recipe.IRecipeCapabilityHolder;
6+
import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability;
7+
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
8+
import com.gregtechceu.gtceu.api.recipe.kind.GTRecipe;
9+
import com.gregtechceu.gtceu.common.recipe.builder.GTRecipeBuilder;
10+
import com.gregtechceu.gtceu.utils.memoization.GTMemoizer;
11+
12+
import net.minecraft.Util;
13+
import net.minecraft.core.component.DataComponents;
14+
import net.minecraft.core.registries.BuiltInRegistries;
15+
import net.minecraft.network.chat.Component;
16+
import net.minecraft.resources.ResourceLocation;
17+
import net.minecraft.world.item.Item;
18+
import net.minecraft.world.item.ItemStack;
19+
import net.minecraft.world.item.Items;
20+
import net.minecraft.world.item.crafting.RecipeType;
21+
import net.neoforged.neoforge.common.util.ItemStackMap;
22+
import net.neoforged.neoforge.fluids.FluidUtil;
23+
import net.neoforged.neoforge.items.IItemHandlerModifiable;
24+
import net.neoforged.neoforge.items.wrapper.CombinedInvWrapper;
25+
26+
import org.jetbrains.annotations.Nullable;
27+
28+
import java.util.HashSet;
29+
import java.util.Map;
30+
import java.util.Set;
31+
import java.util.function.Supplier;
32+
33+
public abstract class SteamBoilerLogic implements GTRecipeType.ICustomRecipeLogic {
34+
35+
private static final Set<SteamBoilerLogic> ALL_BOILER_LOGICS = new HashSet<>();
36+
private static final ResourceLocation EMPTY_MARKER_ID = GTCEu.id("invalid_recipe");
37+
private static final ItemStack EMPTY_MARKER_ITEM = Util.make(new ItemStack(Items.BARRIER), stack -> {
38+
stack.set(DataComponents.CUSTOM_NAME,
39+
Component.literal("Invalid Recipe! Contact developers for help!"));
40+
});
41+
42+
private final Map<ItemStack, GTRecipe> recipeCache = ItemStackMap.createTypeAndTagMap();
43+
private final Supplier<GTRecipe> emptyMarker = GTMemoizer
44+
.memoize(() -> new GTRecipeBuilder(EMPTY_MARKER_ID, getRecipeType())
45+
.inputItems(EMPTY_MARKER_ITEM.copy())
46+
.build());
47+
48+
public SteamBoilerLogic() {
49+
ALL_BOILER_LOGICS.add(this);
50+
}
51+
52+
public static void clearBoilerRecipeCaches() {
53+
for (SteamBoilerLogic logic : ALL_BOILER_LOGICS) {
54+
logic.recipeCache.clear();
55+
}
56+
}
57+
58+
protected abstract GTRecipeType getRecipeType();
59+
60+
protected abstract int modifyBurnTime(int originalBurnTime);
61+
62+
private GTRecipe makeRecipe(ItemStack input, int burnTime) {
63+
ResourceLocation itemId = BuiltInRegistries.ITEM.getKey(input.getItem());
64+
return getRecipeType().recipeBuilder(GTCEu.id(itemId.toDebugFileName()))
65+
.inputItems(input.copyWithCount(1))
66+
.duration(modifyBurnTime(burnTime))
67+
.build();
68+
}
69+
70+
@Override
71+
public @Nullable GTRecipe createCustomRecipe(IRecipeCapabilityHolder holder) {
72+
var itemInputs = holder.getCapabilitiesFlat(IO.IN, ItemRecipeCapability.CAP).stream()
73+
.filter(IItemHandlerModifiable.class::isInstance).map(IItemHandlerModifiable.class::cast)
74+
.toArray(IItemHandlerModifiable[]::new);
75+
var inputs = new CombinedInvWrapper(itemInputs);
76+
for (int i = 0; i < inputs.getSlots(); ++i) {
77+
ItemStack input = inputs.getStackInSlot(i);
78+
GTRecipe cached = recipeCache.get(input);
79+
if (cached == emptyMarker.get()) {
80+
continue;
81+
} else if (cached != null) {
82+
return cached;
83+
}
84+
85+
if (input.isEmpty() || FluidUtil.getFluidContained(input).isPresent()) {
86+
recipeCache.put(input, emptyMarker.get());
87+
continue;
88+
}
89+
int burnTime = input.getBurnTime(RecipeType.SMELTING);
90+
if (burnTime <= 0) {
91+
recipeCache.put(input, emptyMarker.get());
92+
continue;
93+
}
94+
GTRecipe recipe = makeRecipe(input, burnTime);
95+
recipeCache.put(input, recipe);
96+
return recipe;
97+
}
98+
return null;
99+
}
100+
101+
@Override
102+
public void buildRepresentativeRecipes() {
103+
for (Item item : BuiltInRegistries.ITEM) {
104+
ItemStack input = item.getDefaultInstance();
105+
if (input.isEmpty() || FluidUtil.getFluidContained(input).isPresent()) {
106+
continue;
107+
}
108+
int burnTime = input.getBurnTime(RecipeType.SMELTING);
109+
if (burnTime <= 0) {
110+
continue;
111+
}
112+
GTRecipe recipe = makeRecipe(input, burnTime);
113+
getRecipeType().addToMainCategory(recipe);
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)