mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 02:20:57 +00:00
WIP Random Changes
This commit is contained in:
@@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Random;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.Parser;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Executable;
|
||||
@@ -131,14 +131,14 @@ public class StructureScript implements Structure, Keyed<StructureScript> {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation) {
|
||||
platform.getProfiler().push(profile);
|
||||
boolean result = applyBlock(new TerraImplementationArguments(location, rotation, random, world, 0));
|
||||
platform.getProfiler().pop(profile);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation, int recursions) {
|
||||
|
||||
public boolean generate(Vector3Int location, WritableWorld world, RandomGenerator random, Rotation rotation, int recursions) {
|
||||
platform.getProfiler().push(profile);
|
||||
boolean result = applyBlock(new TerraImplementationArguments(location, rotation, random, world, recursions));
|
||||
platform.getProfiler().pop(profile);
|
||||
|
||||
@@ -9,7 +9,7 @@ package com.dfsek.terra.addons.terrascript.script;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.api.util.Rotation;
|
||||
@@ -20,14 +20,14 @@ import com.dfsek.terra.api.world.WritableWorld;
|
||||
|
||||
public class TerraImplementationArguments implements ImplementationArguments {
|
||||
private final Rotation rotation;
|
||||
private final Random random;
|
||||
private final RandomGenerator random;
|
||||
private final WritableWorld world;
|
||||
private final Map<Vector3, String> marks = new HashMap<>();
|
||||
private final int recursions;
|
||||
private final Vector3Int origin;
|
||||
private boolean waterlog = false;
|
||||
|
||||
public TerraImplementationArguments(Vector3Int origin, Rotation rotation, Random random, WritableWorld world, int recursions) {
|
||||
|
||||
public TerraImplementationArguments(Vector3Int origin, Rotation rotation, RandomGenerator random, WritableWorld world, int recursions) {
|
||||
this.rotation = rotation;
|
||||
this.random = random;
|
||||
this.world = world;
|
||||
@@ -38,8 +38,8 @@ public class TerraImplementationArguments implements ImplementationArguments {
|
||||
public int getRecursions() {
|
||||
return recursions;
|
||||
}
|
||||
|
||||
public Random getRandom() {
|
||||
|
||||
public RandomGenerator getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ package com.dfsek.terra.addons.terrascript.script.functions;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.ImplementationArguments;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Returnable;
|
||||
import com.dfsek.terra.addons.terrascript.parser.lang.Scope;
|
||||
@@ -30,6 +28,9 @@ import com.dfsek.terra.api.util.RotationUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector2;
|
||||
import com.dfsek.terra.api.util.vector.Vector3;
|
||||
|
||||
import java.util.random.RandomGenerator;
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
|
||||
|
||||
public class LootFunction implements Function<Void> {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(LootFunction.class);
|
||||
@@ -64,34 +65,35 @@ public class LootFunction implements Function<Void> {
|
||||
|
||||
|
||||
registry.get(RegistryKey.parse(id))
|
||||
.ifPresentOrElse(table -> {
|
||||
Vector3 apply = Vector3.of((int) Math.round(xz.getX()),
|
||||
y.apply(implementationArguments, scope)
|
||||
.intValue(),
|
||||
(int) Math.round(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
|
||||
try {
|
||||
BlockEntity data = arguments.getWorld().getBlockEntity(apply);
|
||||
if(!(data instanceof Container container)) {
|
||||
LOGGER.error("Failed to place loot at {}; block {} is not a container",
|
||||
apply, data);
|
||||
return;
|
||||
}
|
||||
|
||||
LootPopulateEvent event = new LootPopulateEvent(container, table,
|
||||
arguments.getWorld().getPack(), script);
|
||||
platform.getEventManager().callEvent(event);
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
event.getTable().fillInventory(container.getInventory(),
|
||||
new Random(apply.hashCode()));
|
||||
data.update(false);
|
||||
} catch(Exception e) {
|
||||
LOGGER.error("Could not apply loot at {}", apply, e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
},
|
||||
() -> LOGGER.error("No such loot table {}", id));
|
||||
.ifPresentOrElse(table -> {
|
||||
Vector3 apply = Vector3.of(FastMath.roundToInt(xz.getX()),
|
||||
y.apply(implementationArguments, scope)
|
||||
.intValue(),
|
||||
FastMath.roundToInt(xz.getZ())).mutable().add(arguments.getOrigin()).immutable();
|
||||
|
||||
try {
|
||||
BlockEntity data = arguments.getWorld().getBlockEntity(apply);
|
||||
if(!(data instanceof Container container)) {
|
||||
LOGGER.error("Failed to place loot at {}; block {} is not a container",
|
||||
apply, data);
|
||||
return;
|
||||
}
|
||||
|
||||
LootPopulateEvent event = new LootPopulateEvent(container, table,
|
||||
arguments.getWorld().getPack(), script);
|
||||
platform.getEventManager().callEvent(event);
|
||||
if(event.isCancelled()) return;
|
||||
|
||||
event.getTable().fillInventory(container.getInventory(),
|
||||
RandomGeneratorFactory.<RandomGenerator.SplittableGenerator>of(
|
||||
"Xoroshiro128PlusPlus").create(apply.hashCode()));
|
||||
data.update(false);
|
||||
} catch(Exception e) {
|
||||
LOGGER.error("Could not apply loot at {}", apply, e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
},
|
||||
() -> LOGGER.error("No such loot table {}", id));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user