mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-17 14:21:08 +00:00
implement getUngeneratedBlock
This commit is contained in:
@@ -1,10 +1,17 @@
|
|||||||
package com.dfsek.terra;
|
package com.dfsek.terra;
|
||||||
|
|
||||||
|
import com.dfsek.terra.api.math.vector.Location;
|
||||||
|
import com.dfsek.terra.api.math.vector.Vector3;
|
||||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||||
|
import com.dfsek.terra.api.platform.block.BlockData;
|
||||||
import com.dfsek.terra.api.platform.generator.GeneratorWrapper;
|
import com.dfsek.terra.api.platform.generator.GeneratorWrapper;
|
||||||
import com.dfsek.terra.api.platform.world.World;
|
import com.dfsek.terra.api.platform.world.World;
|
||||||
|
import com.dfsek.terra.api.world.palette.Palette;
|
||||||
import com.dfsek.terra.biome.BiomeProvider;
|
import com.dfsek.terra.biome.BiomeProvider;
|
||||||
|
import com.dfsek.terra.biome.UserDefinedBiome;
|
||||||
import com.dfsek.terra.config.base.ConfigPack;
|
import com.dfsek.terra.config.base.ConfigPack;
|
||||||
|
import com.dfsek.terra.generation.math.Sampler;
|
||||||
|
import net.jafama.FastMath;
|
||||||
|
|
||||||
public class TerraWorld {
|
public class TerraWorld {
|
||||||
private final BiomeProvider provider;
|
private final BiomeProvider provider;
|
||||||
@@ -12,6 +19,7 @@ public class TerraWorld {
|
|||||||
private final boolean safe;
|
private final boolean safe;
|
||||||
private final TerraProfiler profiler;
|
private final TerraProfiler profiler;
|
||||||
private final World world;
|
private final World world;
|
||||||
|
private final BlockData air;
|
||||||
|
|
||||||
|
|
||||||
public TerraWorld(World w, ConfigPack c, TerraPlugin main) {
|
public TerraWorld(World w, ConfigPack c, TerraPlugin main) {
|
||||||
@@ -19,6 +27,7 @@ public class TerraWorld {
|
|||||||
profiler = new TerraProfiler(w);
|
profiler = new TerraProfiler(w);
|
||||||
this.provider = config.getTemplate().getProviderBuilder().build(w.getSeed());
|
this.provider = config.getTemplate().getProviderBuilder().build(w.getSeed());
|
||||||
this.world = w;
|
this.world = w;
|
||||||
|
air = main.getWorldHandle().createBlockData("minecraft:air");
|
||||||
safe = true;
|
safe = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,4 +54,39 @@ public class TerraWorld {
|
|||||||
public TerraProfiler getProfiler() {
|
public TerraProfiler getProfiler() {
|
||||||
return profiler;
|
return profiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a block at an ungenerated location
|
||||||
|
*
|
||||||
|
* @param x X coordinate
|
||||||
|
* @param y Y coordinate
|
||||||
|
* @param z Z coordinate
|
||||||
|
* @return BlockData
|
||||||
|
*/
|
||||||
|
public BlockData getUngeneratedBlock(int x, int y, int z) {
|
||||||
|
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome(x, z);
|
||||||
|
Palette<BlockData> palette = biome.getGenerator(world).getPalette(y);
|
||||||
|
Sampler sampler = config.getSamplerCache().get(world, x, z);
|
||||||
|
int fdX = FastMath.floorMod(x, 16);
|
||||||
|
int fdZ = FastMath.floorMod(z, 16);
|
||||||
|
double noise = sampler.sample(fdX, y, fdZ);
|
||||||
|
if(noise > 0) {
|
||||||
|
int level = 0;
|
||||||
|
for(int yi = world.getMaxHeight(); yi > y; yi--) {
|
||||||
|
if(sampler.sample(fdX, yi, fdZ) > 0) level++;
|
||||||
|
else level = 0;
|
||||||
|
}
|
||||||
|
return palette.get(level, x, y, z);
|
||||||
|
} else if(y <= biome.getConfig().getSeaLevel()) {
|
||||||
|
return biome.getConfig().getOceanPalette().get(biome.getConfig().getSeaLevel() - y, x, y, z);
|
||||||
|
} else return air;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockData getUngeneratedBlock(Location l) {
|
||||||
|
return getUngeneratedBlock(l.getBlockX(), l.getBlockY(), l.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockData getUngeneratedBlock(Vector3 v) {
|
||||||
|
return getUngeneratedBlock(v.getBlockX(), v.getBlockY(), v.getBlockZ());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+44
@@ -0,0 +1,44 @@
|
|||||||
|
package com.dfsek.terra.bukkit.command.command;
|
||||||
|
|
||||||
|
import com.dfsek.terra.bukkit.command.WorldCommand;
|
||||||
|
import com.dfsek.terra.bukkit.world.BukkitAdapter;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GetBlockCommand extends WorldCommand {
|
||||||
|
public GetBlockCommand(com.dfsek.terra.bukkit.command.Command parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(@NotNull Player player, @NotNull Command command, @NotNull String s, @NotNull String[] strings, World world) {
|
||||||
|
player.sendMessage("Block: " + getMain().getWorld(BukkitAdapter.adapt(world)).getUngeneratedBlock(BukkitAdapter.adapt(player.getLocation())).getAsString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "block";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<com.dfsek.terra.bukkit.command.Command> getSubCommands() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int arguments() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getTabCompletions(@NotNull CommandSender commandSender, @NotNull String s, @NotNull String[] strings) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -24,6 +24,7 @@ public class TerraCommand extends Command {
|
|||||||
new GeometryCommand(this),
|
new GeometryCommand(this),
|
||||||
new FixChunkCommand(this),
|
new FixChunkCommand(this),
|
||||||
new VersionCommand(this),
|
new VersionCommand(this),
|
||||||
|
new GetBlockCommand(this),
|
||||||
new PacksCommand(this));
|
new PacksCommand(this));
|
||||||
|
|
||||||
public TerraCommand(TerraPlugin main) {
|
public TerraCommand(TerraPlugin main) {
|
||||||
|
|||||||
Reference in New Issue
Block a user