PotentialCalculator .java

net.minecraft.world.level.PotentialCalculator (class, 45 lines): members: getPotentialEnergyChange, PointCharge, addCharge, charges. imports: Lists.

net.minecraft.world.levelclass45 linescommon1.1 KB

API Surface (3)

void addCharge(final BlockPos pos, final double charge)
double getPotentialEnergyChange(final BlockPos pos, final double charge)
double getPotentialChange(final BlockPos pos)

Fields & Constants (1)

charges

Code Graph: Dependencies (1)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

PotentialCalculator.java45 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.level;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.core.BlockPos;
6
7
public class PotentialCalculator {
8
	private final List<PotentialCalculator.PointCharge> charges = Lists.newArrayList();
9
10
	public void addCharge(final BlockPos pos, final double charge) {
11
		if (charge != 0.0) {
12
			this.charges.add(new PotentialCalculator.PointCharge(pos, charge));
13
		}
14
	}
15
16
	public double getPotentialEnergyChange(final BlockPos pos, final double charge) {
17
		if (charge == 0.0) {
18
			return 0.0;
19
		}
20
21
		double potentialChange = 0.0;
22
23
		for (PotentialCalculator.PointCharge point : this.charges) {
24
			potentialChange += point.getPotentialChange(pos);
25
		}
26
27
		return potentialChange * charge;
28
	}
29
30
	private static class PointCharge {
31
		private final BlockPos pos;
32
		private final double charge;
33
34
		public PointCharge(final BlockPos pos, final double charge) {
35
			this.pos = pos;
36
			this.charge = charge;
37
		}
38
39
		public double getPotentialChange(final BlockPos pos) {
40
			double distSqr = this.pos.distSqr(pos);
41
			return distSqr == 0.0 ? Double.POSITIVE_INFINITY : this.charge / Math.sqrt(distSqr);
42
		}
43
	}
44
}
45

Decompiled Minecraft 26.3 source of PotentialCalculator (net/minecraft/world/level/PotentialCalculator.java) with Mojang official mappings, stored verbatim on the site.