Skip to content

Commit

Permalink
Simple /test command, also added some functions to location
Browse files Browse the repository at this point in the history
  • Loading branch information
Abelkrijgtalles committed Dec 18, 2024
1 parent cf446af commit 455199c
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.List;
import net.minecraft.DetectedVersion;
import nl.abelkrijgtalles.mojangmaps.common.command.Commands;
import nl.abelkrijgtalles.mojangmaps.common.config.ConfigItem;
import nl.abelkrijgtalles.mojangmaps.common.config.ConfigObject;
import nl.abelkrijgtalles.mojangmaps.common.config.roads.RoadData;
Expand All @@ -46,6 +47,9 @@ public static void init(LoaderInfo loaderInfo) {
RoadData roadData = new RoadData();
if (!loaderInfo.isRunningTests()) roadData.setupRoadData();

Commands commands = new Commands();
commands.register();

}

public static List<ConfigObject> getDefaultConfig() {
Expand Down
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;
})
);

}

}
21 changes: 21 additions & 0 deletions patches/pathfinding/0005-Add-Location-toString.patch
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());
+
+ }
+
}
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());
+
+ }
+
}

0 comments on commit 455199c

Please sign in to comment.