Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix KJS bedrock/fluid veins, cable transfer rate in scanner #1200

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import com.gregtechceu.gtceu.api.data.worldgen.BiomeWeightModifier;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTBedrockFluids;
import com.gregtechceu.gtceu.utils.RegistryUtil;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.latvian.mods.rhino.util.HideFromJS;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryCodecs;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand All @@ -25,6 +28,7 @@

import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class BedrockFluidDefinition {
public static final MapCodec<Pair<Integer, Integer>> YIELD = Codec.mapPair(Codec.INT.fieldOf("min"), Codec.INT.fieldOf("max"));
Expand Down Expand Up @@ -124,7 +128,6 @@ public static class Builder {
private int depletedYield; // yield after the vein is depleted
@Setter
private Supplier<Fluid> fluid; // the fluid which the vein contains
@Setter
private Set<ResourceKey<Level>> dimensions;
private final List<BiomeWeightModifier> biomes = new LinkedList<>();

Expand Down Expand Up @@ -166,6 +169,16 @@ public Builder biomes(int weight, HolderSet<Biome> biomes) {
return this;
}

@HideFromJS
public Builder dimensions(Set<ResourceKey<Level>> dimensions) {
this.dimensions = dimensions;
return this;
}

public Builder dimensions(String... dimensions) {
return this.dimensions(new HashSet<>(RegistryUtil.resolveResourceKeys(Registries.DIMENSION, dimensions)));
}

public BedrockFluidDefinition register() {
var definition = new BedrockFluidDefinition(weight, minimumYield, maximumYield, depletionAmount, depletionChance, depletedYield, fluid, biomes, dimensions);
GTBedrockFluids.toReRegister.put(name, definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.gregtechceu.gtceu.api.data.worldgen.BiomeWeightModifier;
import com.gregtechceu.gtceu.api.registry.GTRegistries;
import com.gregtechceu.gtceu.common.data.GTOres;
import com.gregtechceu.gtceu.utils.RegistryUtil;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.latvian.mods.rhino.util.HideFromJS;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
Expand Down Expand Up @@ -130,7 +132,6 @@ public static class Builder {
private int depletedYield; // yield after the vein is depleted
@Setter
private List<Pair<Material, Integer>> materials; // the ores which the vein contains
@Setter
private Set<ResourceKey<Level>> dimensions;
private final List<BiomeWeightModifier> biomes = new LinkedList<>();

Expand Down Expand Up @@ -177,6 +178,16 @@ public Builder biomes(int weight, HolderSet<Biome> biomes) {
return this;
}

@HideFromJS
public Builder dimensions(Set<ResourceKey<Level>> dimensions) {
this.dimensions = dimensions;
return this;
}

public Builder dimensions(String... dimensions) {
return this.dimensions(new HashSet<>(RegistryUtil.resolveResourceKeys(Registries.DIMENSION, dimensions)));
}

public BedrockOreDefinition register() {
var definition = new BedrockOreDefinition(weight, size, yield, depletionAmount, depletionChance, depletedYield, materials, biomes, dimensions);
GTOres.toReRegisterBedrock.put(name, definition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public boolean incrementAmperage(long amps, long voltage) {
if (voltage > maxVoltageCounter.get(getLevel())) {
maxVoltageCounter.set(getLevel(), voltage);
}
averageVoltageCounter.increment(getLevel(), voltage);
averageVoltageCounter.increment(getLevel(), voltage * amps);
averageAmperageCounter.increment(getLevel(), amps);

int dif = (int) (averageAmperageCounter.getLast(getLevel()) - getMaxAmperage());
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/utils/RegistryUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gregtechceu.gtceu.utils;

import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Arrays;
import java.util.List;

@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
public class RegistryUtil {
private RegistryUtil() {
}

public static <T> List<ResourceKey<T>> resolveResourceKeys(ResourceKey<Registry<T>> registryKey, String... locations) {
return Arrays.stream(locations)
.map(location -> ResourceKey.create(registryKey, new ResourceLocation(location)))
.toList();
}
}
Loading