-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support sponge schematics v2/3
- Loading branch information
Showing
7 changed files
with
161 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
metadata.format.version = "1.1" | ||
|
||
[versions] | ||
minestom = "e9d0098418" | ||
minestom = "8715f4305d" | ||
logback = "1.4.5" # For tests only | ||
|
||
[libraries] | ||
minestom = { group = "dev.hollowcube", name = "minestom-ce", version.ref = "minestom" } | ||
|
||
logback-core = { group = "ch.qos.logback", name = "logback-core", version.ref = "logback" } | ||
logback-classic = { group = "ch.qos.logback", name = "logback-classic", version.ref = "logback" } | ||
|
||
[bundles] | ||
logback = ["logback-core", "logback-classic"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/net/hollowcube/schem/TestSchematicReaderRegressions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.hollowcube.schem; | ||
|
||
import net.minestom.server.coordinate.Vec; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class TestSchematicReaderRegressions { | ||
|
||
@Test | ||
public void testReadFail1_20_1() { | ||
var schem = assertReadSchematic("/regression/1_20_1_read_fail.schem"); | ||
assertEquals(new Vec(15, 16, 20), schem.size()); | ||
} | ||
|
||
@Test | ||
public void testSpongeV1() { | ||
var schem = assertReadSchematic("/regression/sponge_1.schem"); | ||
assertEquals(new Vec(217, 70, 173), schem.size()); | ||
} | ||
|
||
private @NotNull Schematic assertReadSchematic(@NotNull String path) { | ||
try (var is = getClass().getResourceAsStream(path)) { | ||
assertNotNull(is, "Failed to load resource: " + path); | ||
return SchematicReader.read(is); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.hollowcube.schem.demo; | ||
|
||
import net.hollowcube.schem.Rotation; | ||
import net.minestom.server.MinecraftServer; | ||
import net.minestom.server.command.CommandSender; | ||
import net.minestom.server.command.builder.Command; | ||
import net.minestom.server.command.builder.CommandContext; | ||
import net.minestom.server.command.builder.arguments.ArgumentType; | ||
import net.minestom.server.coordinate.Pos; | ||
import net.minestom.server.entity.GameMode; | ||
import net.minestom.server.entity.Player; | ||
import net.minestom.server.event.player.PlayerLoginEvent; | ||
import net.minestom.server.event.player.PlayerSpawnEvent; | ||
import net.minestom.server.instance.LightingChunk; | ||
import net.minestom.server.instance.block.Block; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class DemoServer { | ||
public static void main(String[] args) { | ||
var server = MinecraftServer.init(); | ||
|
||
var instances = MinecraftServer.getInstanceManager(); | ||
var instance = instances.createInstanceContainer(); | ||
instance.setChunkSupplier(LightingChunk::new); | ||
instance.setGenerator(unit -> unit.modifier().fillHeight(0, 39, Block.STONE)); | ||
|
||
var events = MinecraftServer.getGlobalEventHandler(); | ||
events.addListener(PlayerLoginEvent.class, event -> { | ||
event.setSpawningInstance(instance); | ||
event.getPlayer().setRespawnPoint(new Pos(0, 40, 0)); | ||
}); | ||
events.addListener(PlayerSpawnEvent.class, event -> { | ||
var player = event.getPlayer(); | ||
|
||
player.setGameMode(GameMode.CREATIVE); | ||
}); | ||
|
||
var commands = MinecraftServer.getCommandManager(); | ||
commands.register(new Command("paste") { | ||
{ | ||
addSyntax(this::execute, ArgumentType.StringArray("path")); | ||
} | ||
|
||
public void execute(@NotNull CommandSender sender, @NotNull CommandContext context) { | ||
var player = (Player) sender; | ||
|
||
try (var is = getClass().getResourceAsStream("/" + String.join(" ", context.<String[]>get("path")) + ".schem")) { | ||
var schem = net.hollowcube.schem.SchematicReader.read(is); | ||
schem.build(Rotation.NONE, false).apply(instance, player.getPosition(), () -> { | ||
player.sendMessage("Done!"); | ||
}); | ||
} catch (Exception e) { | ||
player.sendMessage("Failed to paste schematic: " + e.getMessage()); | ||
e.printStackTrace(); | ||
} | ||
} | ||
}); | ||
|
||
server.start("localhost", 25565); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.