Added test command for testing ore gen.

Started reimplementing quartz ore gen ontop of vanilla mechanics.
Fixes several sidedness issues.
Added recipe serialization for server->client sync.
This commit is contained in:
Sebastian Hartte
2020-06-20 18:04:20 +02:00
parent daaac300b8
commit 434386a7ff
44 changed files with 597 additions and 434 deletions
@@ -26,12 +26,18 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.command.CommandSource;
import net.minecraftforge.fml.server.ServerLifecycleHooks;
import appeng.api.features.AEFeature;
import appeng.core.AEConfig;
public final class AECommand {
public void register(CommandDispatcher<CommandSource> dispatcher) {
LiteralArgumentBuilder<CommandSource> builder = literal("ae2");
for (Commands command : Commands.values()) {
if (command.test && !AEConfig.instance().isFeatureEnabled(AEFeature.TEST_COMMANDS)) {
continue;
}
add(builder, command);
}
+6 -2
View File
@@ -20,16 +20,20 @@ package appeng.server;
import appeng.server.subcommands.ChunkLogger;
import appeng.server.subcommands.Supporters;
import appeng.server.subcommands.TestOreGenCommand;
public enum Commands {
Chunklogger(4, new ChunkLogger()), Supporters(0, new Supporters());
Chunklogger(4, new ChunkLogger(), false), Supporters(0, new Supporters(), false),
TestOreGen(4, new TestOreGenCommand(), true);
public final int level;
public final ISubCommand command;
public boolean test;
Commands(final int level, final ISubCommand w) {
Commands(final int level, final ISubCommand w, boolean test) {
this.level = level;
this.command = w;
this.test = test;
}
@Override
@@ -23,7 +23,5 @@ import net.minecraft.server.MinecraftServer;
public interface ISubCommand {
String getHelp(MinecraftServer srv);
void call(MinecraftServer srv, String[] args, CommandSource sender);
}
@@ -64,11 +64,6 @@ public class ChunkLogger implements ISubCommand {
}
}
@Override
public String getHelp(final MinecraftServer srv) {
return "commands.ae2.ChunkLogger";
}
@Override
public void call(final MinecraftServer srv, final String[] data, final CommandSource sender) {
this.enabled = !this.enabled;
@@ -28,11 +28,6 @@ import appeng.server.ISubCommand;
public class Supporters implements ISubCommand {
@Override
public String getHelp(final MinecraftServer srv) {
return "commands.ae2.Supporters";
}
@Override
public void call(final MinecraftServer srv, final String[] data, final CommandSource sender) {
final String[] who = { "Stig Halvorsen", "Josh Ricker", "Jenny \"Othlon\" Sutherland", "Hristo Bogdanov",
@@ -0,0 +1,131 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.server.subcommands;
import java.util.Locale;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.BlockState;
import net.minecraft.command.CommandSource;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.server.ServerWorld;
import appeng.core.Api;
import appeng.server.ISubCommand;
/**
* This is a testing command to validate quartz ore generation.
*/
public class TestOreGenCommand implements ISubCommand {
private final BlockState quartzOre;
private final BlockState chargedQuartzOre;
public TestOreGenCommand() {
quartzOre = Api.INSTANCE.definitions().blocks().quartzOre().block().getDefaultState();
chargedQuartzOre = Api.INSTANCE.definitions().blocks().quartzOreCharged().block().getDefaultState();
}
@Override
public void call(final MinecraftServer srv, final String[] data, final CommandSource sender) {
int radius = 1000;
ServerWorld world = srv.getWorld(DimensionType.OVERWORLD);
BlockPos center;
try {
ServerPlayerEntity player = sender.asPlayer();
center = new BlockPos(player.getPosX(), 0, player.getPosZ());
} catch (CommandSyntaxException e) {
center = world.getSpawnPoint();
}
ChunkPos tl = new ChunkPos(center.add(-radius, 0, -radius));
ChunkPos br = new ChunkPos(center.add(radius, 0, radius));
Stats stats = new Stats();
for (int cx = tl.x; cx <= br.x; cx++) {
for (int cz = tl.z; cz <= br.z; cz++) {
ChunkPos cp = new ChunkPos(cx, cz);
checkChunk(sender, world, cp, stats);
}
}
sendLine(sender, "Checked %d chunks", stats.chunksChecked);
sendLine(sender, "Total Ore: %d (%f per chunk)", stats.quartzOreCount,
stats.quartzOreCount / (float) stats.chunksChecked);
if (stats.quartzOreCount > 0) {
sendLine(sender, "Charged ore: %d (%.1f%%)", stats.chargedOreCount,
stats.chargedOreCount / (float) stats.quartzOreCount * 100);
sendLine(sender, "Height range: %d-%d", stats.minHeight, stats.maxHeight);
}
}
private void checkChunk(CommandSource sender, ServerWorld world, ChunkPos cp, Stats stats) {
IChunk chunk = world.getChunk(cp.x, cp.z, ChunkStatus.FULL, false);
if (chunk == null) {
sendLine(sender, "Skipping chunk %s", cp);
return;
}
stats.chunksChecked++;
BlockPos.Mutable blockPos = new BlockPos.Mutable();
sendLine(sender, "Checking chunk %s", cp);
for (int x = cp.getXStart(); x <= cp.getXEnd(); x++) {
blockPos.setX(x);
for (int z = cp.getZStart(); z <= cp.getZEnd(); z++) {
blockPos.setZ(z);
for (int y = 0; y < world.getMaxHeight(); y++) {
blockPos.setY(y);
BlockState state = chunk.getBlockState(blockPos);
if (state == quartzOre || state == chargedQuartzOre) {
stats.minHeight = Math.min(stats.minHeight, y);
stats.maxHeight = Math.max(stats.maxHeight, y);
stats.quartzOreCount++;
if (state == chargedQuartzOre) {
stats.chargedOreCount++;
}
}
}
}
}
}
private static void sendLine(CommandSource sender, String text, Object... args) {
sender.sendFeedback(new StringTextComponent(String.format(Locale.ROOT, text, args)), true);
}
private static class Stats {
public int chunksChecked = 0;
public int quartzOreCount = 0;
public int chargedOreCount = 0;
public int minHeight = Integer.MAX_VALUE;
public int maxHeight = Integer.MIN_VALUE;
}
}