-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple /test command, also added some functions to location
- Loading branch information
1 parent
cf446af
commit 455199c
Showing
4 changed files
with
123 additions
and
0 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
61 changes: 61 additions & 0 deletions
61
common/src/main/java/nl/abelkrijgtalles/mojangmaps/common/command/Commands.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,61 @@ | ||
/* | ||
* mojang_maps.common.main | ||
* Copyright (C) 2024 Abel van Hulst/Abelkrijgtalles/Abelpro678 | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package nl.abelkrijgtalles.mojangmaps.common.command; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.phys.Vec3; | ||
import nl.abelkrijgtalles.mojangmaps.common.MojangMaps; | ||
import nl.abelkrijgtalles.mojangmaps.pathfinding.AStar; | ||
import nl.abelkrijgtalles.mojangmaps.pathfinding.platform.Location; | ||
import static com.mojang.brigadier.builder.LiteralArgumentBuilder.literal; | ||
|
||
public class Commands { | ||
|
||
@SuppressWarnings({"unchecked", "rawtypes"}) | ||
public void register() { | ||
|
||
CommandDispatcher<CommandSourceStack> dispatcher = new CommandDispatcher(); | ||
|
||
dispatcher.register((LiteralArgumentBuilder) | ||
literal("test") | ||
.executes(context -> { | ||
CommandSourceStack source = (CommandSourceStack) context.getSource(); | ||
AStar aStar = new AStar(new Location( | ||
new Vec3(0, 60, 0), source.getLevel() | ||
), new Location( | ||
new Vec3(2, 60, 30), source.getLevel() | ||
)); | ||
|
||
for (Location location : aStar.getPath()) { | ||
|
||
MojangMaps.LOGGER.info(location.toString()); | ||
location.getLevel().setBlock(location.getPositionAsBlockPos(), Blocks.GLASS.defaultBlockState(), 3); | ||
|
||
} | ||
|
||
return 1; | ||
}) | ||
); | ||
|
||
} | ||
|
||
} |
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,21 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Abel <[email protected]> | ||
Date: Wed, 18 Dec 2024 19:27:15 +0100 | ||
Subject: [PATCH] Add Location#toString() | ||
|
||
|
||
diff --git a/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java b/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java | ||
index 34164f4b8ce232fdfcf32f04dbf7e34779cd1a6a..43f78ad2a412d2563aa0311cd2248c96787fe34c 100644 | ||
--- a/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java | ||
+++ b/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java | ||
@@ -128,4 +128,10 @@ public class Location implements Cloneable { | ||
|
||
} | ||
|
||
+ public String toString() { | ||
+ | ||
+ return String.format("%s in X: %s Y: %s Z: %s", getBlock().getName().getString(), getX(), getY(), getZ()); | ||
+ | ||
+ } | ||
+ | ||
} |
37 changes: 37 additions & 0 deletions
37
patches/pathfinding/0006-Add-Location-getPositionAsBlockPosition.patch
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,37 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: Abel <[email protected]> | ||
Date: Wed, 18 Dec 2024 19:32:02 +0100 | ||
Subject: [PATCH] Add Location#getPositionAsBlockPosition() | ||
|
||
|
||
diff --git a/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java b/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java | ||
index 43f78ad2a412d2563aa0311cd2248c96787fe34c..4ab3fa0545e8dcacfd1481a37234503e2dd2acf4 100644 | ||
--- a/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java | ||
+++ b/src/main/java/nl/abelkrijgtalles/mojangmaps/pathfinding/platform/Location.java | ||
@@ -101,13 +101,13 @@ public class Location implements Cloneable { | ||
|
||
public Block getBlock() { | ||
|
||
- return level.getBlockState(new BlockPos(getBlockX(), getBlockY(), getBlockZ())).getBlock(); | ||
+ return level.getBlockState(getPositionAsBlockPos()).getBlock(); | ||
|
||
} | ||
|
||
public BlockState getBLockState() { | ||
|
||
- return level.getBlockState(new BlockPos(getBlockX(), getBlockY(), getBlockZ())); | ||
+ return level.getBlockState(getPositionAsBlockPos()); | ||
|
||
} | ||
|
||
@@ -134,4 +134,10 @@ public class Location implements Cloneable { | ||
|
||
} | ||
|
||
+ public BlockPos getPositionAsBlockPos() { | ||
+ | ||
+ return new BlockPos(getBlockX(), getBlockY(), getBlockZ()); | ||
+ | ||
+ } | ||
+ | ||
} |