Skip to content

Commit

Permalink
Merge pull request #5 from Monifactory/backport-1
Browse files Browse the repository at this point in the history
[backport] cherrypick backport
  • Loading branch information
ThePansmith authored May 13, 2024
2 parents 12919d5 + 08fd664 commit bf0a380
Show file tree
Hide file tree
Showing 139 changed files with 1,005 additions and 756 deletions.
6 changes: 1 addition & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,8 @@ dependencies {
// Forge
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

//implementation fg.deobf("blank:Xycraft+Core:0.5.2")
//runtimeOnly fg.deobf("blank:Xycraft+Override:0.5.2")
//runtimeOnly fg.deobf("blank:Xycraft+World:0.5.2")

// Registrate
implementation fg.deobf("com.tterrag.registrate:Registrate:${registrate_version}")
implementation fg.deobf("com.tterrag.registrate:Registrate:MC1.20-${registrate_version}")
jarJar(group: 'com.tterrag.registrate', name: 'Registrate', version: "${registrate_version_range}")

// GraphLib
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ mappings_channel=sugarcane
mappings_version=2023.07.23

# Dependencies
registrate_version=MC1.20-1.3.3
registrate_version_range=[MC1.20-1.3.3,)
registrate_version=1.3.11
registrate_version_range=[MC1.20,)
jei_version=15.2.0.22

graphlib_version=3.0.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Capability for getting the IO mode of the side of a block.
*/
public interface ISideConfig {
public interface SideConfig {
/**
* Get the IO mode of this side.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@

import java.util.Map;

// TODO: Instead of loot capacitors having lists of specialized machines, have different loot capacitor items for different
// machine categories.
// TODO: Loot capacitor types (Sculk, Soul) found in respective dungeons/structures.
// TODO: End game capacitor fabrication with mob fighting? Souls? Capacitor sacrifice?

// TODO: Capacitor filter for conduits.

/**
* Capacitor data.
* This defines a capacitor that stores.
* Can be attached to an item as a capability.
*/
public interface ICapacitorData {
public interface CapacitorData {
/**
* Get the base modifier of the capacitor.
*/
float getBase();
float base();

/**
* Get the modifier value for the given capacitor modifier type.
Expand All @@ -26,5 +22,5 @@ public interface ICapacitorData {
* Get a map of all modifiers and levels.
* @implNote When implementing this, only return modifiers that have been changed, don't return 1's as these will pollute tooltips.
*/
Map<CapacitorModifier, Float> getAllModifiers();
Map<CapacitorModifier, Float> modifiers();
}
31 changes: 23 additions & 8 deletions src/api/java/com/enderio/api/capacitor/CapacitorModifier.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
package com.enderio.api.capacitor;

import com.mojang.serialization.Codec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringRepresentable;

import java.util.List;
import java.util.Locale;

/**
* Capacitor key types, for use in loot capacitors for targeting increases to general stats.
*/
public enum CapacitorModifier {
ENERGY_CAPACITY,
ENERGY_USE,
public enum CapacitorModifier implements StringRepresentable {
ENERGY_CAPACITY(1),
ENERGY_USE(2),
FUEL_EFFICIENCY(3),
BURNING_ENERGY_GENERATION(4),

/**
* This should always go last as the loot picker will exclude the final item in this enum
* @apiNote Capacitors should never multiply the FIXED modifiers...
*/
FIXED;
FIXED(0);

public final ResourceLocation id;
public static final Codec<CapacitorModifier> CODEC = StringRepresentable.fromEnum(CapacitorModifier::values);

private final int id;
public final ResourceLocation modifierId;

public static final List<CapacitorModifier> SELECTABLE_MODIFIERS = List.of(
ENERGY_CAPACITY,
ENERGY_USE
ENERGY_USE,
FUEL_EFFICIENCY,
BURNING_ENERGY_GENERATION
);

CapacitorModifier() {
this.id = new ResourceLocation("enderio", "capacitor." + name().toLowerCase(Locale.ROOT));
CapacitorModifier(int id) {
this.id = id;
this.modifierId = new ResourceLocation("enderio", "capacitor." + name().toLowerCase(Locale.ROOT));
}

@Override
public String getSerializedName() {
return name().toLowerCase(Locale.ROOT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* This is designed so that things scaled by capacitors can be provided into non-specific domains.
* It also allows for the base value of a scalable to be powered by configs.
*/
public interface ICapacitorScalable {
Supplier<Float> scaleF(Supplier<ICapacitorData> data);
Supplier<Integer> scaleI(Supplier<ICapacitorData> data);
public interface CapacitorScalable {
Supplier<Float> scaleF(Supplier<CapacitorData> data);
Supplier<Integer> scaleI(Supplier<CapacitorData> data);
}
6 changes: 3 additions & 3 deletions src/api/java/com/enderio/api/capacitor/FixedScalable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
* A fixed value that implements ICapacitorScalable.
* This is a utility and will always return the value provided in the constructor.
*/
public record FixedScalable(Supplier<Integer> value) implements ICapacitorScalable {
public record FixedScalable(Supplier<Integer> value) implements CapacitorScalable {
public static final FixedScalable ZERO = new FixedScalable(() -> 0);

@Override
public Supplier<Float> scaleF(Supplier<ICapacitorData> data) {
public Supplier<Float> scaleF(Supplier<CapacitorData> data) {
return () -> (float) value.get();
}

@Override
public Supplier<Integer> scaleI(Supplier<ICapacitorData> data) {
public Supplier<Integer> scaleI(Supplier<CapacitorData> data) {
return value;
}
}
6 changes: 3 additions & 3 deletions src/api/java/com/enderio/api/capacitor/LinearScalable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* A value that is scaled linearly.
* (base, level) => base * level
*/
public record LinearScalable(CapacitorModifier modifier, Supplier<Integer> base) implements ICapacitorScalable {
public record LinearScalable(CapacitorModifier modifier, Supplier<Integer> base) implements CapacitorScalable {

@Override
public Supplier<Float> scaleF(Supplier<ICapacitorData> data) {
public Supplier<Float> scaleF(Supplier<CapacitorData> data) {
return () -> scale(base.get(), data.get().getModifier(modifier));
}

@Override
public Supplier<Integer> scaleI(Supplier<ICapacitorData> data) {
public Supplier<Integer> scaleI(Supplier<CapacitorData> data) {
return () -> Math.round(scale(base.get(), data.get().getModifier(modifier)));
}

Expand Down
6 changes: 3 additions & 3 deletions src/api/java/com/enderio/api/capacitor/QuadraticScalable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* A value that is scaled using a quadratic equation.
* (base, level) => base * level^2
*/
public record QuadraticScalable(CapacitorModifier modifier, Supplier<Integer> base) implements ICapacitorScalable {
public record QuadraticScalable(CapacitorModifier modifier, Supplier<Integer> base) implements CapacitorScalable {

@Override
public Supplier<Float> scaleF(Supplier<ICapacitorData> data) {
public Supplier<Float> scaleF(Supplier<CapacitorData> data) {
return () -> scale(base.get(), data.get().getModifier(modifier));
}

@Override
public Supplier<Integer> scaleI(Supplier<ICapacitorData> data) {
public Supplier<Integer> scaleI(Supplier<CapacitorData> data) {
return () -> Math.round(scale(base.get(), data.get().getModifier(modifier)));
}

Expand Down
24 changes: 24 additions & 0 deletions src/api/java/com/enderio/api/capacitor/SteppedScalable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.enderio.api.capacitor;

import java.util.function.Supplier;

public record SteppedScalable(
CapacitorModifier modifier,
Supplier<Integer> base,
Supplier<Integer> step
) implements CapacitorScalable {

@Override
public Supplier<Float> scaleF(Supplier<CapacitorData> data) {
return () -> scale(base.get(), step.get(), data.get().getModifier(modifier));
}

@Override
public Supplier<Integer> scaleI(Supplier<CapacitorData> data) {
return () -> Math.round(scale(base.get(), step.get(), data.get().getModifier(modifier)));
}

private static float scale(int base, int step, float level) {
return base + step * level;
}
}
3 changes: 1 addition & 2 deletions src/api/java/com/enderio/api/capacitor/package-info.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@javax.annotation.ParametersAreNonnullByDefault
@net.minecraft.MethodsReturnNonnullByDefault
@com.tterrag.registrate.util.nullness.FieldsAreNonnullByDefault

package com.enderio.api.capacitor;
package com.enderio.api.capacitor;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.enderio.api.conduit;

import com.enderio.api.misc.IIcon;
import com.enderio.api.misc.Icon;
import com.enderio.api.misc.Vector2i;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.AbstractWidget;
Expand All @@ -17,9 +17,9 @@
import java.util.function.Function;
import java.util.function.Supplier;

public interface IClientConduitData<T extends IExtendedConduitData<T>> extends IIcon {
public interface ClientConduitData<T extends ExtendedConduitData<T>> extends Icon {

interface UpdateExtendedData<T extends IExtendedConduitData<T>> {
interface UpdateExtendedData<T extends ExtendedConduitData<T>> {
void update(Function<T, T> mapper);
}

Expand Down Expand Up @@ -68,7 +68,7 @@ default List<ResourceLocation> modelsToLoad() {
return List.of();
}

class Simple<T extends IExtendedConduitData<T>> implements IClientConduitData<T> {
class Simple<T extends ExtendedConduitData<T>> implements ClientConduitData<T> {
private final ResourceLocation textureLocation;
private final Vector2i texturePosition;

Expand Down
6 changes: 3 additions & 3 deletions src/api/java/com/enderio/api/conduit/ConduitItemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ public class ConduitItemFactory {
* this field is set by EIOConduits during the FMLConstructModEvent.
*/
@Nullable
private static BiFunction<Supplier<? extends IConduitType<?>>, Item.Properties, Item> factory = null;
private static BiFunction<Supplier<? extends ConduitType<?>>, Item.Properties, Item> factory = null;

@ApiStatus.Internal
public static void setFactory(BiFunction<Supplier<? extends IConduitType<?>>, Item.Properties, Item> factory) {
public static void setFactory(BiFunction<Supplier<? extends ConduitType<?>>, Item.Properties, Item> factory) {
ConduitItemFactory.factory = factory;
}

/**
* This will create a Conduit Item. If, during porting, EIOConduits isn't available, a dummy item will be returned.
* @return
*/
public static Item build(Supplier<? extends IConduitType<?>> type, Item.Properties properties) {
public static Item build(Supplier<? extends ConduitType<?>> type, Item.Properties properties) {
if (factory != null) {
return factory.apply(type, properties);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.enderio.api.conduit;

public interface IConduitMenuData {
public interface ConduitMenuData {

IConduitMenuData REDSTONE = new Simple(true, true, false, true, true, false);
IConduitMenuData ITEM = new Simple(true, true, true, true, true, true);
IConduitMenuData ENERGY = new Simple(false, false, false, false, false, true);
ConduitMenuData REDSTONE = new Simple(true, true, false, true, true, false);
ConduitMenuData ITEM = new Simple(true, true, true, true, true, true);
ConduitMenuData ENERGY = new Simple(false, false, false, false, false, true);

boolean hasFilterInsert();

Expand All @@ -27,5 +27,5 @@ default boolean showBothEnable() {
boolean showRedstoneExtract();

record Simple(boolean hasFilterInsert, boolean hasFilterExtract, boolean hasUpgrade, boolean showColorInsert, boolean showColorExtract,
boolean showRedstoneExtract) implements IConduitMenuData {}
boolean showRedstoneExtract) implements ConduitMenuData {}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
package com.enderio.api.conduit;

import net.minecraft.resources.ResourceLocation;
import com.enderio.api.registry.EnderIORegistries;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder;
import org.jetbrains.annotations.ApiStatus;

import java.util.function.Supplier;

public class ConduitTypes {
public class ConduitRegistries {
/**
* @apiNote this DeferredRegister is not exposed for you, it's just a requirement to construct the ForgeRegistry.
*/
public static final DeferredRegister<IConduitType<?>> CONDUIT_TYPES = DeferredRegister.create(new ResourceLocation("enderio", "conduit_types"), "enderio");
@ApiStatus.Internal
public static final DeferredRegister<ConduitType<?>> CONDUIT_TYPES = DeferredRegister.create(EnderIORegistries.Keys.CONDUIT_TYPES, "enderio");

/**
* Create a new DeferredRegister using this ForgeRegistry as a base
*/
public static final Supplier<IForgeRegistry<IConduitType<?>>> REGISTRY = CONDUIT_TYPES.makeRegistry(RegistryBuilder::new);
public static final Supplier<IForgeRegistry<ConduitType<?>>> REGISTRY = CONDUIT_TYPES.makeRegistry(RegistryBuilder::new);

public static ForgeRegistry<IConduitType<?>> getRegistry() {
// if only we can use vanilla mc registry
@SuppressWarnings("UnstableApiUsage")
public static ForgeRegistry<ConduitType<?>> getRegistry() {
//should always be a forgeRegistry. Needed for IDs for networking/ordering
return (ForgeRegistry<IConduitType<?>>) REGISTRY.get();
return (ForgeRegistry<ConduitType<?>>) REGISTRY.get();
}

public static void register(IEventBus bus) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.enderio.api.conduit;

import com.enderio.api.UseOnly;
import com.enderio.api.conduit.ticker.IConduitTicker;
import com.enderio.api.conduit.ticker.ConduitTicker;
import com.enderio.api.misc.RedstoneControl;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -16,7 +16,7 @@

import java.util.Optional;

public interface IConduitType<T extends IExtendedConduitData<T>> {
public interface ConduitType<T extends ExtendedConduitData<T>> {

ResourceLocation getTexture(T extendedData);
ResourceLocation getItemTexture();
Expand All @@ -26,27 +26,32 @@ public interface IConduitType<T extends IExtendedConduitData<T>> {
* @return the conduit item that holds this type
*/
default Item getConduitItem() {
return ForgeRegistries.ITEMS.getValue(ConduitTypes.getRegistry().getKey(this));
return ForgeRegistries.ITEMS.getValue(ConduitRegistries.getRegistry().getKey(this));
}

default boolean canBeInSameBlock(IConduitType<?> other) {
default boolean canBeInSameBlock(ConduitType<?> other) {
return true;
}

default boolean canBeReplacedBy(IConduitType<?> other) {
default boolean canBeReplacedBy(ConduitType<?> other) {
return false;
}

IConduitTicker getTicker();
ConduitTicker getTicker();

@UseOnly(LogicalSide.CLIENT)
IClientConduitData<T> getClientData();
IConduitMenuData getMenuData();
ClientConduitData<T> getClientData();
ConduitMenuData getMenuData();

T createExtendedConduitData(Level level, BlockPos pos);

default <K> Optional<LazyOptional<K>> proxyCapability(Capability<K> cap, T extendedConduitData, Level level, BlockPos pos, @Nullable Direction direction,
Optional<NodeIdentifier.IOState> state) {
default <K> Optional<LazyOptional<K>> proxyCapability(
Capability<K> cap,
T extendedConduitData,
Level level,
BlockPos pos,
@Nullable Direction direction,
@Nullable Optional<NodeIdentifier.IOState> state) {
return Optional.empty();
}

Expand Down
Loading

0 comments on commit bf0a380

Please sign in to comment.