Skip to content

Commit

Permalink
Feature: Make EnergyInputHatch to support energy extraction from the …
Browse files Browse the repository at this point in the history
…energy core, providing more custom configurations of EnergyHatch.
  • Loading branch information
KasumiNova committed Feb 19, 2023
1 parent 680216a commit 9fcb9c3
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.CommonProxy;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchSize;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchData;
import hellfirepvp.modularmachinery.common.tiles.base.TileEnergyHatch;
import hellfirepvp.modularmachinery.common.util.RedstoneHelper;
import net.minecraft.block.SoundType;
Expand All @@ -27,7 +27,7 @@
import java.util.List;

public abstract class BlockEnergyHatch extends BlockMachineComponent implements BlockCustomName, BlockVariants {
protected static final PropertyEnum<EnergyHatchSize> BUS_TYPE = PropertyEnum.create("size", EnergyHatchSize.class);
protected static final PropertyEnum<EnergyHatchData> BUS_TYPE = PropertyEnum.create("size", EnergyHatchData.class);

public BlockEnergyHatch() {
super(Material.IRON);
Expand All @@ -39,15 +39,15 @@ public BlockEnergyHatch() {
}

@Optional.Method(modid = "gregtech")
protected abstract void addGTTooltip(List<String> tooltip, EnergyHatchSize size);
protected abstract void addGTTooltip(List<String> tooltip, EnergyHatchData size);

@Override
@SideOnly(Side.CLIENT)
public abstract void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, ITooltipFlag advanced);

@Override
public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
for (EnergyHatchSize size : EnergyHatchSize.values()) {
for (EnergyHatchData size : EnergyHatchData.values()) {
items.add(new ItemStack(this, 1, size.ordinal()));
}
}
Expand All @@ -70,7 +70,7 @@ public int damageDropped(IBlockState state) {

@Override
public IBlockState getStateFromMeta(int meta) {
return getDefaultState().withProperty(BUS_TYPE, EnergyHatchSize.values()[meta]);
return getDefaultState().withProperty(BUS_TYPE, EnergyHatchData.values()[meta]);
}

@Override
Expand All @@ -86,7 +86,7 @@ protected BlockStateContainer createBlockState() {
@Override
public Iterable<IBlockState> getValidStates() {
List<IBlockState> ret = new LinkedList<>();
for (EnergyHatchSize type : EnergyHatchSize.values()) {
for (EnergyHatchData type : EnergyHatchData.values()) {
ret.add(getDefaultState().withProperty(BUS_TYPE, type));
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import hellfirepvp.modularmachinery.client.util.EnergyDisplayUtil;
import hellfirepvp.modularmachinery.common.base.Mods;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchSize;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchData;
import hellfirepvp.modularmachinery.common.tiles.TileEnergyInputHatch;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
Expand All @@ -36,7 +36,7 @@
*/
public class BlockEnergyInputHatch extends BlockEnergyHatch {
@Optional.Method(modid = "gregtech")
protected void addGTTooltip(List<String> tooltip, EnergyHatchSize size) {
protected void addGTTooltip(List<String> tooltip, EnergyHatchData size) {
tooltip.add(TextFormatting.GRAY + I18n.format("tooltip.energyhatch.gregtech.voltage.in",
String.valueOf(size.getGTEnergyTransferVoltage()),
size.getUnlocalizedGTEnergyTier()));
Expand All @@ -49,7 +49,7 @@ protected void addGTTooltip(List<String> tooltip, EnergyHatchSize size) {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, ITooltipFlag advanced) {
EnergyHatchSize size = EnergyHatchSize.values()[MathHelper.clamp(stack.getMetadata(), 0, EnergyHatchSize.values().length - 1)];
EnergyHatchData size = EnergyHatchData.values()[MathHelper.clamp(stack.getMetadata(), 0, EnergyHatchData.values().length - 1)];
if (EnergyDisplayUtil.displayFETooltip) {
tooltip.add(TextFormatting.GRAY + I18n.format("tooltip.energyhatch.storage", size.maxEnergy));
tooltip.add(TextFormatting.GRAY + I18n.format("tooltip.energyhatch.in.accept", size.transferLimit));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import hellfirepvp.modularmachinery.client.util.EnergyDisplayUtil;
import hellfirepvp.modularmachinery.common.base.Mods;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchSize;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchData;
import hellfirepvp.modularmachinery.common.tiles.TileEnergyOutputHatch;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.resources.I18n;
Expand All @@ -36,7 +36,7 @@
*/
public class BlockEnergyOutputHatch extends BlockEnergyHatch {
@Optional.Method(modid = "gregtech")
protected void addGTTooltip(List<String> tooltip, EnergyHatchSize size) {
protected void addGTTooltip(List<String> tooltip, EnergyHatchData size) {
tooltip.add(TextFormatting.GRAY + I18n.format("tooltip.energyhatch.gregtech.voltage.out",
String.valueOf(size.getGTEnergyTransferVoltage()),
size.getUnlocalizedGTEnergyTier()));
Expand All @@ -49,7 +49,7 @@ protected void addGTTooltip(List<String> tooltip, EnergyHatchSize size) {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World player, List<String> tooltip, ITooltipFlag advanced) {
EnergyHatchSize size = EnergyHatchSize.values()[MathHelper.clamp(stack.getMetadata(), 0, EnergyHatchSize.values().length - 1)];
EnergyHatchData size = EnergyHatchData.values()[MathHelper.clamp(stack.getMetadata(), 0, EnergyHatchData.values().length - 1)];
if (EnergyDisplayUtil.displayFETooltip) {
tooltip.add(TextFormatting.GRAY + I18n.format("tooltip.energyhatch.storage", size.maxEnergy));
tooltip.add(TextFormatting.GRAY + I18n.format("tooltip.energyhatch.out.transfer", size.transferLimit));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package hellfirepvp.modularmachinery.common.block.prop;

import gregtech.api.GTValues;
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.common.util.MiscUtils;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.math.MathHelper;
Expand All @@ -24,16 +25,22 @@
* Created by HellFirePvP
* Date: 08.07.2017 / 10:25
*/
public enum EnergyHatchSize implements IStringSerializable {

TINY(2048, 1, 128, 1, 2),
SMALL(4096, 2, 512, 2, 2),
NORMAL(8192, 2, 512, 2, 2),
REINFORCED(16384, 3, 2048, 3, 2),
BIG(32768, 4, 8192, 4, 2),
HUGE(131072, 5, 32768, 5, 2),
LUDICROUS(524288, 6, 131072, 6, 2),
ULTIMATE(2097152, 6, 131072, 6, 2);
public enum EnergyHatchData implements IStringSerializable {

TINY( 2048, 1, 128, 1, 2),
SMALL( 4096, 2, 512, 2, 2),
NORMAL( 8192, 2, 512, 2, 2),
REINFORCED( 16384, 3, 2048, 3, 2),
BIG( 32768, 4, 8192, 4, 2),
HUGE( 131072, 5, 32768, 5, 2),
LUDICROUS( 524288, 6, 131072, 6, 2),
ULTIMATE( 2097152, 6, 131072, 6, 2);

public static boolean enableDEIntegration = true;
public static boolean delayedEnergyCoreSearch = true;
public static int energyCoreSearchDelay = 100;
public static int maxEnergyCoreSearchDelay = 300;
public static int searchRange = 16;

private final int defaultConfigurationEnergy;
private final int defaultConfigurationTransferLimit;
Expand All @@ -46,7 +53,7 @@ public enum EnergyHatchSize implements IStringSerializable {
public int gtEnergyTier;
public int gtAmperage;

EnergyHatchSize(int maxEnergy, int ic2EnergyTier, int transferLimit, int gtEnergyTier, int gtAmperage) {
EnergyHatchData(int maxEnergy, int ic2EnergyTier, int transferLimit, int gtEnergyTier, int gtAmperage) {
this.defaultConfigurationEnergy = maxEnergy;
this.defaultIC2EnergyTier = ic2EnergyTier;
this.defaultConfigurationTransferLimit = transferLimit;
Expand All @@ -55,7 +62,7 @@ public enum EnergyHatchSize implements IStringSerializable {
}

public static void loadFromConfig(Configuration cfg) {
for (EnergyHatchSize size : values()) {
for (EnergyHatchData size : values()) {
size.maxEnergy = cfg.get("energyhatch.size", size.name().toUpperCase(), String.valueOf(size.defaultConfigurationEnergy), "Energy storage size of the energy hatch. [range: 0 ~ 9223372036854775807, default: " + size.defaultConfigurationEnergy + "]").getLong();
size.maxEnergy = MiscUtils.clamp(size.maxEnergy, 1, Long.MAX_VALUE);
size.transferLimit = cfg.get("energyhatch.limit", size.name().toUpperCase(), String.valueOf(size.defaultConfigurationTransferLimit), "Defines the transfer limit for RF/FE things. IC2's transfer limit is defined by the voltage tier. [range: 1 ~ 9223372036854775806, default: " + size.defaultConfigurationEnergy + "]").getLong();
Expand All @@ -68,6 +75,23 @@ public static void loadFromConfig(Configuration cfg) {
size.gtAmperage = cfg.get("energyhatch.gtamperage", size.name().toUpperCase(), size.defaultGTAmperage, "Defines the GT amperage. Affects both output amperage as well as maximum input amperage. [range: 1 ~ 16, default: " + size.defaultGTAmperage + "]").getInt();
size.gtAmperage = MathHelper.clamp(size.gtAmperage, 1, 16);
}

enableDEIntegration = cfg.getBoolean("enable-de-energy-core-integration", "energyhatch", true,
"When enabled, EnergyHatch can be used as an energy tower for the Draconic Evolution energy core and can automatically output energy at a rate that depends on the maximum rate in the configuration. Available only when Draconic Evolution is installed.");
searchRange = cfg.getInt("energy-core-search-range", "energyhatch", 16, 1, 64,
"How many energy cores within a radius does EnergyHatch look for?");
delayedEnergyCoreSearch = cfg.getBoolean("delayed-energy-core-search", "energyhatch", true,
"When enabled, the search interval grows gradually when EnergyHatch fails to find the energy core.");
energyCoreSearchDelay = cfg.getInt("energy-core-search-delay", "energyhatch", 100, 1, 1200,
"The minimum energy core search interval. (TimeUnit: Tick)");
maxEnergyCoreSearchDelay = cfg.getInt("max-energy-core-search-delay", "energyhatch", 300, 2, 1200,
"The maximum energy core search interval. (TimeUnit: Tick)");

if (energyCoreSearchDelay >= maxEnergyCoreSearchDelay) {
ModularMachinery.log.warn("energy-core-search-delay is bigger than or equal max-energy-core-search-delay!, use default value...");
energyCoreSearchDelay = 100;
maxEnergyCoreSearchDelay = 300;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import hellfirepvp.modularmachinery.ModularMachinery;
import hellfirepvp.modularmachinery.client.util.EnergyDisplayUtil;
import hellfirepvp.modularmachinery.common.base.Mods;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchSize;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchData;
import hellfirepvp.modularmachinery.common.block.prop.FluidHatchSize;
import hellfirepvp.modularmachinery.common.integration.ModIntegrationTOP;
import hellfirepvp.modularmachinery.common.machine.RecipeFailureActions;
Expand Down Expand Up @@ -47,7 +47,7 @@ public static void loadFrom(File file) {

private static void load() {
FluidHatchSize.loadFromConfig(lastReadConfig);
EnergyHatchSize.loadFromConfig(lastReadConfig);
EnergyHatchData.loadFromConfig(lastReadConfig);
EnergyDisplayUtil.loadFromConfig(lastReadConfig);
CatalystNameUtil.loadFromConfig(lastReadConfig);
RecipeFailureActions.loadFromConfig(lastReadConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

package hellfirepvp.modularmachinery.common.tiles;

import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchSize;
import com.brandon3055.draconicevolution.blocks.tileentity.TileEnergyStorageCore;
import hellfirepvp.modularmachinery.common.base.Mods;
import hellfirepvp.modularmachinery.common.block.prop.EnergyHatchData;
import hellfirepvp.modularmachinery.common.integration.IntegrationIC2EventHandlerHelper;
import hellfirepvp.modularmachinery.common.machine.IOType;
import hellfirepvp.modularmachinery.common.machine.MachineComponent;
Expand All @@ -18,13 +20,16 @@
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergyEmitter;
import ic2.api.energy.tile.IEnergySink;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Optional;

import javax.annotation.Nullable;

import static hellfirepvp.modularmachinery.common.block.prop.EnergyHatchData.*;

/**
* This class is part of the Modular Machinery Mod
* The complete source code for this mod can be found on github.
Expand All @@ -34,11 +39,10 @@
*/
@Optional.Interface(iface = "ic2.api.energy.tile.IEnergySink", modid = "ic2")
public class TileEnergyInputHatch extends TileEnergyHatch implements IEnergySink {

public TileEnergyInputHatch() {
}

public TileEnergyInputHatch(EnergyHatchSize size) {
public TileEnergyInputHatch(EnergyHatchData size) {
super(size, IOType.INPUT);
}

Expand All @@ -54,6 +58,41 @@ public boolean canReceive() {

@Override
public void update() {
if (world.isRemote) {
return;
}

long maxCanReceive = Math.min(this.size.transferLimit, this.size.maxEnergy - this.energy);
if (maxCanReceive <= 0) {
return;
}

if (Mods.DRACONICEVOLUTION.isPresent() && enableDEIntegration) {
long received = attemptDECoreTransfer(maxCanReceive);
if (received != 0) {
this.energy += received;
markForUpdate();
}
}
}

@Optional.Method(modid = "draconicevolution")
protected long attemptDECoreTransfer(long maxCanReceive) {
TileEntity te = foundCore == null ? null : world.getTileEntity(foundCore);
if (foundCore == null || !(te instanceof TileEnergyStorageCore)) {
foundCore = null;
findCore();
}

if (foundCore != null && te instanceof TileEnergyStorageCore) {
TileEnergyStorageCore core = (TileEnergyStorageCore) te;

long received = Math.min(core.energy.value, maxCanReceive);
core.energy.value -= received;

return received;
}
return 0;
}

@Override
Expand Down
Loading

0 comments on commit 9fcb9c3

Please sign in to comment.