Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/dev_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
uses: marvinpinto/action-automatic-releases@latest
with:
repo_token: '${{ secrets.GITHUB_TOKEN }}'
automatic_release_tag: "1.21.1_1.0.0.1"
automatic_release_tag: "1.21.1_1.0.0.2"
prerelease: true
title: "1.21.1 | 1.0.0.1"
title: "1.21.1 | 1.0.0.2"
files: |
./build/libs/*.jar
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ yarn_mappings=1.21+build.3
loader_version=0.15.11

# Mod Properties
mod_version=1.21.1_1.0.0.1
mod_version=1.21.1_1.0.0.2
maven_group=nekiplay.protrainer
archives_base_name=pro-trainer

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/nekiplay/protrainer/ProTrainerAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.addons.GithubRepo;
import meteordevelopment.meteorclient.commands.Commands;
import meteordevelopment.meteorclient.systems.modules.Modules;
import nekiplay.protrainer.features.commands.TrainerCommand;
import nekiplay.protrainer.features.modules.ProTrainerModule;
import net.fabricmc.loader.api.FabricLoader;
import meteordevelopment.meteorclient.addons.MeteorAddon;
import org.slf4j.Logger;
Expand All @@ -20,17 +22,22 @@ public static ProTrainerAddon getInstance() {
return instance;
}

public ProTrainerModule module = new ProTrainerModule();

@Override
public void onInitialize() {
instance = this;

LOG.info(METEOR_LOGPREFIX + " Initializing...");
LOG.info("Initializing...");

Modules.get().add(module);

TrainerCommand command = new TrainerCommand();
Commands.add(command);
MeteorClient.EVENT_BUS.subscribe(command);

LOG.info("Initializing done");

}

@Override
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/nekiplay/protrainer/data/BlockData.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
package nekiplay.protrainer.data;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;

public class BlockData {
public int blockId;
public BlockPosition blockPosition;
public int blockId = 0;

public BlockData() {}

public BlockData(int rawId) {
this.blockId = rawId;
}

public BlockState toBlockState() {
return Block.getStateFromRawId(blockId);
}
}
15 changes: 15 additions & 0 deletions src/main/java/nekiplay/protrainer/data/BlockDataAndPosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package nekiplay.protrainer.data;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;

public class BlockDataAndPosition {
public int blockId = 0;
public BlockPosition blockPosition;

@Override
public int hashCode() {
return blockPosition.hashCode();
}
}
24 changes: 24 additions & 0 deletions src/main/java/nekiplay/protrainer/data/BlockPosition.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package nekiplay.protrainer.data;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.impl.lib.sat4j.core.Vec;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

Expand All @@ -23,4 +26,25 @@ public BlockPosition(Vec3d pos) {
public BlockPosition() {

}

@Override
public int hashCode() {
return new Vec3d(x, y, z).hashCode();
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BlockPosition other = (BlockPosition) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return z == other.z;
}
}
5 changes: 3 additions & 2 deletions src/main/java/nekiplay/protrainer/data/ProTrainerMap.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package nekiplay.protrainer.data;

import java.util.ArrayList;
import java.util.List;

public class ProTrainerMap {
public ArrayList<BlockData> blocks = new ArrayList<>();
public BlockPosition start = new BlockPosition();
public List<BlockDataAndPosition> blocks = new ArrayList<>();


}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import meteordevelopment.meteorclient.MeteorClient;
import meteordevelopment.meteorclient.commands.Command;
import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.events.world.BlockUpdateEvent;
import meteordevelopment.orbit.EventHandler;
import nekiplay.Main;
import nekiplay.protrainer.ProTrainerAddon;
import nekiplay.protrainer.data.BlockData;
import nekiplay.protrainer.data.BlockDataAndPosition;
import nekiplay.protrainer.data.BlockPosition;
import nekiplay.protrainer.data.ProTrainerMap;
import nekiplay.protrainer.mixin.minecraft.PlayerMoveC2SPacketAccesor;
Expand All @@ -28,6 +30,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -42,7 +45,8 @@ public TrainerCommand() {
public boolean started = false;
public Vec3d start_position = new Vec3d(0, 0, 0);

public List<BlockData> replaced = new ArrayList<>();
public List<BlockDataAndPosition> replaced = new ArrayList<>();
public HashMap<BlockPosition, BlockData> map_blocks = new HashMap<>();

public void build(LiteralArgumentBuilder<CommandSource> builder) {
builder.then(literal("pos1").executes(context -> {
Expand All @@ -69,35 +73,52 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
}
File dir2 = new File(dir, map + ".json");

try {
BufferedReader reader = Files.newBufferedReader(Path.of(dir2.toURI()), StandardCharsets.UTF_8);
try {
String json = reader.lines().collect(Collectors.joining());

ProTrainerMap proTrainerMap = gson.fromJson(json, ProTrainerMap.class);
for (BlockData data : proTrainerMap.blocks) {
assert mc.world != null;
BlockState state = Block.getStateFromRawId(data.blockId);
BlockPos pos = new BlockPos((int) (data.blockPosition.x + mc.player.getBlockX()), (int) (data.blockPosition.y + mc.player.getBlockY()), (int) (data.blockPosition.z + mc.player.getBlockZ()));

BlockData blockData = new BlockData();
blockData.blockPosition = new BlockPosition(pos);
blockData.blockId = Block.getRawIdFromState(mc.world.getBlockState(pos));
replaced.add(blockData);
start_position = mc.player.getPos();

mc.world.setBlockState(pos, state);
new Thread(() -> {
try {
map_blocks.clear();
BufferedReader reader = Files.newBufferedReader(Path.of(dir2.toURI()), StandardCharsets.UTF_8);
try {
String json = reader.lines().collect(Collectors.joining());
int counter = 0;
ProTrainerMap proTrainerMap = gson.fromJson(json, ProTrainerMap.class);
for (BlockDataAndPosition data : proTrainerMap.blocks) {
assert mc.world != null;
BlockState state = Block.getStateFromRawId(data.blockId);
mc.player.setPos(start_position.x, start_position.y, start_position.z);
BlockPos pos = new BlockPos((int) (data.blockPosition.x + mc.player.getBlockX()), (int) (data.blockPosition.y + mc.player.getBlockY()), (int) (data.blockPosition.z + mc.player.getBlockZ()));

BlockDataAndPosition blockData = new BlockDataAndPosition();
blockData.blockPosition = new BlockPosition(pos);
blockData.blockId = Block.getRawIdFromState(mc.world.getBlockState(pos));
replaced.add(blockData);
map_blocks.put(new BlockPosition(pos), new BlockData(data.blockId));

BlockState original_state = mc.world.getBlockState(pos);
if (original_state.getBlock() != state.getBlock()) {
mc.execute(() -> mc.world.setBlockState(pos, state));
if (counter >= ProTrainerAddon.getInstance().module.loadingSpeed.get()) {
Thread.sleep(1);
counter = 0;
} else {
counter++;
}
}
}
info("Successfully loaded");

} catch (JsonSyntaxException e) {
ProTrainerAddon.LOG.error(Main.METEOR_LOGPREFIX + " Error in custom block: " + e);

} catch (InterruptedException e) {
ProTrainerAddon.LOG.error(Main.METEOR_LOGPREFIX + " Error in custom block: " + e);
}

} catch (JsonSyntaxException e) {
} catch (IOException e) {
ProTrainerAddon.LOG.error(Main.METEOR_LOGPREFIX + " Error in custom block: " + e);

}
} catch (IOException e) {
ProTrainerAddon.LOG.error(Main.METEOR_LOGPREFIX + " Error in custom block: " + e);
}
info("Successfully loaded");
start_position = mc.player.getPos();
started = true;
started = true;
}).start();
return SINGLE_SUCCESS;
}
else {
Expand All @@ -110,16 +131,29 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
info("Parkour hasn't started");
return SINGLE_SUCCESS;
}
for (BlockData replace : replaced) {
mc.player.setPos(start_position.x, start_position.y, start_position.z);
BlockState state = Block.getStateFromRawId(replace.blockId);
BlockPos pos = new BlockPos((int) replace.blockPosition.x, (int) replace.blockPosition.y, (int) replace.blockPosition.z);
mc.world.setBlockState(pos, state);
new Thread(() -> {
int counter = 0;
map_blocks.clear();
for (BlockDataAndPosition replace : replaced) {
BlockState state = Block.getStateFromRawId(replace.blockId);
BlockPos pos = new BlockPos((int) replace.blockPosition.x, (int) replace.blockPosition.y, (int) replace.blockPosition.z);
mc.execute(() -> mc.world.setBlockState(pos, state));
if (counter >= ProTrainerAddon.getInstance().module.loadingSpeed.get()) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
counter = 0;
} else {
counter++;
}
}
mc.player.setPos(start_position.x, start_position.y, start_position.z);
started = false;
}
replaced.clear();
info("Parkour has been stopped");
replaced.clear();
info("Parkour has been stopped");
}).start();
return SINGLE_SUCCESS;
}));
builder.then(literal("save").then(argument("map", StringArgumentType.string()).executes(context -> {
Expand All @@ -134,7 +168,6 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
String map = context.getArgument("map", String.class);
Vec3d start = mc.player.getPos();
ProTrainerMap trainerMap = new ProTrainerMap();
trainerMap.start = new BlockPosition(start);

List<BlockPos> blocks = collectBlocksBetween(mc.world, pos1, pos2);
List<BlockPos> sortedBlocks = new ArrayList<>();
Expand All @@ -144,7 +177,7 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) {
for (BlockPos sorted : sortedBlocks) {
var unsorted = sorted.add(new Vec3i(mc.player.getBlockX(), mc.player.getBlockY(), mc.player.getBlockZ()));
BlockState state = mc.world.getBlockState(unsorted);
BlockData blockData = new BlockData();
BlockDataAndPosition blockData = new BlockDataAndPosition();
blockData.blockId = Block.getRawIdFromState(state);
blockData.blockPosition = new BlockPosition(sorted);
trainerMap.blocks.add(blockData);
Expand Down Expand Up @@ -196,6 +229,15 @@ public List<BlockPos> collectBlocksBetween(World world, BlockPos start, BlockPos
return blocks;
}

@EventHandler
private void onBlockUpdate(BlockUpdateEvent event) {
BlockPosition position = new BlockPosition(event.pos);
if (map_blocks.containsKey(position) && started) {
BlockData data = map_blocks.get(position);
mc.world.setBlockState(event.pos, Block.getStateFromRawId(data.blockId));
}
}

@EventHandler
private void onSendPacket(PacketEvent.Send event) {
if (event.packet instanceof PlayerMoveC2SPacket playerMoveC2SPacket) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package nekiplay.protrainer.features.modules;

import meteordevelopment.meteorclient.settings.IntSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Categories;
import meteordevelopment.meteorclient.systems.modules.Module;

Expand All @@ -8,5 +11,17 @@ public ProTrainerModule() {
super(Categories.World, "pro-trainer", "Settings for trainer command");
}

private final SettingGroup defaultGroup = settings.getDefaultGroup();

public final Setting<Integer> loadingSpeed = defaultGroup.add(new IntSetting.Builder()
.name("loading-speed")
.description("World loading speed in blocks.")
.defaultValue(8)
.min(1)
.max(64)
.sliderMin(1)
.sliderMax(64)
.build()
);

}
Loading