mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-16 13:23:07 +00:00
more fabric stuff
This commit is contained in:
@@ -33,6 +33,7 @@ public class DamageFunction implements LootFunction {
|
||||
*/
|
||||
@Override
|
||||
public ItemStack apply(ItemStack original, Random r) {
|
||||
if(!(original instanceof Damageable)) return original;
|
||||
double itemDurability = (r.nextDouble() * (max - min)) + min;
|
||||
Damageable damage = (Damageable) original.getItemMeta();
|
||||
damage.setDamage((int) (original.getType().getMaxDurability() - (itemDurability / 100) * original.getType().getMaxDurability()));
|
||||
|
||||
@@ -35,6 +35,8 @@ public class EnchantFunction implements LootFunction {
|
||||
*/
|
||||
@Override
|
||||
public ItemStack apply(ItemStack original, Random r) {
|
||||
if(original.getItemMeta() == null) return original;
|
||||
|
||||
double enchant = (r.nextDouble() * (max - min)) + min;
|
||||
List<Enchantment> possible = new GlueList<>();
|
||||
for(Enchantment ench : main.getItemHandle().getEnchantments()) {
|
||||
|
||||
@@ -123,6 +123,7 @@ public class StructureScript {
|
||||
private StructureBuffer computeBuffer(Location location, Random random, Rotation rotation) {
|
||||
try {
|
||||
return cache.get(location, () -> {
|
||||
System.out.println("{" + FastMath.floorDiv(location.getBlockX(), 16) + ", " + FastMath.floorDiv(location.getBlockZ(), 16) + "} : " + cache.size() + " : " + location.hashCode());
|
||||
StructureBuffer buf = new StructureBuffer(location);
|
||||
buf.setSucceeded(applyBlock(new TerraImplementationArguments(buf, rotation, random, 0)));
|
||||
return buf;
|
||||
|
||||
@@ -23,9 +23,11 @@ public class BlockFunction implements Function<Void> {
|
||||
private final Returnable<Number> x, y, z;
|
||||
private final Position position;
|
||||
private final Returnable<Boolean> overwrite;
|
||||
private final TerraPlugin main;
|
||||
|
||||
public BlockFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Returnable<String> data, Returnable<Boolean> overwrite, TerraPlugin main, Position position) throws ParseException {
|
||||
this.position = position;
|
||||
this.main = main;
|
||||
if(!(data instanceof ConstantExpression)) throw new ParseException("Block data must be constant", data.getPosition());
|
||||
|
||||
try {
|
||||
@@ -49,7 +51,7 @@ public class BlockFunction implements Function<Void> {
|
||||
RotationUtil.rotateVector(xz, arguments.getRotation());
|
||||
|
||||
RotationUtil.rotateBlockData(rot, arguments.getRotation().inverse());
|
||||
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap)), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
|
||||
arguments.getBuffer().addItem(new BufferedBlock(rot, overwrite.apply(implementationArguments, variableMap), main), new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments, variableMap).doubleValue(), FastMath.roundToInt(xz.getZ())).toLocation(arguments.getBuffer().getOrigin().getWorld()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,11 @@ public class StructureBuffer implements Buffer {
|
||||
}
|
||||
|
||||
public void paste(Chunk chunk) {
|
||||
bufferedItemMap.forEach(((vector3, item) -> {
|
||||
Location current = origin.clone().add(vector3);
|
||||
bufferedItemMap.forEach(((location, item) -> {
|
||||
Location current = origin.clone().add(location);
|
||||
if(FastMath.floorDiv(current.getBlockX(), 16) != chunk.getX() || FastMath.floorDiv(current.getBlockZ(), 16) != chunk.getZ())
|
||||
return;
|
||||
item.paste(origin.clone().add(vector3));
|
||||
item.paste(current);
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.dfsek.terra.api.structures.structure.buffer.items;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.block.Block;
|
||||
import com.dfsek.terra.api.platform.block.BlockData;
|
||||
@@ -7,15 +8,22 @@ import com.dfsek.terra.api.platform.block.BlockData;
|
||||
public class BufferedBlock implements BufferedItem {
|
||||
private final BlockData data;
|
||||
private final boolean overwrite;
|
||||
private final TerraPlugin main;
|
||||
|
||||
public BufferedBlock(BlockData data, boolean overwrite) {
|
||||
public BufferedBlock(BlockData data, boolean overwrite, TerraPlugin main) {
|
||||
this.data = data;
|
||||
this.overwrite = overwrite;
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paste(Location origin) {
|
||||
Block block = origin.getBlock();
|
||||
if(overwrite || block.isEmpty()) block.setBlockData(data, false);
|
||||
try {
|
||||
if(overwrite || block.isEmpty()) block.setBlockData(data, false);
|
||||
} catch(RuntimeException e) {
|
||||
main.logger().severe("Failed to place block at location " + origin + ": " + e.getMessage());
|
||||
main.getDebugLogger().stack(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class StructurePopulator implements TerraBlockPopulator {
|
||||
if(!((UserDefinedBiome) provider.getBiome(spawn)).getConfig().getStructures().contains(conf))
|
||||
continue;
|
||||
Random random = new FastRandom(MathUtil.getCarverChunkSeed(FastMath.floorDiv(spawn.getBlockX(), 16), FastMath.floorDiv(spawn.getBlockZ(), 16), world.getSeed()));
|
||||
System.out.println("chunk: {" + chunk.getX() + ", " + chunk.getZ() + "}");
|
||||
conf.getStructure().get(random).execute(spawn.setY(conf.getSpawnStart().get(random)), chunk, random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user