Skip to content

Commit

Permalink
1182
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Dec 14, 2023
1 parent 37fd06c commit 61d9c7f
Show file tree
Hide file tree
Showing 35 changed files with 143 additions and 1,453 deletions.
20 changes: 0 additions & 20 deletions src/main/java/com/github/zly2006/reden/RedenClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.github.zly2006.reden.malilib.KeyCallbacksKt;
import com.github.zly2006.reden.malilib.MalilibSettingsKt;
import com.github.zly2006.reden.malilib.data.CommandHotkey;
import com.github.zly2006.reden.report.ReportKt;
import com.github.zly2006.reden.utils.DebugKt;
import com.google.gson.JsonObject;
Expand All @@ -18,7 +17,6 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -57,24 +55,6 @@ public void addKeysToMap(IKeybindManager iKeybindManager) {
MalilibSettingsKt.HOTKEYS.stream()
.map(IHotkey::getKeybind)
.forEach(iKeybindManager::addKeybindToMap);

for (CommandHotkey commandHotkey : MalilibSettingsKt.RUN_COMMAND.getCommandHotkeyList()) {
iKeybindManager.addKeybindToMap(commandHotkey.getKeybind());
commandHotkey.getKeybind().setCallback((action, key) -> {
ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();
if (networkHandler != null) {
for (String command : commandHotkey.getCommands()) {
if (command.startsWith("/")) {
networkHandler.sendChatCommand(command.substring(1));
} else {
networkHandler.sendChatMessage(command);
}
}
return true;
}
return false;
});
}
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/github/zly2006/reden/Sounds.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.github.zly2006.reden;

import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.registry.Registry;

public class Sounds {
public final static SoundEvent THE_WORLD = SoundEvent.of(Reden.identifier("the_world"));
public final static SoundEvent MIKU_MIKU = SoundEvent.of(Reden.identifier("miku_miku"));
public final static SoundEvent THE_WORLD = new SoundEvent(Reden.identifier("the_world"));
public final static SoundEvent MIKU_MIKU = new SoundEvent(Reden.identifier("miku_miku"));
public static void init() {
Registry.register(Registries.SOUND_EVENT, THE_WORLD.getId(), THE_WORLD);
Registry.register(Registries.SOUND_EVENT, MIKU_MIKU.getId(), MIKU_MIKU);
Registry.register(Registry.SOUND_EVENT, THE_WORLD.getId(), THE_WORLD);
Registry.register(Registry.SOUND_EVENT, MIKU_MIKU.getId(), MIKU_MIKU);
}
}
25 changes: 13 additions & 12 deletions src/main/java/com/github/zly2006/reden/access/PlayerData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import net.minecraft.entity.player.PlayerEntity
import net.minecraft.nbt.NbtCompound
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.text.Text
import net.minecraft.text.TranslatableText
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World
import java.util.*
Expand All @@ -26,13 +27,13 @@ class PlayerData(
fun topRedo() {
player.sendMessage(Text.of(redo.lastOrNull {
it.data.isNotEmpty() && it.entities.isNotEmpty()
}?.toString()))
}?.toString()), false)
}

fun topUndo() {
player.sendMessage(Text.of(undo.lastOrNull {
it.data.isNotEmpty() && it.entities.isNotEmpty()
}?.toString()))
}?.toString()), false)
}

val canRecord: Boolean
Expand All @@ -51,7 +52,7 @@ class PlayerData(
val blockEntity: NbtCompound?,
val time: Int
) {
fun getMemorySize() = (blockEntity?.sizeInBytes ?: 0) + 20
fun getMemorySize() = 20 //todo: blockEntity
}

internal interface PlayerDataAccess {
Expand Down Expand Up @@ -108,7 +109,7 @@ ${data.map { "${BlockPos.fromLong(it.key).toShortString()} = ${it.value.state}"

open fun getMemorySize() = data.asSequence().map { it.value.getMemorySize() }.sum() +
data.size * 16 +
entities.map { 16 + it.value.nbt.sizeInBytes }.sum()
entities.map { 16 + it.value.nbt.size }.sum()
}

class UndoRecord(
Expand All @@ -121,14 +122,14 @@ ${data.map { "${BlockPos.fromLong(it.key).toShortString()} = ${it.value.state}"
var notified = false

enum class Cause(val message: Text) {
BREAK_BLOCK(Text.translatable("reden.feature.undo.cause.break_block")),
USE_BLOCK(Text.translatable("reden.feature.undo.cause.use_block")),
USE_ITEM(Text.translatable("reden.feature.undo.cause.use_item")),
USE_ENTITY(Text.translatable("reden.feature.undo.cause.use_entity")),
ATTACK_ENTITY(Text.translatable("reden.feature.undo.cause.attack_entity")),
COMMAND(Text.translatable("reden.feature.undo.cause.command")),
LITEMATICA_TASK(Text.translatable("reden.feature.undo.cause.litematica_task")),
UNKNOWN(Text.translatable("reden.feature.undo.cause.unknown"))
BREAK_BLOCK(TranslatableText("reden.feature.undo.cause.break_block")),
USE_BLOCK(TranslatableText("reden.feature.undo.cause.use_block")),
USE_ITEM(TranslatableText("reden.feature.undo.cause.use_item")),
USE_ENTITY(TranslatableText("reden.feature.undo.cause.use_entity")),
ATTACK_ENTITY(TranslatableText("reden.feature.undo.cause.attack_entity")),
COMMAND(TranslatableText("reden.feature.undo.cause.command")),
LITEMATICA_TASK(TranslatableText("reden.feature.undo.cause.litematica_task")),
UNKNOWN(TranslatableText("reden.feature.undo.cause.unknown"))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
package com.github.zly2006.reden.carpet;

import carpet.api.settings.CarpetRule;
import carpet.api.settings.Rule;
import carpet.api.settings.RuleCategory;
import carpet.api.settings.Validator;
import carpet.settings.ParsedRule;
import carpet.settings.Rule;
import carpet.settings.RuleCategory;
import carpet.settings.Validator;
import com.github.zly2006.reden.utils.DebugKt;
import com.github.zly2006.reden.utils.UtilsKt;
import net.minecraft.server.command.ServerCommandSource;
import org.jetbrains.annotations.Nullable;

public class RedenCarpetSettings {
private static final String CATEGORY_REDEN = "Reden-Undo";

public static class Options {
@Rule(
categories = {CATEGORY_REDEN, RuleCategory.CREATIVE},
category = {CATEGORY_REDEN, RuleCategory.CREATIVE},
options = {"-1", "0", "52428800"}, // 50 MB
strict = false
strict = false,
desc = "Memory size a player can use for undo. Default is 5MB, 0 to disable, -1 for infinite. (This setting was broken n 1.18)"
)
public static int allowedUndoSizeInBytes = 52428800;

@Rule(
categories = {CATEGORY_REDEN, RuleCategory.CREATIVE}
category = {CATEGORY_REDEN, RuleCategory.CREATIVE},
desc = "undoScheduledTicks"
)
public static boolean undoScheduledTicks = true;

@Rule(
categories = {CATEGORY_REDEN, RuleCategory.CREATIVE}
category = {CATEGORY_REDEN, RuleCategory.CREATIVE},
desc = "undoEntities"
)
public static boolean undoEntities = true;

@Rule(
categories = {CATEGORY_REDEN, RuleCategory.CREATIVE}
category = {CATEGORY_REDEN, RuleCategory.CREATIVE},
desc = "undoApplyingClearScheduledTicks"
)
public static boolean undoApplyingClearScheduledTicks = true;

private static class DebugOptionObserver extends Validator<Boolean> {
@Override
public Boolean validate(@Nullable ServerCommandSource source, CarpetRule<Boolean> changingRule, Boolean newValue, String userInput) {
public Boolean validate(ServerCommandSource serverCommandSource, ParsedRule<Boolean> parsedRule, Boolean newValue, String s) {
if (!UtilsKt.isClient()) {
if (newValue) {
DebugKt.startDebugAppender();
Expand All @@ -50,8 +53,9 @@ public Boolean validate(@Nullable ServerCommandSource source, CarpetRule<Boolean
}

@Rule(
categories = {CATEGORY_REDEN},
validators = {DebugOptionObserver.class}
category = {CATEGORY_REDEN},
validate = {DebugOptionObserver.class},
desc = "debug loggers"
)
public static boolean redenDebug = false;
}
Expand Down
189 changes: 0 additions & 189 deletions src/main/java/com/github/zly2006/reden/gui/CreditScreen.kt

This file was deleted.

Loading

0 comments on commit 61d9c7f

Please sign in to comment.