Skip to content

Commit 7647e86

Browse files
committed
Unfinished remaking of the Energy module.
2 new energy systems making use of the new catalyst block networks: - Simple: Operates on simple numeric energy values. - Electric: Incorporates voltage tiers, amperage and loss over distance into the energy network (incomplete).
1 parent 8c1fd5f commit 7647e86

34 files changed

+1043
-0
lines changed

energy/src/main/java/sunsetsatellite/catalyst/CatalystEnergy.java

+23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import net.minecraft.core.data.tag.Tag;
66
import org.slf4j.Logger;
77
import org.slf4j.LoggerFactory;
8+
import sunsetsatellite.catalyst.energy.improved.simple.test.tile.TileEntityBatteryBox;
9+
import sunsetsatellite.catalyst.energy.improved.simple.test.tile.TileEntitySimpleGenerator;
10+
import sunsetsatellite.catalyst.energy.improved.simple.test.tile.TileEntityWire;
11+
import turniplabs.halplibe.helper.EntityHelper;
812
import turniplabs.halplibe.util.TomlConfigHandler;
913
import turniplabs.halplibe.util.toml.Toml;
1014

@@ -16,6 +20,21 @@ public class CatalystEnergy implements ModInitializer {
1620

1721
public static final Tag<Block> ENERGY_CONDUITS_CONNECT = Tag.of("energy_conduits_connect");
1822

23+
/*public static final BlockWire wire = new BlockBuilder(MOD_ID)
24+
.setTextures("catalyst-energy:block/wire")
25+
.build(new BlockWire("wire",1550));
26+
public static final BlockBatteryBox box = new BlockBuilder(MOD_ID)
27+
.setTextures("catalyst-energy:block/battery_box")
28+
.build(new BlockBatteryBox("box",1551));
29+
public static final BlockSimpleGenerator generator = new BlockBuilder(MOD_ID)
30+
.setTextures("catalyst-energy:block/machine_side")
31+
.setSouthTexture("catalyst-energy:block/generator")
32+
.build(new BlockSimpleGenerator("generator",1552));
33+
public static final BlockSimpleMachine machine = new BlockBuilder(MOD_ID)
34+
.setTextures("catalyst-energy:block/machine_side")
35+
.setSouthTexture("catalyst-energy:block/machine")
36+
.build(new BlockSimpleMachine("machine",1553));*/
37+
1938
static {
2039
Toml configToml = new Toml("Catalyst: Energy configuration file.");
2140
configToml.addEntry("energyName","Energy");
@@ -39,6 +58,10 @@ public static double map(double valueCoord1,
3958
}
4059
@Override
4160
public void onInitialize() {
61+
EntityHelper.createTileEntity(TileEntityBatteryBox.class,"BatteryBox");
62+
EntityHelper.createTileEntity(TileEntitySimpleGenerator.class,"SimpleGenerator");
63+
EntityHelper.createTileEntity(TileEntitySimpleGenerator.class,"SimpleMachine");
64+
EntityHelper.createTileEntity(TileEntityWire.class,"Wire");
4265
LOGGER.info("Catalyst: Energy initialized.");
4366
}
4467
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @deprecated Use classes inside the <code>improved</code> package instead.
3+
*/
4+
@Deprecated
5+
package sunsetsatellite.catalyst.energy.api;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @deprecated Use classes inside the <code>improved</code> package instead.
3+
*/
4+
@Deprecated
5+
package sunsetsatellite.catalyst.energy.impl;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package sunsetsatellite.catalyst.energy.improved.electric.api;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
import sunsetsatellite.catalyst.core.util.Direction;
5+
6+
public interface IElectric {
7+
/**
8+
* @param dir Direction to check
9+
* @return <code>true</code> if container can receive energy from <code>dir</code>, <code>false</code> otherwise
10+
*/
11+
boolean canReceive(@NotNull Direction dir);
12+
/**
13+
* @param dir Direction to check
14+
* @return <code>true</code> if container can provide energy to <code>dir</code>, <code>false</code> otherwise
15+
*/
16+
default boolean canProvide(@NotNull Direction dir) { return false; }
17+
18+
/**
19+
* @return Amount of energy currently available in container
20+
*/
21+
long getEnergy();
22+
/**
23+
* @return Maximum energy capacity of the container.
24+
*/
25+
long getCapacity();
26+
27+
/**
28+
* @return Amount of unused capacity left
29+
*/
30+
default long getCapacityRemaining() {
31+
return getCapacity() - getEnergy();
32+
}
33+
34+
/**
35+
* @return Maximum voltage this container can handle
36+
*/
37+
long getMaxInputVoltage();
38+
39+
/**
40+
* @return Maximum amount of amps this machine can use
41+
*/
42+
long getMaxInputAmperage();
43+
44+
/**
45+
* @return Maximum voltage this container can maintain
46+
*/
47+
long getMaxOutputVoltage();
48+
49+
/**
50+
* @return Maximum amperage this container can deliver
51+
*/
52+
long getMaxOutputAmperage();
53+
54+
/**
55+
* Changes energy amount in container.
56+
* @param difference Amount of energy changed, will remove energy if negative
57+
* @return Amount of energy actually changed.
58+
*/
59+
long internalChangeEnergy(long difference);
60+
61+
/**
62+
* Adds energy to container.
63+
* @param energy Amount of energy to be added
64+
* @return Amount of energy actually added
65+
*/
66+
default long internalAddEnergy(long energy) {
67+
return internalChangeEnergy(energy);
68+
}
69+
70+
/**
71+
* Removes energy from the container.
72+
* @param energy Amount of energy to be removed
73+
* @return Amount of energy actually removed
74+
*/
75+
default long internalRemoveEnergy(long energy) {
76+
return internalChangeEnergy(-energy);
77+
}
78+
79+
/**
80+
* @return Amperage currently being used
81+
*/
82+
long getAmpsCurrentlyUsed();
83+
84+
void addAmpUsage(long amperage);
85+
86+
/**
87+
* Only this method should be to pass energy in blocks, handles both voltage and amperage.
88+
* @param dir Direction of receive
89+
* @param amperage Receiving amperage
90+
* @return Amps used
91+
*/
92+
long receiveEnergy(@NotNull Direction dir, long amperage);
93+
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package sunsetsatellite.catalyst.energy.improved.electric.api;
2+
3+
import net.minecraft.core.net.command.TextFormatting;
4+
5+
public enum VoltageTier {
6+
ULV("Ultra Low Voltage",1,8, TextFormatting.GRAY),
7+
LV("Low Voltage",9,32, TextFormatting.RED),
8+
MV("Medium Voltage",33,128, TextFormatting.ORANGE),
9+
HV("High Voltage",129,512, TextFormatting.YELLOW),
10+
EV("Extreme Voltage",513,1024, TextFormatting.BLUE),
11+
UV("Ultra Voltage",1025,2048, TextFormatting.PURPLE),
12+
OV("Over Voltage",2049,Integer.MAX_VALUE, TextFormatting.MAGENTA);
13+
14+
VoltageTier(String voltageName, int minVoltage, int maxVoltage, TextFormatting color){
15+
this.voltageName = voltageName;
16+
this.minVoltage = minVoltage;
17+
this.maxVoltage = maxVoltage;
18+
this.color = color;
19+
}
20+
21+
public final String voltageName;
22+
public final int minVoltage;
23+
public final int maxVoltage;
24+
public final TextFormatting color;
25+
26+
public static VoltageTier get(int voltage){
27+
for (VoltageTier tier : values()) {
28+
if(voltage >= tier.minVoltage && voltage <= tier.maxVoltage){
29+
return tier;
30+
}
31+
}
32+
return null;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package sunsetsatellite.catalyst.energy.improved.electric.api;
2+
3+
public class WireMaterial {
4+
private final String name;
5+
private final String identifier;
6+
private final int color;
7+
private final VoltageTier maxVoltage;
8+
private final int defaultAmps;
9+
private final int lossPerBlock;
10+
private final int meltingTemperature;
11+
12+
13+
public WireMaterial(String name, String identifier, int color, int defaultAmps, VoltageTier maxVoltage, int lossPerBlock, int meltingTemperature) {
14+
this.name = name;
15+
this.identifier = identifier;
16+
this.color = color;
17+
this.maxVoltage = maxVoltage;
18+
this.defaultAmps = defaultAmps;
19+
this.lossPerBlock = lossPerBlock;
20+
this.meltingTemperature = meltingTemperature;
21+
}
22+
23+
public String getName() {
24+
return name;
25+
}
26+
27+
public int getMeltingTemperature() {
28+
return meltingTemperature;
29+
}
30+
31+
public VoltageTier getMaxVoltage() {
32+
return maxVoltage;
33+
}
34+
35+
public int getLossPerBlock() {
36+
return lossPerBlock;
37+
}
38+
39+
public String getIdentifier() {
40+
return identifier;
41+
}
42+
43+
public int getDefaultAmps() {
44+
return defaultAmps;
45+
}
46+
47+
public int getColor() {
48+
return color;
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package sunsetsatellite.catalyst.energy.improved.electric.api;
2+
3+
public class WireProperties {
4+
5+
private final int size;
6+
private final boolean insulated;
7+
private final boolean superconductor;
8+
private final WireMaterial material;
9+
10+
public WireProperties(int size, boolean insulated, boolean superconductor, WireMaterial material) {
11+
this.size = size;
12+
this.insulated = insulated;
13+
this.superconductor = superconductor;
14+
this.material = material;
15+
}
16+
17+
public int getSize() {
18+
return size;
19+
}
20+
21+
public boolean isSuperconductor() {
22+
return superconductor;
23+
}
24+
25+
public WireMaterial getMaterial() {
26+
return material;
27+
}
28+
29+
public boolean isInsulated() {
30+
return insulated;
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package sunsetsatellite.catalyst.energy.improved.electric.base;
2+
3+
import net.minecraft.core.block.entity.TileEntity;
4+
import sunsetsatellite.catalyst.core.util.Direction;
5+
import sunsetsatellite.catalyst.core.util.Vec3i;
6+
import sunsetsatellite.catalyst.core.util.network.Network;
7+
import sunsetsatellite.catalyst.core.util.network.NetworkComponentTile;
8+
import sunsetsatellite.catalyst.core.util.network.NetworkType;
9+
import sunsetsatellite.catalyst.energy.improved.electric.api.IElectric;
10+
11+
12+
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
13+
public abstract class TileEntityElectricBase extends TileEntity implements IElectric, NetworkComponentTile {
14+
15+
protected long energy = 0;
16+
protected long capacity = 0;
17+
18+
protected long maxVoltageIn = 0;
19+
protected long maxAmpsIn = 0;
20+
21+
protected long maxVoltageOut = 0;
22+
protected long maxAmpsOut = 0;
23+
24+
protected long ampsUsing = 0;
25+
26+
public TileEntityElectricBase() {}
27+
28+
//IEnergyContainer
29+
@Override
30+
public long getEnergy() {
31+
return energy;
32+
}
33+
34+
@Override
35+
public long getCapacity() {
36+
return capacity;
37+
}
38+
39+
@Override
40+
public long getMaxInputVoltage() {
41+
return maxVoltageIn;
42+
}
43+
44+
@Override
45+
public long getMaxInputAmperage() {
46+
return maxAmpsIn;
47+
}
48+
49+
@Override
50+
public long getMaxOutputVoltage() {
51+
return maxVoltageOut;
52+
}
53+
54+
@Override
55+
public long getMaxOutputAmperage() {
56+
return maxAmpsOut;
57+
}
58+
59+
@Override
60+
public long internalChangeEnergy(long difference) {
61+
energy += difference;
62+
return difference;
63+
}
64+
65+
@Override
66+
public long getAmpsCurrentlyUsed() {
67+
return ampsUsing;
68+
}
69+
70+
@Override
71+
public void addAmpUsage(long amperage) {
72+
ampsUsing += amperage;
73+
}
74+
75+
//NetworkComponent
76+
public Network energyNet;
77+
78+
@Override
79+
public NetworkType getType() {
80+
return NetworkType.ELECTRIC;
81+
}
82+
83+
@Override
84+
public Vec3i getPosition() {
85+
return new Vec3i(x,y,z);
86+
}
87+
88+
@Override
89+
public boolean isConnected(Direction direction) {
90+
return direction.getTileEntity(worldObj,this) instanceof TileEntityElectricConductor;
91+
}
92+
93+
@Override
94+
public void networkChanged(Network network) {
95+
this.energyNet = network;
96+
}
97+
98+
@Override
99+
public void removedFromNetwork(Network network) {
100+
this.energyNet = null;
101+
}
102+
}

0 commit comments

Comments
 (0)