make Vector3 immutable by default

This commit is contained in:
dfsek
2021-12-20 00:37:54 -07:00
parent 961a42d1cb
commit b9965bdbc5
14 changed files with 343 additions and 235 deletions

View File

@@ -42,16 +42,18 @@ public class BiomeFunction implements Function<String> {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, variableMap).doubleValue(),
z.apply(implementationArguments, variableMap).doubleValue()), arguments.getRotation());
z.apply(implementationArguments, variableMap).doubleValue()),
arguments.getRotation());
BiomeProvider grid = arguments.getWorld().getBiomeProvider();
return grid.getBiome(arguments.getOrigin()
.toVector3()
.mutable()
.add(Vector3.of(FastMath.roundToInt(xz.getX()),
y.apply(implementationArguments, variableMap).intValue(),
FastMath.roundToInt(xz.getZ()))), arguments.getWorld().getSeed()).getID();
y.apply(implementationArguments, variableMap).intValue(),
FastMath.roundToInt(xz.getZ()))).immutable(), arguments.getWorld().getSeed()).getID();
}
@Override

View File

@@ -77,9 +77,9 @@ public class BlockFunction implements Function<Void> {
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
try {
Vector3 set = Vector3.of(FastMath.roundToInt(xz.getX()),
Vector3.Mutable set = Vector3.of(FastMath.roundToInt(xz.getX()),
y.apply(implementationArguments, variableMap).doubleValue(),
FastMath.roundToInt(xz.getZ())).add(arguments.getOrigin());
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
BlockState current = arguments.getWorld().getBlockState(set);
if(overwrite.apply(implementationArguments, variableMap) || current.isAir()) {
if(arguments.isWaterlog() && current.has(Properties.WATERLOGGED) && current.getBlockType().isWater()) {

View File

@@ -37,17 +37,19 @@ public class CheckBlockFunction implements Function<String> {
@Override
public String apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, variableMap).doubleValue(),
z.apply(implementationArguments, variableMap).doubleValue()), arguments.getRotation());
z.apply(implementationArguments, variableMap).doubleValue()),
arguments.getRotation());
String data = arguments.getWorld()
.getBlockState(arguments.getOrigin()
.toVector3()
.mutable()
.add(Vector3.of(FastMath.roundToInt(xz.getX()),
y.apply(implementationArguments, variableMap)
.doubleValue(), FastMath.roundToInt(xz.getZ()))))
y.apply(implementationArguments, variableMap)
.doubleValue(), FastMath.roundToInt(xz.getZ()))))
.getAsString();
if(data.contains("[")) return data.substring(0, data.indexOf('[')); // Strip properties
else return data;

View File

@@ -50,7 +50,7 @@ public class EntityFunction implements Function<Void> {
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, variableMap).doubleValue(),
z.apply(implementationArguments, variableMap).doubleValue()), arguments.getRotation());
Entity entity = arguments.getWorld().spawnEntity(Vector3.of(xz.getX(), y.apply(implementationArguments, variableMap).doubleValue(), xz.getZ()).add(arguments.getOrigin()).add(0.5, 0, 0.5), data);
Entity entity = arguments.getWorld().spawnEntity(Vector3.of(xz.getX(), y.apply(implementationArguments, variableMap).doubleValue(), xz.getZ()).mutable().add(arguments.getOrigin()).add(0.5, 0, 0.5).immutable(), data);
platform.getEventManager().callEvent(new EntitySpawnEvent(entity.world().getPack(), entity));
return null;
}

View File

@@ -40,7 +40,7 @@ public class GetMarkFunction implements Function<String> {
z.apply(implementationArguments, variableMap).doubleValue()), arguments.getRotation());
String mark = arguments.getMark(Vector3.of(FastMath.floorToInt(xz.getX()), FastMath.floorToInt(
y.apply(implementationArguments, variableMap).doubleValue()), FastMath.floorToInt(xz.getZ())).add(arguments.getOrigin()));
y.apply(implementationArguments, variableMap).doubleValue()), FastMath.floorToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable());
return mark == null ? "" : mark;
}

View File

@@ -59,9 +59,10 @@ public class LootFunction implements Function<Void> {
public Void apply(ImplementationArguments implementationArguments, Map<String, Variable<?>> variableMap) {
TerraImplementationArguments arguments = (TerraImplementationArguments) implementationArguments;
Vector2 xz = RotationUtil.rotateVector(Vector2.of(x.apply(implementationArguments, variableMap).doubleValue(),
z.apply(implementationArguments, variableMap).doubleValue()), arguments.getRotation());
z.apply(implementationArguments, variableMap).doubleValue()),
arguments.getRotation());
String id = data.apply(implementationArguments, variableMap);
@@ -70,8 +71,8 @@ public class LootFunction implements Function<Void> {
Vector3 apply = Vector3.of(FastMath.roundToInt(xz.getX()),
y.apply(implementationArguments, variableMap)
.intValue(),
FastMath.roundToInt(xz.getZ())).add(arguments.getOrigin());
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
try {
BlockEntity data = arguments.getWorld().getBlockEntity(apply);
if(!(data instanceof Container container)) {

View File

@@ -51,8 +51,8 @@ public class PullFunction implements Function<Void> {
BlockState rot = data.clone();
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
Vector3 mutable = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(),
FastMath.roundToInt(xz.getZ())).add(arguments.getOrigin());
Vector3.Mutable mutable = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(),
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin());
while(mutable.getY() > arguments.getWorld().getMinHeight()) {
if(!arguments.getWorld().getBlockState(mutable).isAir()) {
arguments.getWorld().setBlockState(mutable, rot);

View File

@@ -45,7 +45,7 @@ public class SetMarkFunction implements Function<Void> {
arguments.setMark(Vector3.of(FastMath.floorToInt(xz.getX()),
FastMath.floorToInt(
y.apply(implementationArguments, variableMap).doubleValue()),
FastMath.floorToInt(xz.getZ())).add(arguments.getOrigin()), mark.apply(implementationArguments, variableMap));
FastMath.floorToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable(), mark.apply(implementationArguments, variableMap));
return null;
}

View File

@@ -50,7 +50,7 @@ public class StateFunction implements Function<Void> {
Vector3 origin = Vector3.of(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).intValue(),
FastMath.roundToInt(xz.getZ())).add(arguments.getOrigin());
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
try {
BlockEntity state = arguments.getWorld().getBlockEntity(origin);
state.applyState(data.apply(implementationArguments, variableMap));