mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-03 06:16:10 +00:00
create and register PointSetDistributor
This commit is contained in:
@@ -2,6 +2,9 @@ package com.dfsek.terra.addons.feature.distributor;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.config.NoiseDistributorTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.config.PointSetDistributorTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.addons.feature.distributor.util.PointTemplate;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
@@ -33,5 +36,9 @@ public class DistributorAddon extends TerraAddon implements EventListener {
|
||||
public void packPreLoad(ConfigPackPreLoadEvent event) {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Distributor>>> distributorRegistry = event.getPack().getOrCreateRegistry(DISTRIBUTOR_TOKEN);
|
||||
distributorRegistry.register("NOISE", NoiseDistributorTemplate::new);
|
||||
distributorRegistry.register("POINTS", PointSetDistributorTemplate::new);
|
||||
|
||||
event.getPack()
|
||||
.applyLoader(Point.class, PointTemplate::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.distributors.PointSetDistributor;
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class PointSetDistributorTemplate implements ObjectTemplate<Distributor> {
|
||||
@Value("points")
|
||||
private Set<Point> points;
|
||||
|
||||
@Override
|
||||
public Distributor get() {
|
||||
return new PointSetDistributor(points);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.distributors;
|
||||
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class PointSetDistributor implements Distributor {
|
||||
private final Set<Point> points;
|
||||
|
||||
public PointSetDistributor(Set<Point> points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int z, long seed) {
|
||||
return points.contains(new Point(x, z));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.util;
|
||||
|
||||
public class Point {
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
private final int hash;
|
||||
|
||||
public Point(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.hash = 31 * x + z;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Point)) return false;
|
||||
Point that = (Point) obj;
|
||||
return this.x == that.x && this.z == that.z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.util;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
public class PointTemplate implements ObjectTemplate<Point> {
|
||||
@Value("x")
|
||||
private int x;
|
||||
|
||||
@Value("z")
|
||||
private int z;
|
||||
|
||||
@Override
|
||||
public Point get() {
|
||||
return new Point(x, z);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user