panorama and small fixes
@@ -0,0 +1,83 @@
|
||||
package dev.tggamesyt.szar.client;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import dev.tggamesyt.szar.Szar;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
|
||||
|
||||
public class PanoramaClientCommand {
|
||||
|
||||
static void register(CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(literal("takepanorama")
|
||||
.executes(PanoramaClientCommand::execute));
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<FabricClientCommandSource> context) {
|
||||
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
if (client.world == null) {
|
||||
context.getSource().sendError(Text.literal("Not in world."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
client.execute(() -> {
|
||||
try {
|
||||
createPanorama(client, context);
|
||||
} catch (Exception e) {
|
||||
context.getSource().sendError(Text.literal("Failed: " + e.getMessage()));
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static void createPanorama(MinecraftClient client,
|
||||
CommandContext<FabricClientCommandSource> context) throws Exception {
|
||||
|
||||
String timestamp = LocalDateTime.now()
|
||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss"));
|
||||
|
||||
File screenshotDir = new File(client.runDirectory, "screenshots");
|
||||
File panoramaDir = new File(screenshotDir, "panorama-" + timestamp);
|
||||
|
||||
Files.createDirectories(panoramaDir.toPath());
|
||||
|
||||
// This creates: panoramaDir/screenshots/
|
||||
Text result = client.takePanorama(panoramaDir, 1024, 1024);
|
||||
|
||||
// Move files up one folder
|
||||
File innerScreenshotDir = new File(panoramaDir, "screenshots");
|
||||
|
||||
if (innerScreenshotDir.exists()) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
File src = new File(innerScreenshotDir, "panorama_" + i + ".png");
|
||||
File dst = new File(panoramaDir, "panorama_" + i + ".png");
|
||||
|
||||
if (src.exists()) {
|
||||
Files.move(src.toPath(), dst.toPath());
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the now-empty inner screenshots folder
|
||||
innerScreenshotDir.delete();
|
||||
}
|
||||
|
||||
context.getSource().sendFeedback(result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import dev.tggamesyt.szar.Szar;
|
||||
import dev.tggamesyt.szar.PlaneAnimation;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
|
||||
@@ -36,6 +37,10 @@ import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
|
||||
import static dev.tggamesyt.szar.Szar.*;
|
||||
@@ -324,8 +329,35 @@ public class SzarClient implements ClientModInitializer {
|
||||
(stack, world, entity, seed) -> {
|
||||
return entity != null && entity.getMainHandStack() == stack ? 1.0f : 0.0f;
|
||||
});
|
||||
if (isDebugEnabled()) {
|
||||
ClientCommandRegistrationCallback.EVENT.register(
|
||||
(dispatcher, registryAccess) -> PanoramaClientCommand.register(dispatcher)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
private boolean isDebugEnabled() {
|
||||
|
||||
MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
File configDir = new File(client.runDirectory, "config");
|
||||
File debugFile = new File(configDir, "panodebugmode.txt");
|
||||
|
||||
if (!debugFile.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
String content = Files.readString(debugFile.toPath(), StandardCharsets.UTF_8)
|
||||
.trim();
|
||||
|
||||
return content.equals("true");
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static void scrambleMovement(MinecraftClient client, float chance) {
|
||||
var options = client.options;
|
||||
long window = client.getWindow().getHandle();
|
||||
|
||||
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 879 KiB |
|
After Width: | Height: | Size: 946 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"szar:niggerite_block"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"szar:uranium_ore"
|
||||
"szar:uranium_ore",
|
||||
"szar:niggerite_block"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"type": "minecraft:block",
|
||||
"pools": [
|
||||
{
|
||||
"rolls": 1,
|
||||
"entries": [
|
||||
{
|
||||
"type": "minecraft:item",
|
||||
"name": "szar:niggerite_block"
|
||||
}
|
||||
],
|
||||
"conditions": [
|
||||
{
|
||||
"condition": "minecraft:survives_explosion"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||