Skip to content

Commit a2d4b68

Browse files
committed
Adding a energy loss across distance
Also i noticed that Wireless Syncs behave quite badly when a receiving pair exists, but doesn't accept energy. Don't worry, it doesn't waste any energy, but the sending device reduces (divides) its income by the amount of notworking pairs. I'm trying to find a solution.
1 parent 86679db commit a2d4b68

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

makmods/levelstorage/logic/BlockLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public int getDistance(BlockLocation other) {
6262
* @param distance Distance
6363
* @return energy discount
6464
*/
65-
public int getEnergyDiscount(int energy, int distance) {
65+
public static int getEnergyDiscount(int energy, int distance) {
6666
// Cross-Dimensional
6767
if (distance == Integer.MAX_VALUE)
6868
return (int)(energy * 0.25f);

makmods/levelstorage/tileentity/TileEntityWirelessConductor.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import makmods.levelstorage.ModBlocks;
1212
import makmods.levelstorage.gui.SlotFrequencyCard;
1313
import makmods.levelstorage.item.ItemFrequencyCard;
14+
import makmods.levelstorage.logic.BlockLocation;
1415
import makmods.levelstorage.registry.ConductorType;
1516
import makmods.levelstorage.registry.IWirelessConductor;
1617
import makmods.levelstorage.registry.WirelessConductorRegistry;
@@ -117,8 +118,17 @@ public int demandsEnergy() {
117118
@Override
118119
public int injectEnergy(Direction directionFrom, int amount) {
119120
if (this.type == ConductorType.SOURCE) {
120-
if (this.safePair != null)
121-
return this.safePair.receiveEnergy(amount);
121+
if (this.safePair != null) {
122+
BlockLocation thisTe = new BlockLocation(this.getDimId(),
123+
this.getX(), this.getY(), this.getZ());
124+
BlockLocation pairTe = new BlockLocation(
125+
this.safePair.getDimId(), this.safePair.getX(),
126+
this.safePair.getY(), this.safePair.getZ());
127+
int amtWithDisc = amount
128+
- BlockLocation.getEnergyDiscount(amount,
129+
thisTe.getDistance(pairTe));
130+
return this.safePair.receiveEnergy(amtWithDisc);
131+
}
122132
}
123133
return amount;
124134
}
@@ -235,7 +245,7 @@ public IWirelessConductor getSafePair() {
235245

236246
@Override
237247
public void updateEntity() {
238-
248+
239249
if (!this.addedToENet) {
240250
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
241251
this.addedToENet = true;

makmods/levelstorage/tileentity/TileEntityWirelessPowerSynchronizer.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import ic2.api.energy.tile.IEnergyTile;
1010
import ic2.api.tile.IWrenchable;
1111
import makmods.levelstorage.ModBlocks;
12+
import makmods.levelstorage.logic.BlockLocation;
1213
import makmods.levelstorage.logic.Helper;
1314
import makmods.levelstorage.registry.IWirelessPowerSync;
1415
import makmods.levelstorage.registry.SyncType;
@@ -244,7 +245,13 @@ public int sendEnergyEqually(int amount) {
244245
}
245246

246247
for (IWirelessPowerSync s : this.pairs) {
247-
energyNotUsed += s.receiveEnergy(forEach);
248+
BlockLocation thisTe = new BlockLocation(this.getWorld().provider.dimensionId,
249+
this.getX(), this.getY(), this.getZ());
250+
BlockLocation pairTe = new BlockLocation(
251+
s.getWorld().provider.dimensionId, s.getX(),
252+
s.getY(), s.getZ());
253+
int forEachWithDisc = forEach - BlockLocation.getEnergyDiscount(forEach, thisTe.getDistance(pairTe));
254+
energyNotUsed += s.receiveEnergy(forEachWithDisc);
248255
}
249256
return energyNotUsed;
250257
}

0 commit comments

Comments
 (0)