Skip to content

Commit c80a5fe

Browse files
authored
Add (configurable) support for GTEU.
- GTEU support can be enabled/disabled individually for all three machines (Automation Interface, Quantum Compressor, Combination Crafter) in the config. - The value of one GTEU as RF can be configured as any integer between 1 and 2^31-1.
1 parent c283d56 commit c80a5fe

7 files changed

Lines changed: 174 additions & 7 deletions

File tree

build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ repositories {
5656
maven {
5757
url = "https://maven.blamejared.com/"
5858
}
59+
maven {
60+
url = "http://chickenbones.net/maven/"
61+
}
62+
maven {
63+
url = "https://minecraft.curseforge.com/api/maven"
64+
}
5965
}
6066

6167
dependencies {
@@ -66,6 +72,8 @@ dependencies {
6672
deobfCompile "curse.maven:hwyla:2568751"
6773
deobfCompile "curse.maven:packagedauto:2977147"
6874
deobfCompile "curse.maven:pexc:2899874"
75+
deobfCompile "gregtechce:gregtech:1.12.2:1.10.1.557"
76+
deobfCompile "codechicken-lib-1-8:CodeChickenLib-1.12.2:3.2.3.357:universal"
6977
}
7078

7179
processResources {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.blakebr0.extendedcrafting.compat.gregtech;
2+
3+
import gregtech.api.capability.GregtechCapabilities;
4+
import net.minecraftforge.common.capabilities.Capability;
5+
6+
import javax.annotation.Nonnull;
7+
import javax.annotation.Nullable;
8+
9+
/**
10+
* Interface for blocks that may have the
11+
* {@link GregtechCapabilities#CAPABILITY_ENERGY_CONTAINER}
12+
* capability.
13+
*
14+
* Implementing classes are expected to implement the {@link IGTEnergyContainer}
15+
* interface as well, but using {@link net.minecraftforge.fml.common.Optional.Interface}.
16+
*
17+
* This class ensures that when the {@link IGTEnergyContainer} interface is stripped,
18+
* {@link #getGTCapability(Capability)} is still available.
19+
*/
20+
public interface IGTCapHolder {
21+
/**
22+
* Get the {@link GregtechCapabilities#CAPABILITY_ENERGY_CONTAINER} capability, if
23+
* it is being requested.
24+
*
25+
* This will be the implementation used if GregTech is not present.
26+
*/
27+
@Nullable
28+
default <T> T getGTCapability(@Nonnull Capability<T> capability) {
29+
return null;
30+
}
31+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.blakebr0.extendedcrafting.compat.gregtech;
2+
3+
import com.blakebr0.extendedcrafting.config.ModConfig;
4+
import gregtech.api.capability.GregtechCapabilities;
5+
import gregtech.api.capability.IEnergyContainer;
6+
import net.minecraft.util.EnumFacing;
7+
import net.minecraftforge.common.capabilities.Capability;
8+
import net.minecraftforge.energy.IEnergyStorage;
9+
10+
import javax.annotation.Nonnull;
11+
import javax.annotation.Nullable;
12+
13+
/**
14+
* Interface for accepting GTEU, built on top of an existing FE implementation.
15+
*
16+
* @see IGTCapHolder
17+
*/
18+
public interface IGTEnergyContainer extends IEnergyContainer, IGTCapHolder {
19+
IEnergyStorage getEnergy();
20+
21+
@Nullable
22+
@Override
23+
default <T> T getGTCapability(@Nonnull Capability<T> capability) {
24+
if (capability == GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER) {
25+
return GregtechCapabilities.CAPABILITY_ENERGY_CONTAINER.cast(this);
26+
}
27+
return null;
28+
}
29+
30+
static int euToRF(long eu) {
31+
return (int) Math.min(Integer.MAX_VALUE / ModConfig.confEUtoRF, eu) * ModConfig.confEUtoRF;
32+
}
33+
34+
static long rfToEU(int rf) {
35+
return (long) rf / ModConfig.confEUtoRF;
36+
}
37+
38+
@Override
39+
default long acceptEnergyFromNetwork(EnumFacing side, long voltage, long amperage) {
40+
if (voltage <= 0 || amperage <= 0 || (side != null && !inputsEnergy(side))) return 0;
41+
42+
long amperesAccepted = Math.min(getEnergyCanBeInserted() / voltage, Math.min(amperage, getInputAmperage()));
43+
if (amperesAccepted <= 0) return 0;
44+
45+
addEnergy(voltage * amperesAccepted);
46+
return amperesAccepted;
47+
}
48+
49+
@Override
50+
default boolean inputsEnergy(EnumFacing enumFacing) {
51+
return getEnergy().canReceive();
52+
}
53+
54+
@Override
55+
default long changeEnergy(long difference) {
56+
return rfToEU(difference >= 0 ?
57+
getEnergy().receiveEnergy(euToRF(difference), false) :
58+
getEnergy().extractEnergy(euToRF(-difference), false));
59+
}
60+
61+
@Override
62+
default long getEnergyStored() {
63+
return rfToEU(getEnergy().getEnergyStored());
64+
}
65+
66+
@Override
67+
default long getEnergyCapacity() {
68+
return rfToEU(getEnergy().getMaxEnergyStored());
69+
}
70+
71+
@Override
72+
default long getInputAmperage() {
73+
return Long.MAX_VALUE;
74+
}
75+
76+
@Override
77+
default long getInputVoltage() {
78+
return Long.MAX_VALUE;
79+
}
80+
}

src/main/java/com/blakebr0/extendedcrafting/config/ModConfig.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.blakebr0.extendedcrafting.config;
22

3-
import java.io.File;
4-
53
import com.blakebr0.extendedcrafting.ExtendedCrafting;
64
import com.blakebr0.extendedcrafting.item.ModItems;
7-
85
import net.minecraftforge.common.config.ConfigCategory;
96
import net.minecraftforge.common.config.Configuration;
107
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
118
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
129

10+
import java.io.File;
11+
1312
public class ModConfig {
1413

1514
public static Configuration config;
@@ -22,10 +21,12 @@ public class ModConfig {
2221
public static boolean confCraftingCoreEnabled;
2322
public static int confCraftingCoreRFCapacity;
2423
public static int confCraftingCoreRFRate;
25-
24+
public static boolean confCraftingCoreAcceptGTEU;
25+
2626
public static boolean confInterfaceEnabled;
2727
public static int confInterfaceRFCapacity;
2828
public static int confInterfaceRFRate;
29+
public static boolean confInterfaceAcceptGTEU;
2930
public static boolean confInterfaceRenderer;
3031

3132
public static boolean confTableEnabled;
@@ -34,6 +35,7 @@ public class ModConfig {
3435
public static boolean confCompressorEnabled;
3536
public static int confCompressorRFCapacity;
3637
public static int confCompressorRFRate;
38+
public static boolean confCompressorAcceptGTEU;
3739
public static boolean confCompressorRenderer;
3840

3941
public static boolean confEnderEnabled;
@@ -51,6 +53,8 @@ public class ModConfig {
5153
public static boolean confUltimateSingularityRecipe;
5254
public static String confSingularityCatalyst;
5355

56+
public static int confEUtoRF;
57+
5458
@SubscribeEvent
5559
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
5660
if (event.getModID().equals(ExtendedCrafting.MOD_ID)) {
@@ -80,12 +84,14 @@ public static void init() {
8084
confCraftingCoreEnabled = config.getBoolean("enabled", category, true, "Should the Crafting Core and Pedestal be enabled?");
8185
confCraftingCoreRFCapacity = config.getInt("energy_capacity", category, 5000000, 0, Integer.MAX_VALUE, "How much FE the Crafting Core should hold.");
8286
confCraftingCoreRFRate = config.getInt("energy_rate", category, 500, 0, Integer.MAX_VALUE, "How much FE/t the Crafting Core should use when crafting by default.");
87+
confCraftingCoreAcceptGTEU = config.getBoolean("accept_gteu", category, false, "Should the Crafting Core accept GTEU?");
8388

8489
category = "automation_interface";
8590
config.setCategoryComment(category, "Settings for the Automation Interface.");
8691
confInterfaceEnabled = config.getBoolean("enabled", category, true, "Should the Automation Interface be enabled?");
8792
confInterfaceRFCapacity = config.getInt("energy_capacity", category, 1000000, 0, Integer.MAX_VALUE, "How much FE the Automation Interface should hold.");
8893
confInterfaceRFRate = config.getInt("energy_rate", category, 80, 0, 100000, "How much FE the Automation Interface should use when moving items.");
94+
confInterfaceAcceptGTEU = config.getBoolean("accept_gteu", category, false, "Should the Automation Interface accept GTEU?");
8995
confInterfaceRenderer = config.getBoolean("render_item", category, true, "Should the Automation Interface render the result item inside it?");
9096

9197
category = "table_crafting";
@@ -98,6 +104,7 @@ public static void init() {
98104
confCompressorEnabled = config.getBoolean("enabled", category, true, "Should the Quantum Compressor be enabled?");
99105
confCompressorRFCapacity = config.getInt("energy_capacity", category, 10000000, 0, Integer.MAX_VALUE, "How much FE the Quantum Compressor should hold.");
100106
confCompressorRFRate = config.getInt("energy_rate", category, 5000, 0, Integer.MAX_VALUE, "How much FE/t the Quantum Compressor should use when crafting by default.");
107+
confCompressorAcceptGTEU = config.getBoolean("accept_gteu", category, false, "Should the Quantum Compressor accept GTEU?");
101108
confCompressorRenderer = config.getBoolean("render_item", category, true, "Should the Quantum Compressor render the result item above it?");
102109

103110
category = "ender_crafting";
@@ -123,6 +130,10 @@ public static void init() {
123130
ModItems.itemSingularityCustom.configure(config);
124131
ModItems.itemSingularityUltimate.configure(config);
125132

133+
category = "gregtech";
134+
config.setCategoryComment(category, "Settings for GregTech compatibility.");
135+
confEUtoRF = config.getInt("conversion", category, 4, 1, Integer.MAX_VALUE, "How much RF should one GTEU be handled as?");
136+
126137
if (config.hasChanged()) {
127138
config.save();
128139
}

src/main/java/com/blakebr0/extendedcrafting/tile/TileAutomationInterface.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.blakebr0.cucumber.energy.EnergyStorageCustom;
44
import com.blakebr0.cucumber.helper.StackHelper;
5+
import com.blakebr0.extendedcrafting.compat.gregtech.IGTCapHolder;
6+
import com.blakebr0.extendedcrafting.compat.gregtech.IGTEnergyContainer;
57
import com.blakebr0.extendedcrafting.config.ModConfig;
68
import com.blakebr0.extendedcrafting.crafting.endercrafter.EnderCrafterRecipeManager;
79
import com.blakebr0.extendedcrafting.crafting.table.TableCrafting;
@@ -21,6 +23,7 @@
2123
import net.minecraftforge.common.ForgeHooks;
2224
import net.minecraftforge.common.capabilities.Capability;
2325
import net.minecraftforge.energy.CapabilityEnergy;
26+
import net.minecraftforge.fml.common.Optional;
2427
import net.minecraftforge.items.CapabilityItemHandler;
2528
import net.minecraftforge.items.IItemHandler;
2629
import net.minecraftforge.items.IItemHandlerModifiable;
@@ -33,7 +36,11 @@
3336

3437
@ParametersAreNonnullByDefault
3538
@MethodsReturnNonnullByDefault
36-
public class TileAutomationInterface extends TileInventoryBase implements ITickable, ISidedInventory {
39+
@Optional.Interface(modid = "gregtech",
40+
iface = "com.blakebr0.extendedcrafting.compat.gregtech.IGTEnergyContainer")
41+
public class TileAutomationInterface
42+
extends TileInventoryBase
43+
implements ITickable, ISidedInventory, IGTEnergyContainer, IGTCapHolder {
3744

3845
private final ItemStackHandler inventory = new StackHandler();
3946
private final ItemStackHandler recipe = new FakeRecipeHandler();
@@ -358,6 +365,11 @@ public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFaci
358365
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(new SidedInvWrapper(this, side));
359366
} else if (capability == CapabilityEnergy.ENERGY) {
360367
return CapabilityEnergy.ENERGY.cast(this.energy);
368+
} else if (ModConfig.confInterfaceAcceptGTEU) {
369+
T cap = getGTCapability(capability);
370+
if (cap != null) {
371+
return cap;
372+
}
361373
}
362374

363375
return super.getCapability(capability, side);
@@ -375,6 +387,7 @@ public ItemStack getResult() {
375387
return this.result;
376388
}
377389

390+
@Override
378391
public EnergyStorageCustom getEnergy() {
379392
return this.energy;
380393
}

src/main/java/com/blakebr0/extendedcrafting/tile/TileCompressor.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.blakebr0.cucumber.energy.EnergyStorageCustom;
44
import com.blakebr0.cucumber.helper.StackHelper;
5+
import com.blakebr0.extendedcrafting.compat.gregtech.IGTCapHolder;
6+
import com.blakebr0.extendedcrafting.compat.gregtech.IGTEnergyContainer;
57
import com.blakebr0.extendedcrafting.config.ModConfig;
68
import com.blakebr0.extendedcrafting.crafting.CompressorRecipe;
79
import com.blakebr0.extendedcrafting.crafting.CompressorRecipeManager;
@@ -14,14 +16,19 @@
1416
import net.minecraft.util.NonNullList;
1517
import net.minecraftforge.common.capabilities.Capability;
1618
import net.minecraftforge.energy.CapabilityEnergy;
19+
import net.minecraftforge.fml.common.Optional;
1720
import net.minecraftforge.items.CapabilityItemHandler;
1821
import net.minecraftforge.items.wrapper.SidedInvWrapper;
1922

2023
import javax.annotation.Nullable;
2124
import java.util.ArrayList;
2225
import java.util.List;
2326

24-
public class TileCompressor extends TileInventoryBase implements ISidedInventory, ITickable {
27+
@Optional.Interface(modid = "gregtech",
28+
iface = "com.blakebr0.extendedcrafting.compat.gregtech.IGTEnergyContainer")
29+
public class TileCompressor
30+
extends TileInventoryBase
31+
implements ISidedInventory, ITickable, IGTEnergyContainer, IGTCapHolder {
2532

2633
private NonNullList<ItemStack> inventoryStacks = NonNullList.withSize(3, ItemStack.EMPTY);
2734
private final EnergyStorageCustom energy = new EnergyStorageCustom(ModConfig.confCompressorRFCapacity);
@@ -214,6 +221,7 @@ public int addStackToSlot(int slot, ItemStack stack) {
214221
return 0;
215222
}
216223

224+
@Override
217225
public EnergyStorageCustom getEnergy() {
218226
return this.energy;
219227
}
@@ -330,6 +338,11 @@ public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing
330338
return (T) new SidedInvWrapper(this, facing);
331339
} else if (capability == CapabilityEnergy.ENERGY) {
332340
return CapabilityEnergy.ENERGY.cast(this.energy);
341+
} else if (ModConfig.confCompressorAcceptGTEU) {
342+
T cap = getGTCapability(capability);
343+
if (cap != null) {
344+
return cap;
345+
}
333346
}
334347

335348
return super.getCapability(capability, facing);

src/main/java/com/blakebr0/extendedcrafting/tile/TileCraftingCore.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import com.blakebr0.cucumber.helper.StackHelper;
55
import com.blakebr0.cucumber.util.VanillaPacketDispatcher;
66
import com.blakebr0.extendedcrafting.block.BlockPedestal;
7+
import com.blakebr0.extendedcrafting.compat.gregtech.IGTCapHolder;
8+
import com.blakebr0.extendedcrafting.compat.gregtech.IGTEnergyContainer;
79
import com.blakebr0.extendedcrafting.config.ModConfig;
810
import com.blakebr0.extendedcrafting.crafting.CombinationRecipe;
911
import com.blakebr0.extendedcrafting.crafting.CombinationRecipeManager;
@@ -22,14 +24,17 @@
2224
import net.minecraft.world.WorldServer;
2325
import net.minecraftforge.common.capabilities.Capability;
2426
import net.minecraftforge.energy.CapabilityEnergy;
27+
import net.minecraftforge.fml.common.Optional;
2528
import net.minecraftforge.items.CapabilityItemHandler;
2629
import net.minecraftforge.items.IItemHandlerModifiable;
2730
import net.minecraftforge.items.ItemStackHandler;
2831

2932
import javax.annotation.Nullable;
3033
import java.util.*;
3134

32-
public class TileCraftingCore extends TileEntity implements ITickable {
35+
@Optional.Interface(modid = "gregtech",
36+
iface = "com.blakebr0.extendedcrafting.compat.gregtech.IGTEnergyContainer")
37+
public class TileCraftingCore extends TileEntity implements ITickable, IGTEnergyContainer, IGTCapHolder {
3338

3439
private final ItemStackHandler inventory = new StackHandler();
3540
private final EnergyStorageCustom energy = new EnergyStorageCustom(ModConfig.confCraftingCoreRFCapacity);
@@ -178,6 +183,7 @@ public IItemHandlerModifiable getInventory() {
178183
return this.inventory;
179184
}
180185

186+
@Override
181187
public EnergyStorageCustom getEnergy() {
182188
return this.energy;
183189
}
@@ -236,6 +242,11 @@ public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing side)
236242
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(this.inventory);
237243
} else if (capability == CapabilityEnergy.ENERGY) {
238244
return CapabilityEnergy.ENERGY.cast(this.energy);
245+
} else if (ModConfig.confCraftingCoreAcceptGTEU) {
246+
T cap = getGTCapability(capability);
247+
if (cap != null) {
248+
return cap;
249+
}
239250
}
240251

241252
return super.getCapability(capability, side);

0 commit comments

Comments
 (0)