diff --git a/src/main/java/ru/windcorp/progressia/test/CollisionModelRenderer.java b/src/main/java/ru/windcorp/progressia/test/CollisionModelRenderer.java index 4c7ca68..345e7f8 100644 --- a/src/main/java/ru/windcorp/progressia/test/CollisionModelRenderer.java +++ b/src/main/java/ru/windcorp/progressia/test/CollisionModelRenderer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import glm.mat._4.Mat4; @@ -33,9 +33,9 @@ import ru.windcorp.progressia.common.collision.CompoundCollisionModel; public class CollisionModelRenderer { private static final Shape CUBE = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), (Texture) null) - .setColorMultiplier(1.0f, 0.7f, 0.2f).create(); + .setColorMultiplier(1.0f, 0.7f, 0.2f).create(); private static final Shape CUBE_GRAY = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), (Texture) null) - .setColorMultiplier(0.5f, 0.5f, 0.5f).create(); + .setColorMultiplier(0.5f, 0.5f, 0.5f).create(); public static void renderCollisionModel(CollisionModel model, ShapeRenderHelper helper) { if (model instanceof AABBoid) { @@ -60,10 +60,7 @@ public class CollisionModelRenderer { helper.popTransform(); } - private static void renderCompound( - CompoundCollisionModel model, - ShapeRenderHelper helper - ) { + private static void renderCompound(CompoundCollisionModel model, ShapeRenderHelper helper) { for (CollisionModel part : model.getModels()) { renderCollisionModel(part, helper); } diff --git a/src/main/java/ru/windcorp/progressia/test/ControlBreakBlockData.java b/src/main/java/ru/windcorp/progressia/test/ControlBreakBlockData.java index a9df57a..d7e8a36 100644 --- a/src/main/java/ru/windcorp/progressia/test/ControlBreakBlockData.java +++ b/src/main/java/ru/windcorp/progressia/test/ControlBreakBlockData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import glm.vec._3.i.Vec3i; diff --git a/src/main/java/ru/windcorp/progressia/test/ControlPlaceBlockData.java b/src/main/java/ru/windcorp/progressia/test/ControlPlaceBlockData.java index f3e45e2..f83a0cc 100644 --- a/src/main/java/ru/windcorp/progressia/test/ControlPlaceBlockData.java +++ b/src/main/java/ru/windcorp/progressia/test/ControlPlaceBlockData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import glm.vec._3.i.Vec3i; diff --git a/src/main/java/ru/windcorp/progressia/test/ControlPlaceTileData.java b/src/main/java/ru/windcorp/progressia/test/ControlPlaceTileData.java index 5a37b6f..5835d7b 100644 --- a/src/main/java/ru/windcorp/progressia/test/ControlPlaceTileData.java +++ b/src/main/java/ru/windcorp/progressia/test/ControlPlaceTileData.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import glm.vec._3.i.Vec3i; diff --git a/src/main/java/ru/windcorp/progressia/test/LayerAbout.java b/src/main/java/ru/windcorp/progressia/test/LayerAbout.java index 3eaff87..20260b0 100644 --- a/src/main/java/ru/windcorp/progressia/test/LayerAbout.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerAbout.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import ru.windcorp.progressia.client.graphics.Colors; @@ -38,29 +38,12 @@ public class LayerAbout extends GUILayer { Font font = new Font().withColor(Colors.WHITE).deriveOutlined().withAlign(Typeface.ALIGN_RIGHT); Font aboutFont = font.withColor(0xFF37A3E6).deriveBold(); - panel.addChild( - new Label( - "About", - aboutFont, - new MutableStringLocalized("LayerAbout.Title") - ) - ); + panel.addChild(new Label("About", aboutFont, new MutableStringLocalized("LayerAbout.Title"))); panel.addChild( - new Label( - "Version", - font, - new MutableStringLocalized("LayerAbout.Version").format("pre-alpha 1") - ) - ); + new Label("Version", font, new MutableStringLocalized("LayerAbout.Version").format("pre-alpha 1"))); - panel.addChild( - new Label( - "DebugHint", - font, - new MutableStringLocalized("LayerAbout.DebugHint") - ) - ); + panel.addChild(new Label("DebugHint", font, new MutableStringLocalized("LayerAbout.DebugHint"))); getRoot().addChild(panel); diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java b/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java index ca02ed8..db42176 100755 --- a/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTestGUI.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import glm.vec._3.Vec3; @@ -58,146 +58,51 @@ public class LayerTestGUI extends GUILayer { TestPlayerControls tpc = TestPlayerControls.getInstance(); panel.addChild( - new Label( - "IsFlyingDisplay", - font, - tmp_dynFormat("LayerTestGUI.IsFlyingDisplay", tpc::isFlying) - ) - ); + new Label("IsFlyingDisplay", font, tmp_dynFormat("LayerTestGUI.IsFlyingDisplay", tpc::isFlying))); + + panel.addChild(new Label("IsSprintingDisplay", font, + tmp_dynFormat("LayerTestGUI.IsSprintingDisplay", tpc::isSprinting))); + + panel.addChild(new Label("IsMouseCapturedDisplay", font, + tmp_dynFormat("LayerTestGUI.IsMouseCapturedDisplay", tpc::isMouseCaptured))); + + panel.addChild(new Label("CameraModeDisplay", font, tmp_dynFormat("LayerTestGUI.CameraModeDisplay", + ClientState.getInstance().getCamera()::getCurrentModeIndex))); + + panel.addChild(new Label("GravityModeDisplay", font, tmp_dynFormat("LayerTestGUI.GravityModeDisplay", + () -> tpc.useMinecraftGravity() ? "Minecraft" : "Realistic"))); + + panel.addChild(new Label("LanguageDisplay", font, + tmp_dynFormat("LayerTestGUI.LanguageDisplay", Localizer.getInstance()::getLanguage))); + + panel.addChild(new Label("FullscreenDisplay", font, + tmp_dynFormat("LayerTestGUI.IsFullscreen", GraphicsBackend::isFullscreen))); + + panel.addChild(new Label("VSyncDisplay", font, + tmp_dynFormat("LayerTestGUI.IsVSync", GraphicsBackend::isVSyncEnabled))); panel.addChild( - new Label( - "IsSprintingDisplay", - font, - tmp_dynFormat("LayerTestGUI.IsSprintingDisplay", tpc::isSprinting) - ) - ); + new DynamicLabel("FPSDisplay", font, + DynamicStrings.builder().addDyn(new MutableStringLocalized("LayerTestGUI.FPSDisplay")) + .addDyn(() -> FPS_RECORD.update(GraphicsInterface.getFPS()), 5, 1).buildSupplier(), + 128)); + + panel.addChild(new DynamicLabel("TPSDisplay", font, LayerTestGUI::getTPS, 128)); panel.addChild( - new Label( - "IsMouseCapturedDisplay", - font, - tmp_dynFormat("LayerTestGUI.IsMouseCapturedDisplay", tpc::isMouseCaptured) - ) - ); + new DynamicLabel("ChunkUpdatesDisplay", font, + DynamicStrings.builder().addDyn(new MutableStringLocalized("LayerTestGUI.ChunkUpdatesDisplay")) + .addDyn(ClientState.getInstance().getWorld()::getPendingChunkUpdates).buildSupplier(), + 128)); - panel.addChild( - new Label( - "CameraModeDisplay", - font, - tmp_dynFormat( - "LayerTestGUI.CameraModeDisplay", - ClientState.getInstance().getCamera()::getCurrentModeIndex - ) - ) - ); + panel.addChild(new DynamicLabel("PosDisplay", font, LayerTestGUI::getPos, 128)); - panel.addChild( - new Label( - "GravityModeDisplay", - font, - tmp_dynFormat( - "LayerTestGUI.GravityModeDisplay", - () -> tpc.useMinecraftGravity() ? "Minecraft" : "Realistic" - ) - ) - ); - - panel.addChild( - new Label( - "LanguageDisplay", - font, - tmp_dynFormat("LayerTestGUI.LanguageDisplay", Localizer.getInstance()::getLanguage) - ) - ); - - panel.addChild( - new Label( - "FullscreenDisplay", - font, - tmp_dynFormat("LayerTestGUI.IsFullscreen", GraphicsBackend::isFullscreen) - ) - ); - - panel.addChild( - new Label( - "VSyncDisplay", - font, - tmp_dynFormat("LayerTestGUI.IsVSync", GraphicsBackend::isVSyncEnabled) - ) - ); - - panel.addChild( - new DynamicLabel( - "FPSDisplay", - font, - DynamicStrings.builder() - .addDyn(new MutableStringLocalized("LayerTestGUI.FPSDisplay")) - .addDyn(() -> FPS_RECORD.update(GraphicsInterface.getFPS()), 5, 1) - .buildSupplier(), - 128 - ) - ); - - panel.addChild( - new DynamicLabel( - "TPSDisplay", - font, - LayerTestGUI::getTPS, - 128 - ) - ); - - panel.addChild( - new DynamicLabel( - "ChunkUpdatesDisplay", - font, - DynamicStrings.builder() - .addDyn(new MutableStringLocalized("LayerTestGUI.ChunkUpdatesDisplay")) - .addDyn(ClientState.getInstance().getWorld()::getPendingChunkUpdates) - .buildSupplier(), - 128 - ) - ); - - panel.addChild( - new DynamicLabel( - "PosDisplay", - font, - LayerTestGUI::getPos, - 128 - ) - ); - - panel.addChild( - new Label( - "SelectedBlockDisplay", - font, - tmp_dynFormat( - "LayerTestGUI.SelectedBlockDisplay", - () -> tpc.isBlockSelected() ? ">" : " ", - () -> tpc.getSelectedBlock().getId() - ) - ) - ); - panel.addChild( - new Label( - "SelectedTileDisplay", - font, - tmp_dynFormat( - "LayerTestGUI.SelectedTileDisplay", - () -> tpc.isBlockSelected() ? " " : ">", - () -> tpc.getSelectedTile().getId() - ) - ) - ); - panel.addChild( - new Label( - "PlacementModeHint", - font, - new MutableStringLocalized("LayerTestGUI.PlacementModeHint").format("\u2B04") - ) - ); + panel.addChild(new Label("SelectedBlockDisplay", font, tmp_dynFormat("LayerTestGUI.SelectedBlockDisplay", + () -> tpc.isBlockSelected() ? ">" : " ", () -> tpc.getSelectedBlock().getId()))); + panel.addChild(new Label("SelectedTileDisplay", font, tmp_dynFormat("LayerTestGUI.SelectedTileDisplay", + () -> tpc.isBlockSelected() ? " " : ">", () -> tpc.getSelectedTile().getId()))); + panel.addChild(new Label("PlacementModeHint", font, + new MutableStringLocalized("LayerTestGUI.PlacementModeHint").format("\u2B04"))); getRoot().addChild(panel); } @@ -265,16 +170,14 @@ public class LayerTestGUI extends GUILayer { private static final Averager TPS_RECORD = new Averager(); private static final Supplier TPS_STRING = DynamicStrings.builder() - .addDyn(new MutableStringLocalized("LayerTestGUI.TPSDisplay")) - .addDyn(() -> TPS_RECORD.update(ServerState.getInstance().getTPS()), 5, 1) - .buildSupplier(); + .addDyn(new MutableStringLocalized("LayerTestGUI.TPSDisplay")) + .addDyn(() -> TPS_RECORD.update(ServerState.getInstance().getTPS()), 5, 1).buildSupplier(); private static final Supplier POS_STRING = DynamicStrings.builder() - .addDyn(new MutableStringLocalized("LayerTestGUI.PosDisplay")) - .addDyn(() -> ClientState.getInstance().getCamera().getLastAnchorPosition().x, 7, 1) - .addDyn(() -> ClientState.getInstance().getCamera().getLastAnchorPosition().y, 7, 1) - .addDyn(() -> ClientState.getInstance().getCamera().getLastAnchorPosition().z, 7, 1) - .buildSupplier(); + .addDyn(new MutableStringLocalized("LayerTestGUI.PosDisplay")) + .addDyn(() -> ClientState.getInstance().getCamera().getLastAnchorPosition().x, 7, 1) + .addDyn(() -> ClientState.getInstance().getCamera().getLastAnchorPosition().y, 7, 1) + .addDyn(() -> ClientState.getInstance().getCamera().getLastAnchorPosition().z, 7, 1).buildSupplier(); private static CharSequence getTPS() { Server server = ServerState.getInstance(); @@ -316,93 +219,95 @@ public class LayerTestGUI extends GUILayer { }); } -// private static class DebugComponent extends Component { -// private final int color; -// -// public DebugComponent(String name, Vec2i size, int color) { -// super(name); -// this.color = color; -// -// setPreferredSize(size); -// -// addListener(new Object() { -// @Subscribe -// public void onHoverChanged(HoverEvent e) { -// requestReassembly(); -// } -// }); -// -// addListener(KeyEvent.class, this::onClicked); -// } -// -// private boolean onClicked(KeyEvent event) { -// if (!event.isMouse()) { -// return false; -// } else if (event.isPress() && event.isLeftMouseButton()) { -// System.out.println("You pressed a Component!"); -// } -// return true; -// } -// -// @Override -// protected void assembleSelf(RenderTarget target) { -// target.fill(getX(), getY(), getWidth(), getHeight(), Colors.BLACK); -// -// target.fill( -// getX() + 2, getY() + 2, -// getWidth() - 4, getHeight() - 4, -// isHovered() ? Colors.DEBUG_YELLOW : color -// ); -// } -// } -// -// public LayerTestGUI() { -// super("LayerTestGui", new LayoutAlign(1, 0.75, 5)); -// -// Panel panel = new Panel("Alex", new LayoutVertical(5)); -// -// panel.addChild(new DebugComponent("Bravo", new Vec2i(200, 100), 0x44FF44)); -// -// Component charlie = new DebugComponent("Charlie", null, 0x222222); -// charlie.setLayout(new LayoutVertical(5)); -// -// //Debug -// Localizer.getInstance().setLanguage("ru-RU"); -// MutableString epsilon = new MutableStringLocalized("Epsilon") -// .addListener(() -> ((Label)charlie.getChild(0)).update()).format(34, "thirty-four"); -// // These two are swapped in code due to a bug in layouts, fixing ATM -// charlie.addChild( -// new Label( -// "Delta", -// new Font().withColor(0xCCBB44).deriveShadow().deriveBold(), -// "Пре-альфа!" -// ) -// ); -// charlie.addChild( -// new Label( -// "Epsilon", -// new Font().withColor(0x4444BB).deriveItalic(), -// () -> epsilon.get().concat("\u269b") -// ) -// ); -// panel.addChild(charlie); -// -// -// charlie.addListener(KeyEvent.class, e -> { -// if(e.isPress() && e.getKey() == GLFW.GLFW_KEY_L) { -// Localizer localizer = Localizer.getInstance(); -// if (localizer.getLanguage().equals("ru-RU")) { -// localizer.setLanguage("en-US"); -// } else { -// localizer.setLanguage("ru-RU"); -// } -// return true; -// } return false; -// }); -// charlie.setFocusable(true); -// charlie.takeFocus(); -// -// getRoot().addChild(panel); -// } + // private static class DebugComponent extends Component { + // private final int color; + // + // public DebugComponent(String name, Vec2i size, int color) { + // super(name); + // this.color = color; + // + // setPreferredSize(size); + // + // addListener(new Object() { + // @Subscribe + // public void onHoverChanged(HoverEvent e) { + // requestReassembly(); + // } + // }); + // + // addListener(KeyEvent.class, this::onClicked); + // } + // + // private boolean onClicked(KeyEvent event) { + // if (!event.isMouse()) { + // return false; + // } else if (event.isPress() && event.isLeftMouseButton()) { + // System.out.println("You pressed a Component!"); + // } + // return true; + // } + // + // @Override + // protected void assembleSelf(RenderTarget target) { + // target.fill(getX(), getY(), getWidth(), getHeight(), Colors.BLACK); + // + // target.fill( + // getX() + 2, getY() + 2, + // getWidth() - 4, getHeight() - 4, + // isHovered() ? Colors.DEBUG_YELLOW : color + // ); + // } + // } + // + // public LayerTestGUI() { + // super("LayerTestGui", new LayoutAlign(1, 0.75, 5)); + // + // Panel panel = new Panel("Alex", new LayoutVertical(5)); + // + // panel.addChild(new DebugComponent("Bravo", new Vec2i(200, 100), + // 0x44FF44)); + // + // Component charlie = new DebugComponent("Charlie", null, 0x222222); + // charlie.setLayout(new LayoutVertical(5)); + // + // //Debug + // Localizer.getInstance().setLanguage("ru-RU"); + // MutableString epsilon = new MutableStringLocalized("Epsilon") + // .addListener(() -> ((Label)charlie.getChild(0)).update()).format(34, + // "thirty-four"); + // // These two are swapped in code due to a bug in layouts, fixing ATM + // charlie.addChild( + // new Label( + // "Delta", + // new Font().withColor(0xCCBB44).deriveShadow().deriveBold(), + // "Пре-альфа!" + // ) + // ); + // charlie.addChild( + // new Label( + // "Epsilon", + // new Font().withColor(0x4444BB).deriveItalic(), + // () -> epsilon.get().concat("\u269b") + // ) + // ); + // panel.addChild(charlie); + // + // + // charlie.addListener(KeyEvent.class, e -> { + // if(e.isPress() && e.getKey() == GLFW.GLFW_KEY_L) { + // Localizer localizer = Localizer.getInstance(); + // if (localizer.getLanguage().equals("ru-RU")) { + // localizer.setLanguage("en-US"); + // } else { + // localizer.setLanguage("ru-RU"); + // } + // return true; + // } return false; + // }); + // charlie.setFocusable(true); + // charlie.takeFocus(); + // + // getRoot().addChild(panel); + // } } diff --git a/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java b/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java index c93a055..892df0f 100755 --- a/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java +++ b/src/main/java/ru/windcorp/progressia/test/LayerTestUI.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import org.lwjgl.glfw.GLFW; @@ -75,17 +75,10 @@ public class LayerTestUI extends AssembledFlatLayer { target.drawTexture(texShadow, -texShadow, texSize, texSize, Colors.BLACK, compassBg); target.drawTexture(0, 0, texSize, texSize, compassBg); - target.addCustomRenderer( - new LambdaModel( - LambdaModel.lambdaBuilder() - .addDynamicPart( - target.createRectagle(0, 0, texSize, texSize, Colors.WHITE, compassFg), - mat -> mat.translate(texSize / 2, texSize / 2, 0) - .rotateZ(getCompassRotation()) - .translate(-texSize / 2, -texSize / 2, 0) - ) - ) - ); + target.addCustomRenderer(new LambdaModel(LambdaModel.lambdaBuilder().addDynamicPart( + target.createRectagle(0, 0, texSize, texSize, Colors.WHITE, compassFg), + mat -> mat.translate(texSize / 2, texSize / 2, 0).rotateZ(getCompassRotation()).translate(-texSize / 2, + -texSize / 2, 0)))); target.popTransform(); drawCross(target); @@ -110,37 +103,15 @@ public class LayerTestUI extends AssembledFlatLayer { final Vec4 borderColor = Colors.BLACK; final Vec4 fillColor = Colors.WHITE; - target.fill( - cx - length - thickness / 2, - cy - thickness / 2, - 2 * length + thickness, - thickness, - borderColor - ); + target.fill(cx - length - thickness / 2, cy - thickness / 2, 2 * length + thickness, thickness, borderColor); - target.fill( - cx - thickness / 2, - cy - length - thickness / 2, - thickness, - 2 * length + thickness, - borderColor - ); + target.fill(cx - thickness / 2, cy - length - thickness / 2, thickness, 2 * length + thickness, borderColor); - target.fill( - cx - length - thickness / 2 + borderSize, - cy - thickness / 2 + borderSize, - 2 * length + thickness - 2 * borderSize, - thickness - 2 * borderSize, - fillColor - ); + target.fill(cx - length - thickness / 2 + borderSize, cy - thickness / 2 + borderSize, + 2 * length + thickness - 2 * borderSize, thickness - 2 * borderSize, fillColor); - target.fill( - cx - thickness / 2 + borderSize, - cy - length - thickness / 2 + borderSize, - thickness - 2 * borderSize, - 2 * length + thickness - 2 * borderSize, - fillColor - ); + target.fill(cx - thickness / 2 + borderSize, cy - length - thickness / 2 + borderSize, + thickness - 2 * borderSize, 2 * length + thickness - 2 * borderSize, fillColor); } @Override diff --git a/src/main/java/ru/windcorp/progressia/test/TestBlockLogicAir.java b/src/main/java/ru/windcorp/progressia/test/TestBlockLogicAir.java index e378dbf..e9877e9 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestBlockLogicAir.java +++ b/src/main/java/ru/windcorp/progressia/test/TestBlockLogicAir.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import ru.windcorp.progressia.common.world.block.BlockFace; diff --git a/src/main/java/ru/windcorp/progressia/test/TestBlockLogicGlass.java b/src/main/java/ru/windcorp/progressia/test/TestBlockLogicGlass.java index eca9e5c..e58cc3d 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestBlockLogicGlass.java +++ b/src/main/java/ru/windcorp/progressia/test/TestBlockLogicGlass.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import ru.windcorp.progressia.common.world.block.BlockFace; diff --git a/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java b/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java index a4f891b..a9298a1 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java +++ b/src/main/java/ru/windcorp/progressia/test/TestChunkCodec.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import java.io.DataInput; @@ -85,8 +85,7 @@ public class TestChunkCodec extends ChunkCodec { @Override public ChunkData decode(WorldData world, Vec3i position, DataInputStream input, IOContext context) - throws DecodingException, - IOException { + throws DecodingException, IOException { BlockData[] blockPalette = readBlockPalette(input); TileData[] tilePalette = readTilePalette(input); diff --git a/src/main/java/ru/windcorp/progressia/test/TestContent.java b/src/main/java/ru/windcorp/progressia/test/TestContent.java index 7f4ed7e..573fd1f 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestContent.java +++ b/src/main/java/ru/windcorp/progressia/test/TestContent.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import static ru.windcorp.progressia.client.world.block.BlockRenderRegistry.getBlockTexture; @@ -129,17 +129,9 @@ public class TestContent { register(new BlockLogic("Test:Concrete")); register(new BlockData("Test:Log")); - register( - new BlockRenderOpaqueCube( - "Test:Log", - getBlockTexture("LogTop"), - getBlockTexture("LogTop"), - getBlockTexture("LogSide"), - getBlockTexture("LogSide"), - getBlockTexture("LogSide"), - getBlockTexture("LogSide") - ) - ); + register(new BlockRenderOpaqueCube("Test:Log", getBlockTexture("LogTop"), getBlockTexture("LogTop"), + getBlockTexture("LogSide"), getBlockTexture("LogSide"), getBlockTexture("LogSide"), + getBlockTexture("LogSide"))); register(new BlockLogic("Test:Log")); register(new BlockData("Test:WoodenPlank")); @@ -257,49 +249,24 @@ public class TestContent { ControlLogicRegistry logic = ControlLogicRegistry.getInstance(); data.register("Test:BreakBlock", ControlBreakBlockData::new); - triggers.register( - ControlTriggers.of( - "Test:BreakBlock", - KeyEvent.class, - TestContent::onBlockBreakTrigger, - KeyMatcher.of(GLFW.GLFW_MOUSE_BUTTON_LEFT).matcher(), - i -> isAnythingSelected() - ) - ); + triggers.register(ControlTriggers.of("Test:BreakBlock", KeyEvent.class, TestContent::onBlockBreakTrigger, + KeyMatcher.of(GLFW.GLFW_MOUSE_BUTTON_LEFT).matcher(), i -> isAnythingSelected())); logic.register(ControlLogic.of("Test:BreakBlock", TestContent::onBlockBreakReceived)); data.register("Test:PlaceBlock", ControlPlaceBlockData::new); - triggers.register( - ControlTriggers.of( - "Test:PlaceBlock", - KeyEvent.class, - TestContent::onBlockPlaceTrigger, + triggers.register(ControlTriggers.of("Test:PlaceBlock", KeyEvent.class, TestContent::onBlockPlaceTrigger, KeyMatcher.of(GLFW.GLFW_MOUSE_BUTTON_RIGHT).matcher(), - i -> isAnythingSelected() && TestPlayerControls.getInstance().isBlockSelected() - ) - ); + i -> isAnythingSelected() && TestPlayerControls.getInstance().isBlockSelected())); logic.register(ControlLogic.of("Test:PlaceBlock", TestContent::onBlockPlaceReceived)); data.register("Test:PlaceTile", ControlPlaceTileData::new); - triggers.register( - ControlTriggers.of( - "Test:PlaceTile", - KeyEvent.class, - TestContent::onTilePlaceTrigger, + triggers.register(ControlTriggers.of("Test:PlaceTile", KeyEvent.class, TestContent::onTilePlaceTrigger, KeyMatcher.of(GLFW.GLFW_MOUSE_BUTTON_RIGHT).matcher(), - i -> isAnythingSelected() && !TestPlayerControls.getInstance().isBlockSelected() - ) - ); + i -> isAnythingSelected() && !TestPlayerControls.getInstance().isBlockSelected())); logic.register(ControlLogic.of("Test:PlaceTile", TestContent::onTilePlaceReceived)); - - triggers.register( - ControlTriggers.localOf( - "Test:StartNextMusic", - KeyEvent.class, - TestMusicPlayer::startNextNow, - KeyMatcher.of(GLFW.GLFW_KEY_M).matcher() - ) - ); + + triggers.register(ControlTriggers.localOf("Test:StartNextMusic", KeyEvent.class, TestMusicPlayer::startNextNow, + KeyMatcher.of(GLFW.GLFW_KEY_M).matcher())); } private static void register(BlockData x) { @@ -310,17 +277,11 @@ public class TestContent { TileDataRegistry.getInstance().register(x); } - private static void register( - String id, - Factory factory - ) { + private static void register(String id, Factory factory) { EntityDataRegistry.getInstance().register(id, factory); } - private static void registerEntityData( - String id, - Consumer transform - ) { + private static void registerEntityData(String id, Consumer transform) { EntityDataRegistry.getInstance().register(id, new Factory() { @Override public EntityData build() { @@ -379,27 +340,19 @@ public class TestContent { sfx.play(false); } - private static void onBlockBreakReceived( - Server server, - PacketControl packet, - ru.windcorp.progressia.server.comms.Client client - ) { + private static void onBlockBreakReceived(Server server, PacketControl packet, + ru.windcorp.progressia.server.comms.Client client) { Vec3i blockInWorld = ((ControlBreakBlockData) packet.getControl()).getBlockInWorld(); server.getWorldAccessor().setBlock(blockInWorld, BlockDataRegistry.getInstance().get("Test:Air")); } private static void onBlockPlaceTrigger(ControlData control) { - ((ControlPlaceBlockData) control).set( - TestPlayerControls.getInstance().getSelectedBlock(), - getSelection().getBlock().add_(getSelection().getSurface().getVector()) - ); + ((ControlPlaceBlockData) control).set(TestPlayerControls.getInstance().getSelectedBlock(), + getSelection().getBlock().add_(getSelection().getSurface().getVector())); } - private static void onBlockPlaceReceived( - Server server, - PacketControl packet, - ru.windcorp.progressia.server.comms.Client client - ) { + private static void onBlockPlaceReceived(Server server, PacketControl packet, + ru.windcorp.progressia.server.comms.Client client) { ControlPlaceBlockData controlData = ((ControlPlaceBlockData) packet.getControl()); BlockData block = controlData.getBlock(); Vec3i blockInWorld = controlData.getBlockInWorld(); @@ -409,18 +362,12 @@ public class TestContent { } private static void onTilePlaceTrigger(ControlData control) { - ((ControlPlaceTileData) control).set( - TestPlayerControls.getInstance().getSelectedTile(), - getSelection().getBlock(), - getSelection().getSurface() - ); + ((ControlPlaceTileData) control).set(TestPlayerControls.getInstance().getSelectedTile(), + getSelection().getBlock(), getSelection().getSurface()); } - private static void onTilePlaceReceived( - Server server, - PacketControl packet, - ru.windcorp.progressia.server.comms.Client client - ) { + private static void onTilePlaceReceived(Server server, PacketControl packet, + ru.windcorp.progressia.server.comms.Client client) { ControlPlaceTileData controlData = ((ControlPlaceTileData) packet.getControl()); TileData tile = controlData.getTile(); Vec3i blockInWorld = controlData.getBlockInWorld(); diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java index 0b1e1e1..7d11bb6 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityDataFallingBlock.java @@ -6,49 +6,45 @@ import ru.windcorp.progressia.common.world.entity.EntityData; /** * Data for Test:FallingBlock + * * @author opfromthestart * */ public class TestEntityDataFallingBlock extends EntityData { - + private BlockData block; private boolean isDone = false; private boolean hasDeleted = false; public TestEntityDataFallingBlock() { - this("Test:FallingBlock",new BlockData("Test:Sand")); + this("Test:FallingBlock", new BlockData("Test:Sand")); } - + protected TestEntityDataFallingBlock(String id, BlockData blockInput) { super(id); - setCollisionModel(new AABB(0,0,0,1,1,1)); + setCollisionModel(new AABB(0, 0, 0, 1, 1, 1)); block = blockInput; } - - public void setDestroyed() - { + + public void setDestroyed() { hasDeleted = true; } - - public boolean hasDestroyed() - { + + public boolean hasDestroyed() { return hasDeleted; } - - public BlockData getBlock() - { + + public BlockData getBlock() { return block; } - - public void setInvisible() - { - //block = new BlockData("Test:Log"); + + public void setInvisible() { + // block = new BlockData("Test:Log"); isDone = true; - setCollisionModel(new AABB(0,0,0,.5f,0.5f,0.5f)); + setCollisionModel(new AABB(0, 0, 0, .5f, 0.5f, 0.5f)); } - - public boolean isDone() - { + + public boolean isDone() { return isDone; } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityDataStatie.java b/src/main/java/ru/windcorp/progressia/test/TestEntityDataStatie.java index 94f5043..6bbee70 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityDataStatie.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityDataStatie.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import ru.windcorp.progressia.common.collision.AABB; diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java index 62b8337..ccbb37a 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicFallingBlock.java @@ -15,83 +15,94 @@ import ru.windcorp.progressia.server.world.entity.EntityLogic; /** * Logic for Test:FallingBlock + * * @author opfromthestart * */ public class TestEntityLogicFallingBlock extends EntityLogic { public static Set FallingBlocks = new HashSet(); - - public void addFallables() - { + + public void addFallables() { FallingBlocks.add("Test:Sand"); } - + public TestEntityLogicFallingBlock(String id) { super(id); addFallables(); } - - private Vec3i trueMod(Vec3i input,Vec3i modulus) //Move this to a class in Vec or something + + private Vec3i trueMod(Vec3i input, Vec3i modulus) // Move this to a class in + // Vec or something { return input.mod_(modulus).add_(modulus).mod_(modulus); } - - private Vec3i trueDiv(Vec3i input,Vec3i divisor) //Move this to a class in Vec or something + + private Vec3i trueDiv(Vec3i input, Vec3i divisor) // Move this to a class in + // Vec or something { Vec3i temp = input.div_(divisor); - temp.add(new Vec3i(input.x<0 ? -1 : 0,input.y<0 ? -1 : 0,input.z<0 ? -1 : 0)); + temp.add(new Vec3i(input.x < 0 ? -1 : 0, input.y < 0 ? -1 : 0, input.z < 0 ? -1 : 0)); return temp; } @Override - public void tick(EntityData entity, TickContext context) { //context.getWorldData() ClientState.getInstance().getWorld().getData() - if (entity == null) - { + public void tick(EntityData entity, TickContext context) { // context.getWorldData() + // ClientState.getInstance().getWorld().getData() + if (entity == null) { return; } - - //LogManager.getLogger().info("NotNull "+entity.toString() + " " + context.toString()); + + // LogManager.getLogger().info("NotNull "+entity.toString() + " " + + // context.toString()); super.tick(entity, context); - - //friction + + // friction Vec3 vel = entity.getVelocity(); float friction = 0f; - vel = new Vec3(vel.x*friction,vel.y*friction,vel.z); + vel = new Vec3(vel.x * friction, vel.y * friction, vel.z); entity.setVelocity(vel); - - TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); //ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); - //fallBlock = (TestEntityDataFallingBlock) entity; - - if (fallBlock.isDone() || !context.getWorld().isBlockLoaded(fallBlock.getBlockInWorld(null))) - { + + TestEntityDataFallingBlock fallBlock = (TestEntityDataFallingBlock) ClientState.getInstance().getWorld() + .getData().getEntity(entity.getEntityId()); // ClientState.getInstance().getWorld().getData().getEntity(entity.getEntityId()); + // fallBlock = (TestEntityDataFallingBlock) entity; + + if (fallBlock.isDone() || !context.getWorld().isBlockLoaded(fallBlock.getBlockInWorld(null))) { return; } - - if (!fallBlock.hasDestroyed()) - { - //LogManager.getLogger().info(fallBlock.getStartPos()); - context.getAccessor().setBlock(fallBlock.getBlockInWorld(null), BlockDataRegistry.getInstance().get("Test:Air")); + + if (!fallBlock.hasDestroyed()) { + // LogManager.getLogger().info(fallBlock.getStartPos()); + context.getAccessor().setBlock(fallBlock.getBlockInWorld(null), + BlockDataRegistry.getInstance().get("Test:Air")); fallBlock.setDestroyed(); } - + Vec3i occupiedBlock = fallBlock.getBlockInWorld(null); Vec3i underBlock = occupiedBlock.sub_(0, 0, 1); - + Vec3i chunkCoords = trueDiv(underBlock, new Vec3i(16)); Vec3i inChunkCoords = trueMod(underBlock, new Vec3i(16)); - - //LogManager.getLogger().info("InChunk "+String.valueOf(chunkCoords.x)+" "+String.valueOf(chunkCoords.y)+" "+String.valueOf(chunkCoords.z)+" "+String.valueOf(inChunkCoords.x)+" "+String.valueOf(inChunkCoords.y)+" "+String.valueOf(inChunkCoords.z)); - //LogManager.getLogger().info("FallingBlock is at "+String.valueOf(occupiedBlock.x)+" "+String.valueOf(occupiedBlock.y)+" "+String.valueOf(occupiedBlock.z)); - //LogManager.getLogger().info("Block is of type " + context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); - if (context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords) - .getId() != "Test:Air") { + // LogManager.getLogger().info("InChunk + // "+String.valueOf(chunkCoords.x)+" "+String.valueOf(chunkCoords.y)+" + // "+String.valueOf(chunkCoords.z)+" "+String.valueOf(inChunkCoords.x)+" + // "+String.valueOf(inChunkCoords.y)+" + // "+String.valueOf(inChunkCoords.z)); + // LogManager.getLogger().info("FallingBlock is at + // "+String.valueOf(occupiedBlock.x)+" + // "+String.valueOf(occupiedBlock.y)+" + // "+String.valueOf(occupiedBlock.z)); + // LogManager.getLogger().info("Block is of type " + + // context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId()); + + if (context.getWorldData().getChunk(chunkCoords).getBlock(inChunkCoords).getId() != "Test:Air") { LogManager.getLogger().info("Deleting FallingBlock at " + String.valueOf(occupiedBlock.x)); - //ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, fallBlock.getBlock(),true); + // ClientState.getInstance().getWorld().getData().setBlock(occupiedBlock, + // fallBlock.getBlock(),true); context.getAccessor().setBlock(occupiedBlock, fallBlock.getBlock()); - fallBlock.setInvisible(); //Until I know how to properly delete it. - //context.getWorldData().removeEntity(entity.getEntityId()); + fallBlock.setInvisible(); // Until I know how to properly delete it. + // context.getWorldData().removeEntity(entity.getEntityId()); } } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicStatie.java b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicStatie.java index 5fa66fb..f27abfe 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityLogicStatie.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityLogicStatie.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import ru.windcorp.progressia.common.world.entity.EntityData; diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java index fccb704..0adaa34 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderFallingBlock.java @@ -41,11 +41,13 @@ public class TestEntityRenderFallingBlock extends EntityRender { // LogManager.getLogger().info("Rendering FallingBlock"); if (((TestEntityDataFallingBlock) entity).isDone()) { return; - //setTexture(new SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/LogSide"), - // new AtlasGroup("Blocks", 1 << 12)))); + // setTexture(new + // SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/LogSide"), + // new AtlasGroup("Blocks", 1 << 12)))); } - //setTexture(new SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/Sand"), - // new AtlasGroup("Blocks", 1 << 12)))); + // setTexture(new + // SimpleTexture(Atlases.getSprite(ResourceManager.getTextureResource("blocks/Sand"), + // new AtlasGroup("Blocks", 1 << 12)))); cube.render(renderer); } }; diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderHuman.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderHuman.java index 388d89c..31b73ca 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderHuman.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderHuman.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import static java.lang.Math.toRadians; @@ -56,11 +56,7 @@ public class TestEntityRenderHuman extends EntityRender { this.skin = fetchSkin(); - ComplexTexture texture = new ComplexTexture( - this.skin, - 16, - 16 - ); + ComplexTexture texture = new ComplexTexture(this.skin, 16, 16); this.body = createBody(texture); this.head = createHead(texture); @@ -80,109 +76,37 @@ public class TestEntityRenderHuman extends EntityRender { } private Renderable createBody(ComplexTexture texture) { - return createLayeredCuboid( - texture, - 4, - 8, - 4, - 4, - 2, - 3, - 1, - -0.5f, - -1, - 3, - 1, - 2, - 3 - ); + return createLayeredCuboid(texture, 4, 8, 4, 4, 2, 3, 1, -0.5f, -1, 3, 1, 2, 3); } private Renderable createHead(ComplexTexture texture) { - return createLayeredCuboid( - texture, - 0, - 12, - 8, - 12, - 2, - 2, - 2, - -1, - -1, - 0, - 2, - 2, - 2 - ); + return createLayeredCuboid(texture, 0, 12, 8, 12, 2, 2, 2, -1, -1, 0, 2, 2, 2); } - private Renderable createLimb( - ComplexTexture texture, - int tx, - int ty, - int tx2, - int ty2, - boolean isArm, - boolean isLeft - ) { - Renderable model = createLayeredCuboid( - texture, - tx, - ty, - tx2, - ty2, - 1, - 3, - 1, - -0.5f, - -0.5f, - isArm ? -2.5f : -3f, - 1, - 1, - 3 - ); + private Renderable createLimb(ComplexTexture texture, int tx, int ty, int tx2, int ty2, boolean isArm, + boolean isLeft) { + Renderable model = createLayeredCuboid(texture, tx, ty, tx2, ty2, 1, 3, 1, -0.5f, -0.5f, isArm ? -2.5f : -3f, 1, + 1, 3); if (isArm) { - return LambdaModel.animate( - model, - mat -> { - double phase = GraphicsInterface.getTime() + (isLeft ? 0 : Math.PI / 3); - mat.rotateX((isLeft ? +1 : -1) * 1 / 40f * (sin(phase) + 1)); - mat.rotateY(1 / 20f * sin(Math.PI / 3 * phase)); - } - ); + return LambdaModel.animate(model, mat -> { + double phase = GraphicsInterface.getTime() + (isLeft ? 0 : Math.PI / 3); + mat.rotateX((isLeft ? +1 : -1) * 1 / 40f * (sin(phase) + 1)); + mat.rotateY(1 / 20f * sin(Math.PI / 3 * phase)); + }); } else { return model; } } - private Renderable createLayeredCuboid( - ComplexTexture texture, - int tx, - int ty, - int tx2, - int ty2, - int tw, - int th, - int td, - float ox, - float oy, - float oz, - float sx, - float sy, - float sz - ) { + private Renderable createLayeredCuboid(ComplexTexture texture, int tx, int ty, int tx2, int ty2, int tw, int th, + int td, float ox, float oy, float oz, float sx, float sy, float sz) { WorldRenderProgram program = WorldRenderProgram.getDefault(); StaticModel.Builder b = StaticModel.builder(); // First layer - b.addPart( - new PppBuilder( - program, - texture.getCuboidTextures(tx, ty, tw, th, td) - ).setOrigin(ox, oy, oz).setSize(sx, sy, sz).create() - ); + b.addPart(new PppBuilder(program, texture.getCuboidTextures(tx, ty, tw, th, td)).setOrigin(ox, oy, oz) + .setSize(sx, sy, sz).create()); ox -= SECOND_LAYER_OFFSET; oy -= SECOND_LAYER_OFFSET; @@ -193,55 +117,25 @@ public class TestEntityRenderHuman extends EntityRender { sz += SECOND_LAYER_OFFSET * 2; // Second layer - b.addPart( - new PppBuilder( - program, - texture.getCuboidTextures(tx2, ty2, tw, th, td) - ).setOrigin(ox, oy, oz).setSize(sx, sy, sz).create() - ); + b.addPart(new PppBuilder(program, texture.getCuboidTextures(tx2, ty2, tw, th, td)).setOrigin(ox, oy, oz) + .setSize(sx, sy, sz).create()); return b.build(); } @Override public EntityRenderable createRenderable(EntityData entity) { - return new HumanoidModel( - entity, + return new HumanoidModel(entity, - new HumanoidModel.Body(body), - new HumanoidModel.Head( - head, - new Vec3(0, 0, 6), - 70, - 25, - new Vec3(1.2f, 0, 1.5f) - ), - new HumanoidModel.Arm( - leftArm, - new Vec3(0, +1.5f, 3 + 3 - 0.5f), - 0.0f - ), - new HumanoidModel.Arm( - rightArm, - new Vec3(0, -1.5f, 3 + 3 - 0.5f), - FloatMathUtil.PI_F - ), - new HumanoidModel.Leg( - leftLeg, - new Vec3(0, +0.5f, 3), - FloatMathUtil.PI_F - ), - new HumanoidModel.Leg( - rightLeg, - new Vec3(0, -0.5f, 3), - 0.0f - ), + new HumanoidModel.Body(body), + new HumanoidModel.Head(head, new Vec3(0, 0, 6), 70, 25, new Vec3(1.2f, 0, 1.5f)), + new HumanoidModel.Arm(leftArm, new Vec3(0, +1.5f, 3 + 3 - 0.5f), 0.0f), + new HumanoidModel.Arm(rightArm, new Vec3(0, -1.5f, 3 + 3 - 0.5f), FloatMathUtil.PI_F), + new HumanoidModel.Leg(leftLeg, new Vec3(0, +0.5f, 3), FloatMathUtil.PI_F), + new HumanoidModel.Leg(rightLeg, new Vec3(0, -0.5f, 3), 0.0f), - 1.8f / (3 + 3 + 2) - ) - .setWalkingArmSwing((float) toRadians(30)) - .setWalkingLegSwing((float) toRadians(50)) - .setWalkingFrequency(0.15f / 60.0f); + 1.8f / (3 + 3 + 2)).setWalkingArmSwing((float) toRadians(30)).setWalkingLegSwing((float) toRadians(50)) + .setWalkingFrequency(0.15f / 60.0f); } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java index aefa1c6..aa3ad1b 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderJavapony.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import java.util.ArrayList; @@ -54,11 +54,7 @@ public class TestEntityRenderJavapony extends EntityRender { public TestEntityRenderJavapony(String id) { super(id); - ComplexTexture texture = new ComplexTexture( - EntityRenderRegistry.getEntityTexture("javapony"), - 256, - 128 - ); + ComplexTexture texture = new ComplexTexture(EntityRenderRegistry.getEntityTexture("javapony"), 256, 128); this.body = createBody(texture); this.head = createHead(texture); @@ -75,49 +71,20 @@ public class TestEntityRenderJavapony extends EntityRender { Texture tailStartTexture = texture.get(128, 96, 8, 32); - b.addStaticPart( - new PppBuilder( - WorldRenderProgram.getDefault(), - BlockFace.mapToFaces( - tailStartTexture, - tailStartTexture, - tailStartTexture, - tailStartTexture, - tailStartTexture, - tailStartTexture - ) - ) - .setOrigin(-60, -4, 14) - .setDepth(32, 0, -16).setWidth(8).setHeight(8) - .create() - ); + b.addStaticPart(new PppBuilder(WorldRenderProgram.getDefault(), + BlockFace.mapToFaces(tailStartTexture, tailStartTexture, tailStartTexture, tailStartTexture, + tailStartTexture, tailStartTexture)).setOrigin(-60, -4, 14).setDepth(32, 0, -16).setWidth(8) + .setHeight(8).create()); Texture neckTexture = texture.get(0, 48, 16, 16); - b.addStaticPart( - new PppBuilder( - WorldRenderProgram.getDefault(), - BlockFace.mapToFaces( - neckTexture, - neckTexture, - neckTexture, - neckTexture, - neckTexture, - neckTexture - ) - ) - .setOrigin(0, -8, 8) - .setWidth(16).setDepth(16).setHeight(2, 0, 16) - .create() - ); + b.addStaticPart(new PppBuilder(WorldRenderProgram.getDefault(), + BlockFace.mapToFaces(neckTexture, neckTexture, neckTexture, neckTexture, neckTexture, neckTexture)) + .setOrigin(0, -8, 8).setWidth(16).setDepth(16).setHeight(2, 0, 16).create()); - b.addDynamicPart( - createTail(texture), - m -> m - .translate(-60, 0, 24) - .rotateX(0.05f * Math.sin(GraphicsInterface.getTime())) - .rotateY(0.05f * Math.sin(Math.PI / 3 * GraphicsInterface.getTime())) - ); + b.addDynamicPart(createTail(texture), + m -> m.translate(-60, 0, 24).rotateX(0.05f * Math.sin(GraphicsInterface.getTime())) + .rotateY(0.05f * Math.sin(Math.PI / 3 * GraphicsInterface.getTime()))); return new LambdaModel(b); } @@ -127,192 +94,62 @@ public class TestEntityRenderJavapony extends EntityRender { List faces = new ArrayList<>(); // F BODY - faces.add( - Faces.createRectangle( - program, - texture.get(80, 16, 32, 32), - Colors.WHITE, - new Vec3(+16, -16, -16), - new Vec3(0, +32, 0), - new Vec3(0, 0, +32), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(80, 16, 32, 32), Colors.WHITE, new Vec3(+16, -16, -16), + new Vec3(0, +32, 0), new Vec3(0, 0, +32), false)); // NECK BASE - faces.add( - Faces.createRectangle( - program, - texture.get(80, 48, 32, 16), - Colors.WHITE, - new Vec3(+16, -16, +16), - new Vec3(0, +32, 0), - new Vec3(-16, 0, 0), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(80, 48, 32, 16), Colors.WHITE, new Vec3(+16, -16, +16), + new Vec3(0, +32, 0), new Vec3(-16, 0, 0), false)); // T BODY (BACK) - faces.add( - Faces.createRectangle( - program, - texture.get(128, 0, 32, 48), - Colors.WHITE, - new Vec3(0, -16, +16), - new Vec3(0, +32, 0), - new Vec3(-48, 0, 0), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(128, 0, 32, 48), Colors.WHITE, new Vec3(0, -16, +16), + new Vec3(0, +32, 0), new Vec3(-48, 0, 0), false)); // BOTTOM B (upper) - faces.add( - Faces.createRectangle( - program, - texture.get(144, 48, 32, 16), - Colors.WHITE, - new Vec3(-48, -16, 0), - new Vec3(0, 32, 0), - new Vec3(0, 0, 16), - true - ) - ); + faces.add(Faces.createRectangle(program, texture.get(144, 48, 32, 16), Colors.WHITE, new Vec3(-48, -16, 0), + new Vec3(0, 32, 0), new Vec3(0, 0, 16), true)); // BOTTOM B (lower) - faces.add( - Faces.createRectangle( - program, - texture.get(144, 48, 32, 16), - Colors.WHITE, - new Vec3(-48, -16, -16), - new Vec3(0, 32, 0), - new Vec3(0, 0, 16), - true - ) - ); + faces.add(Faces.createRectangle(program, texture.get(144, 48, 32, 16), Colors.WHITE, new Vec3(-48, -16, -16), + new Vec3(0, 32, 0), new Vec3(0, 0, 16), true)); // BOTTOM B (stomach) - faces.add( - Faces.createRectangle( - program, - texture.get(144, 48, 32, 16), - Colors.WHITE, - new Vec3(-48, -16, -16), - new Vec3(0, 32, 0), - new Vec3(16, 0, 0), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(144, 48, 32, 16), Colors.WHITE, new Vec3(-48, -16, -16), + new Vec3(0, 32, 0), new Vec3(16, 0, 0), false)); // STOMACH - faces.add( - Faces.createRectangle( - program, - texture.get(224, 96, 32, 32), - Colors.WHITE, - new Vec3(-32, -16, -16), - new Vec3(0, 32, 0), - new Vec3(32, 0, 0), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(224, 96, 32, 32), Colors.WHITE, new Vec3(-32, -16, -16), + new Vec3(0, 32, 0), new Vec3(32, 0, 0), false)); // BOTTOM F - faces.add( - Faces.createRectangle( - program, - texture.get(112, 48, 32, 16), - Colors.WHITE, - new Vec3(+16, -16, -16), - new Vec3(0, 32, 0), - new Vec3(-16, 0, 0), - true - ) - ); + faces.add(Faces.createRectangle(program, texture.get(112, 48, 32, 16), Colors.WHITE, new Vec3(+16, -16, -16), + new Vec3(0, 32, 0), new Vec3(-16, 0, 0), true)); // BODY L - faces.add( - Faces.createRectangle( - program, - texture.get(112, 16, 16, 32), - Colors.WHITE, - new Vec3(+16, +16, -16), - new Vec3(-16, 0, 0), - new Vec3(0, 0, +32), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(112, 16, 16, 32), Colors.WHITE, new Vec3(+16, +16, -16), + new Vec3(-16, 0, 0), new Vec3(0, 0, +32), false)); // BODY SIDES (left) - faces.add( - Faces.createRectangle( - program, - texture.get(96, 96, 32, 32), - Colors.WHITE, - new Vec3(0, +16, -16), - new Vec3(-32, 0, 0), - new Vec3(0, 0, +32), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(96, 96, 32, 32), Colors.WHITE, new Vec3(0, +16, -16), + new Vec3(-32, 0, 0), new Vec3(0, 0, +32), false)); // QT MARK (left) - faces.add( - Faces.createRectangle( - program, - texture.get(16, 96, 16, 32), - Colors.WHITE, - new Vec3(-32, +16, -16), - new Vec3(-16, 0, 0), - new Vec3(0, 0, +32), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(16, 96, 16, 32), Colors.WHITE, new Vec3(-32, +16, -16), + new Vec3(-16, 0, 0), new Vec3(0, 0, +32), false)); // BODY R - faces.add( - Faces.createRectangle( - program, - texture.get(64, 16, 16, 32), - Colors.WHITE, - new Vec3(0, -16, -16), - new Vec3(+16, 0, 0), - new Vec3(0, 0, +32), - false - ) - ); + faces.add(Faces.createRectangle(program, texture.get(64, 16, 16, 32), Colors.WHITE, new Vec3(0, -16, -16), + new Vec3(+16, 0, 0), new Vec3(0, 0, +32), false)); // BODY SIDES (right) - faces.add( - Faces.createRectangle( - program, - texture.get(96, 96, 32, 32), - Colors.WHITE, - new Vec3(0, -16, -16), - new Vec3(-32, 0, 0), - new Vec3(0, 0, +32), - true - ) - ); + faces.add(Faces.createRectangle(program, texture.get(96, 96, 32, 32), Colors.WHITE, new Vec3(0, -16, -16), + new Vec3(-32, 0, 0), new Vec3(0, 0, +32), true)); // QT MARK (right) - faces.add( - Faces.createRectangle( - program, - texture.get(16, 96, 16, 32), - Colors.WHITE, - new Vec3(-32, -16, -16), - new Vec3(-16, 0, 0), - new Vec3(0, 0, +32), - true - ) - ); + faces.add(Faces.createRectangle(program, texture.get(16, 96, 16, 32), Colors.WHITE, new Vec3(-32, -16, -16), + new Vec3(-16, 0, 0), new Vec3(0, 0, +32), true)); - return new Shape( - Usage.STATIC, - program, - faces.toArray(new Face[faces.size()]) - ); + return new Shape(Usage.STATIC, program, faces.toArray(new Face[faces.size()])); } private static Renderable createHead(ComplexTexture texture) { @@ -320,87 +157,42 @@ public class TestEntityRenderJavapony extends EntityRender { StaticModel.Builder b = StaticModel.builder(); // Head - b.addPart( - new PppBuilder( - program, - texture.getCuboidTextures(0, 64, 32) - ).setOrigin(-16, -16, 0).setSize(32).create() - ); + b.addPart(new PppBuilder(program, texture.getCuboidTextures(0, 64, 32)).setOrigin(-16, -16, 0).setSize(32) + .create()); final float hairOffset = 1f; // Hair - b.addPart( - new PppBuilder( - program, - texture.getCuboidTextures(128, 64, 32) - ) - .setOrigin(-16 - hairOffset, -16 - hairOffset, -hairOffset) - .setSize(32 + 2 * hairOffset) - .create() - ); + b.addPart(new PppBuilder(program, texture.getCuboidTextures(128, 64, 32)) + .setOrigin(-16 - hairOffset, -16 - hairOffset, -hairOffset).setSize(32 + 2 * hairOffset).create()); // Right ear - b.addPart( - new PppBuilder( - program, - texture.getCuboidTextures(48, 128 - 80, 8) - ).setOrigin(-16 + 3, -16, 32).setSize(8).create() - ); + b.addPart(new PppBuilder(program, texture.getCuboidTextures(48, 128 - 80, 8)).setOrigin(-16 + 3, -16, 32) + .setSize(8).create()); // Left ear - b.addPart( - new PppBuilder( - program, - texture.getCuboidTextures(48, 128 - 80, 8) - ).setOrigin(-16 + 3, +16, 32).setSize(8, -8, 8).flip().create() - ); + b.addPart(new PppBuilder(program, texture.getCuboidTextures(48, 128 - 80, 8)).setOrigin(-16 + 3, +16, 32) + .setSize(8, -8, 8).flip().create()); // Muzzle - b.addPart( - new PppBuilder( - program, - BlockFace.mapToFaces( - texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0), - texture.get(32 + 8, 64, 16, 8), - texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0) - ) - ).setOrigin(16, -8, 0).setSize(4, 16, 8).create() - ); + b.addPart(new PppBuilder(program, + BlockFace.mapToFaces(texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), + texture.get(32 + 8, 64, 16, 8), texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0))).setOrigin(16, -8, 0).setSize(4, 16, 8).create()); // Nose - b.addPart( - new PppBuilder( - program, - BlockFace.mapToFaces( - texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0), - texture.get(32 + 12, 64 + 8, 8, 4), - texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0), - texture.get(32, 64, 0, 0) - ) - ).setOrigin(16, -4, 8).setSize(4, 8, 4).create() - ); + b.addPart(new PppBuilder(program, + BlockFace.mapToFaces(texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), + texture.get(32 + 12, 64 + 8, 8, 4), texture.get(32, 64, 0, 0), texture.get(32, 64, 0, 0), + texture.get(32, 64, 0, 0))).setOrigin(16, -4, 8).setSize(4, 8, 4).create()); return b.build(); } - private static Renderable createLeg( - ComplexTexture texture, - int textureX, - int textureY, - boolean isLeft - ) { - PppBuilder b = new PppBuilder( - WorldRenderProgram.getDefault(), - texture.getCuboidTextures(textureX, textureY, 16, 48, 16) - ) - .setOrigin(-8, isLeft ? +8 : -8, -48) - .setSize(16, isLeft ? -16 : +16, 48); + private static Renderable createLeg(ComplexTexture texture, int textureX, int textureY, boolean isLeft) { + PppBuilder b = new PppBuilder(WorldRenderProgram.getDefault(), + texture.getCuboidTextures(textureX, textureY, 16, 48, 16)).setOrigin(-8, isLeft ? +8 : -8, -48) + .setSize(16, isLeft ? -16 : +16, 48); if (isLeft) b.flip(); @@ -413,59 +205,26 @@ public class TestEntityRenderJavapony extends EntityRender { StaticModel.Builder b = StaticModel.builder(); // Main tail - b.addPart( - new PppBuilder( - program, - BlockFace.mapToFaces( - texture.get(128, 96, 16, 16), - texture.get(128, 96, 16, 16), - texture.get(128, 96, 16, 32), - texture.get(128, 96, 16, 32), - texture.get(144, 96, 16, 32), - texture.get(144, 96, 16, 32) - ) - ).setOrigin(-8, -8, -32).setSize(16, 16, 32).create() - ); + b.addPart(new PppBuilder(program, + BlockFace.mapToFaces(texture.get(128, 96, 16, 16), texture.get(128, 96, 16, 16), + texture.get(128, 96, 16, 32), texture.get(128, 96, 16, 32), texture.get(144, 96, 16, 32), + texture.get(144, 96, 16, 32))).setOrigin(-8, -8, -32).setSize(16, 16, 32).create()); return b.build(); } @Override public EntityRenderable createRenderable(EntityData entity) { - return new QuadripedModel( - entity, + return new QuadripedModel(entity, - new QuadripedModel.Body(body), - new QuadripedModel.Head( - head, - new Vec3(12, 0, 20), - 120, - 45, - new Vec3(16, 0, 20) - ), - new QuadripedModel.Leg( - leftForeLeg, - new Vec3(6, +8.1f, -16), - 0.0f - ), - new QuadripedModel.Leg( - rightForeLeg, - new Vec3(6, -8.1f, -16), - 2.5f - ), - new QuadripedModel.Leg( - leftHindLeg, - new Vec3(-36, +8.2f, -16), - 2.5f - ), - new QuadripedModel.Leg( - rightHindLeg, - new Vec3(-36, -8.2f, -16), - 0.0f - ), + new QuadripedModel.Body(body), + new QuadripedModel.Head(head, new Vec3(12, 0, 20), 120, 45, new Vec3(16, 0, 20)), + new QuadripedModel.Leg(leftForeLeg, new Vec3(6, +8.1f, -16), 0.0f), + new QuadripedModel.Leg(rightForeLeg, new Vec3(6, -8.1f, -16), 2.5f), + new QuadripedModel.Leg(leftHindLeg, new Vec3(-36, +8.2f, -16), 2.5f), + new QuadripedModel.Leg(rightHindLeg, new Vec3(-36, -8.2f, -16), 0.0f), - 1 / 96f - ); + 1 / 96f); } } diff --git a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderStatie.java b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderStatie.java index 47990fd..af5ed11 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestEntityRenderStatie.java +++ b/src/main/java/ru/windcorp/progressia/test/TestEntityRenderStatie.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import ru.windcorp.progressia.client.graphics.model.Renderable; @@ -29,12 +29,8 @@ import ru.windcorp.progressia.common.world.entity.EntityData; public class TestEntityRenderStatie extends EntityRender { - private final Renderable cube = new Shapes.PppBuilder( - WorldRenderProgram.getDefault(), - (Texture) null - ) - .setColorMultiplier(1, 1, 0) - .create(); + private final Renderable cube = new Shapes.PppBuilder(WorldRenderProgram.getDefault(), (Texture) null) + .setColorMultiplier(1, 1, 0).create(); public TestEntityRenderStatie(String id) { super(id); @@ -45,9 +41,7 @@ public class TestEntityRenderStatie extends EntityRender { return new EntityRenderable(entity) { @Override public void render(ShapeRenderHelper renderer) { - renderer.pushTransform().scale( - ((TestEntityDataStatie) entity).getSize() / 24.0f - ); + renderer.pushTransform().scale(((TestEntityDataStatie) entity).getSize() / 24.0f); cube.render(renderer); diff --git a/src/main/java/ru/windcorp/progressia/test/TestMusicPlayer.java b/src/main/java/ru/windcorp/progressia/test/TestMusicPlayer.java index 1674d5b..ac221d8 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestMusicPlayer.java +++ b/src/main/java/ru/windcorp/progressia/test/TestMusicPlayer.java @@ -38,41 +38,41 @@ import ru.windcorp.progressia.common.resource.ResourceManager; import ru.windcorp.progressia.common.util.crash.CrashReports; public class TestMusicPlayer implements Runnable { - + private static final int MIN_SILENCE = 15 * 1000; // 15 seconds private static final int MAX_SILENCE = 60 * 1000; // one minute - + private static TestMusicPlayer instance = null; - + private final List compositions = new ArrayList<>(); - + private final Random random = new Random(); private long nextStart; private Sound lastStarted = null; - + public TestMusicPlayer() { this.nextStart = System.currentTimeMillis(); - + instance = this; } - + public static void start() { Thread thread = new Thread(new TestMusicPlayer(), "Music Thread"); thread.setDaemon(true); thread.start(); } - + @Override public void run() { loadCompositions(); - + if (compositions.isEmpty()) { LogManager.getLogger().warn("No music found"); return; } - + while (true) { - + try { synchronized (this) { while (true) { @@ -88,39 +88,39 @@ public class TestMusicPlayer implements Runnable { LogManager.getLogger().warn("Received interrupt in music thread, terminating thread..."); return; } - + startNextComposition(); - + } } private void loadCompositions() { try { - + Path directory = Paths.get("music"); - + if (!Files.isDirectory(directory)) { Files.createDirectories(directory); } - + Iterator it = Files.walk(directory).filter(Files::isRegularFile).iterator(); int i = 0; - + while (it.hasNext()) { String file = it.next().toString(); if (!file.endsWith(".ogg") && !file.endsWith(".oga")) { LogManager.getLogger().warn("Skipping " + file + ": not .ogg nor .oga"); } - + String id = "Progressia:Music" + (i++); - + AudioManager.loadSound(ResourceManager.getFileResource(file.toString()), id, AudioFormat.STEREO); SoundType composition = AudioRegistry.getInstance().get(id); compositions.add(composition); - + LogManager.getLogger().info("Loaded " + file); } - + } catch (IOException e) { throw CrashReports.report(e, "Could not load music"); } @@ -129,20 +129,21 @@ public class TestMusicPlayer implements Runnable { private synchronized void startNextComposition() { int index = random.nextInt(compositions.size()); SoundType composition = compositions.get(index); - + long now = System.currentTimeMillis(); long durationInMs = (long) (composition.getDuration() * 1000); long silence = random.nextInt(MAX_SILENCE - MIN_SILENCE) + MIN_SILENCE; - + nextStart = now + durationInMs + silence; - + lastStarted = new Music(composition); lastStarted.play(false); } - + public static void startNextNow() { - if (instance == null) return; - + if (instance == null) + return; + synchronized (instance) { instance.nextStart = System.currentTimeMillis(); instance.notifyAll(); diff --git a/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java b/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java index f129255..f9b4439 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java +++ b/src/main/java/ru/windcorp/progressia/test/TestPlayerControls.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import glm.Glm; @@ -119,12 +119,8 @@ public class TestPlayerControls { desiredVelocity.z = movementUp; desiredVelocity.mul(speed); - Vec3 change = new Vec3() - .set(desiredVelocity) - .sub(player.getVelocity()) - .mul((float) Math.exp(-authority * GraphicsInterface.getFrameLength())) - .negate() - .add(desiredVelocity); + Vec3 change = new Vec3().set(desiredVelocity).sub(player.getVelocity()) + .mul((float) Math.exp(-authority * GraphicsInterface.getFrameLength())).negate().add(desiredVelocity); if (!isFlying) { change.z = player.getVelocity().z; @@ -134,7 +130,7 @@ public class TestPlayerControls { // THIS IS TERRIBLE TEST EntityData serverEntity = ServerState.getInstance().getWorld().getData() - .getEntity(TestContent.PLAYER_ENTITY_ID); + .getEntity(TestContent.PLAYER_ENTITY_ID); if (serverEntity != null) { serverEntity.setPosition(player.getPosition()); } @@ -356,12 +352,8 @@ public class TestPlayerControls { EntityData player = getEntity(); - normalizeAngles( - player.getDirection().add( - (float) (event.getChangeX() * yawScale), - (float) (event.getChangeY() * pitchScale) - ) - ); + normalizeAngles(player.getDirection().add((float) (event.getChangeX() * yawScale), + (float) (event.getChangeY() * pitchScale))); } private void normalizeAngles(Vec2 dir) { @@ -369,11 +361,7 @@ public class TestPlayerControls { dir.x = FloatMathUtil.normalizeAngle(dir.x); // Clamp pitch - dir.y = Glm.clamp( - dir.y, - -FloatMathUtil.PI_F / 2, - +FloatMathUtil.PI_F / 2 - ); + dir.y = Glm.clamp(dir.y, -FloatMathUtil.PI_F / 2, +FloatMathUtil.PI_F / 2); } private void onWheelScroll(WheelScrollEvent event) { diff --git a/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java b/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java index 06afc77..e6514ca 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java +++ b/src/main/java/ru/windcorp/progressia/test/TestTileLogicGrass.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import ru.windcorp.progressia.common.world.block.BlockFace; diff --git a/src/main/java/ru/windcorp/progressia/test/TestWorldDiskIO.java b/src/main/java/ru/windcorp/progressia/test/TestWorldDiskIO.java index 97a0d99..7d10013 100644 --- a/src/main/java/ru/windcorp/progressia/test/TestWorldDiskIO.java +++ b/src/main/java/ru/windcorp/progressia/test/TestWorldDiskIO.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - + package ru.windcorp.progressia.test; import java.io.BufferedInputStream; @@ -52,29 +52,15 @@ public class TestWorldDiskIO { return; try { - LOG.debug( - "Saving {} {} {}", - chunk.getPosition().x, - chunk.getPosition().y, - chunk.getPosition().z - ); + LOG.debug("Saving {} {} {}", chunk.getPosition().x, chunk.getPosition().y, chunk.getPosition().z); Files.createDirectories(SAVE_DIR); - Path path = SAVE_DIR.resolve( - String.format( - "chunk_%+d_%+d_%+d.progressia_chunk", - chunk.getPosition().x, - chunk.getPosition().y, - chunk.getPosition().z - ) - ); + Path path = SAVE_DIR.resolve(String.format("chunk_%+d_%+d_%+d.progressia_chunk", chunk.getPosition().x, + chunk.getPosition().y, chunk.getPosition().z)); - try ( - DataOutputStream output = new DataOutputStream( - new DeflaterOutputStream(new BufferedOutputStream(Files.newOutputStream(path))) - ) - ) { + try (DataOutputStream output = new DataOutputStream( + new DeflaterOutputStream(new BufferedOutputStream(Files.newOutputStream(path))))) { ChunkIO.save(chunk, output, IOContext.SAVE); writeGenerationHint(chunk, output, server); } @@ -84,7 +70,7 @@ public class TestWorldDiskIO { } private static void writeGenerationHint(ChunkData chunk, DataOutputStream output, Server server) - throws IOException { + throws IOException { server.getWorld().getGenerator().writeGenerationHint(output, chunk.getGenerationHint()); } @@ -92,22 +78,11 @@ public class TestWorldDiskIO { if (!ENABLE) return null; - Path path = SAVE_DIR.resolve( - String.format( - "chunk_%+d_%+d_%+d.progressia_chunk", - chunkPos.x, - chunkPos.y, - chunkPos.z - ) - ); + Path path = SAVE_DIR + .resolve(String.format("chunk_%+d_%+d_%+d.progressia_chunk", chunkPos.x, chunkPos.y, chunkPos.z)); if (!Files.exists(path)) { - LOG.debug( - "Not found {} {} {}", - chunkPos.x, - chunkPos.y, - chunkPos.z - ); + LOG.debug("Not found {} {} {}", chunkPos.x, chunkPos.y, chunkPos.z); return null; } @@ -115,34 +90,20 @@ public class TestWorldDiskIO { try { ChunkData result = load(path, chunkPos, world, server); - LOG.debug( - "Loaded {} {} {}", - chunkPos.x, - chunkPos.y, - chunkPos.z - ); + LOG.debug("Loaded {} {} {}", chunkPos.x, chunkPos.y, chunkPos.z); return result; } catch (Exception e) { e.printStackTrace(); - LOG.debug( - "Could not load {} {} {}", - chunkPos.x, - chunkPos.y, - chunkPos.z - ); + LOG.debug("Could not load {} {} {}", chunkPos.x, chunkPos.y, chunkPos.z); return null; } } private static ChunkData load(Path path, Vec3i chunkPos, WorldData world, Server server) - throws IOException, - DecodingException { - try ( - DataInputStream input = new DataInputStream( - new InflaterInputStream(new BufferedInputStream(Files.newInputStream(path))) - ) - ) { + throws IOException, DecodingException { + try (DataInputStream input = new DataInputStream( + new InflaterInputStream(new BufferedInputStream(Files.newInputStream(path))))) { ChunkData chunk = ChunkIO.load(world, chunkPos, input, IOContext.SAVE); readGenerationHint(chunk, input, server); return chunk; @@ -150,8 +111,7 @@ public class TestWorldDiskIO { } private static void readGenerationHint(ChunkData chunk, DataInputStream input, Server server) - throws IOException, - DecodingException { + throws IOException, DecodingException { chunk.setGenerationHint(server.getWorld().getGenerator().readGenerationHint(input)); } diff --git a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java index bb3acc9..8ce6e45 100644 --- a/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java +++ b/src/main/java/ru/windcorp/progressia/test/gen/TestWorldGenerator.java @@ -57,15 +57,22 @@ public class TestWorldGenerator extends AbstractWorldGenerator { @Override public void onChunkLoaded(WorldData world, ChunkData chunk) { findAndPopulate(chunk.getPosition(), world); - chunk.addListener(new ChunkDataListener() { //Falling Block spawning logic + chunk.addListener(new ChunkDataListener() { // Falling Block + // spawning logic @Override public void onChunkBlockChanged(ChunkData chunk, Vec3i blockInChunk, BlockData previous, BlockData current) { + Vec3i chunkWorldPos = chunk.getPosition().mul_(16).add_(blockInChunk); + + if (TestEntityLogicFallingBlock.FallingBlocks.contains(chunk.getWorld() + .getBlock(chunkWorldPos.add_(0, 0, 1)).getId())) { + chunk.getWorld().setBlock(chunkWorldPos.add_(0, 0, 1), BlockDataRegistry.getInstance().get(chunk.getWorld().getBlock(chunkWorldPos.add_(0,0,1)).getId()), true); + } if (!TestEntityLogicFallingBlock.FallingBlocks.contains(current.getId())) { return; } - if (chunk.getWorld().getBlock(chunk.getPosition().mul_(16).add_(blockInChunk.add_(0, 0, -1))).getId() == "Test:Air") - { + if (chunk.getWorld().getBlock(chunkWorldPos.add_(0, 0, -1)) + .getId() == "Test:Air") { LogManager.getLogger().info("Inserting FallingBlock"); TestEntityDataFallingBlock fallingBlock = new TestEntityDataFallingBlock(); @@ -78,10 +85,11 @@ public class TestWorldGenerator extends AbstractWorldGenerator { + String.valueOf(new Random().nextFloat())).hashCode()); chunk.getWorld().addEntity(fallingBlock); - + chunk.setBlock(blockInChunk, previous, false); - Vec3i chunkWorldPos = chunk.getPosition().mul_(16).add_(blockInChunk); - LogManager.getLogger().info(String.valueOf(chunkWorldPos.x)+" "+String.valueOf(chunkWorldPos.y)+" "+String.valueOf(chunkWorldPos.z)); + + LogManager.getLogger().info(String.valueOf(chunkWorldPos.x) + " " + + String.valueOf(chunkWorldPos.y) + " " + String.valueOf(chunkWorldPos.z)); } } });