feat: added ForcePlace & No Updates, Modifier disabled messages moved to Toast

This commit is contained in:
moonleay 2024-04-27 03:34:45 +02:00
parent ff77e2b576
commit 8930d64fd0
Signed by: moonleay
GPG key ID: 82667543CCD715FB
11 changed files with 74 additions and 66 deletions

View file

@ -2,23 +2,24 @@
This project aims to improve the experience of creating structures in Minecraft.
## Features
- **Modes** Use different modes to edit structures. Think Vim for Minecraft.
- **Modifier** Use modifiers to change the behavior of the modes and your building experience.
- **Modes** Use different modes to edit structures. Think Vim for Minecraft. [x]
- **Modifier** Use modifiers to change the behavior of the modes and your building experience. [x]
- **Undo/Redo** Easily undo and redo your changes. (planned)
## Modes
- **Normal** The default mode. Use it to change to other modes
- **Insert** Edit blocks in the world
- **Normal** The default mode. Use it to change to other modes [x]
- **Insert** Edit blocks in the world [x]
- **Visual** Use selection to edit (contains worldedit support) (planned)
- **Replace** Replace blocks in the world
- **Replace** Replace blocks in the world [x]
## Modifiers
- **Bulldozer** Basically an auto-clicker
- **Force Place** Ignore block placing restrictions
- **No Clip** Walk and fly through blocks
- **No Updates** Prevent block updates
- **Force Place** Ignore block placing restrictions [x]
- **No Clip** Walk and fly through blocks [x]
- **No Updates** Prevent block updates [x]
- **No Gravity** Prevent blocks from falling (planned)
- **Better Fly** Disable floaty fly physics and set custom fly speeds (planned)
- **Angelic Placement** Place blocks in the air (planned)
## Installation
This mod requires Fabric, the Fabric API, aswell as the HCConfigLib.

View file

@ -72,8 +72,7 @@ object ClientEditor {
this.updateServerState()
if(TEMP_DISABLED_MODIFIERS.isNotEmpty()) {
ChatUtil.addToChatHistory("The following modifiers are not supported by this editor mode and are therefore currently disabled: " +
getListAsString(TEMP_DISABLED_MODIFIERS), MinecraftClient.getInstance())
ChatUtil.showToastToSelf("${CURRENT_MODE.displayName} Mode disabled", getListAsString(TEMP_DISABLED_MODIFIERS), MinecraftClient.getInstance())
}
}
@ -83,9 +82,9 @@ object ClientEditor {
val sb = StringBuilder()
for (mod in list) {
sb.append(mod.displayName)
sb.append(" ")
sb.append(", ")
}
return sb.toString().dropLast(1)
return sb.toString().dropLast(2)
}
fun getCurrentMode(): Mode {

View file

@ -1,6 +1,7 @@
package net.moonleay.gimble.client.util
import net.minecraft.client.MinecraftClient
import net.minecraft.client.toast.SystemToast
import net.minecraft.text.Text
object ChatUtil {
@ -17,4 +18,9 @@ object ChatUtil {
fun addToChatHistory(message: String, client: MinecraftClient) {
client.inGameHud.chatHud.addMessage(Text.of(message))
}
fun showToastToSelf(title: String, description: String, client: MinecraftClient) {
val toast = SystemToast(SystemToast.Type.PERIODIC_NOTIFICATION, Text.of(title), Text.of(description))
client.toastManager.add(toast)
}
}

View file

@ -9,7 +9,7 @@ import java.util.UUID
object ServerEditorManager {
private val LOGGER = LogManager.getLogger(BuildConstants.modName)
val STATEMAP = mutableMapOf<UUID, EditorState>()
private val STATEMAP = mutableMapOf<UUID, EditorState>()
fun updateEditorState(playerUUID: UUID, editorState: EditorState) {
STATEMAP[playerUUID] = editorState

View file

@ -1,7 +1,7 @@
package net.moonleay.gimble.editor.state.mode
enum class Mode(val displayName: String, val color: Int, val incompatibleModifiers: List<ModeModifier>){
UNKNOWN("UNKNOWN", 0x000000, listOf()), // Unknown mode. This mode cannot be entered
// UNKNOWN("UNKNOWN", 0x000000, listOf()), // Unknown mode. This mode cannot be entered
NORMAL("NORMAL", 0x90a959, listOf(ModeModifier.NO_UPDATES, ModeModifier.BULLDOZER, ModeModifier.FORCE_PLACE)), // Do nothing
INSERT("INSERT", 0xf4bf75, listOf()), // Place and break blocks
REPLACE("REPLACE", 0xac4242, listOf()), // Replace blocks

View file

@ -1,19 +0,0 @@
package net.moonleay.gimble.mixin;
import net.minecraft.block.Block;
import net.minecraft.block.pattern.CachedBlockPosition;
import net.minecraft.item.ItemStack;
import net.minecraft.util.registry.Registry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(ItemStack.class)
public class AlwaysAllowBlock {
@Redirect(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;canPlaceOn(Lnet/minecraft/util/registry/Registry;Lnet/minecraft/block/pattern/CachedBlockPosition;)Z"))
private boolean func(ItemStack instance, Registry<Block> blockRegistry, CachedBlockPosition pos) {
return true;
}
}

View file

@ -1,22 +1,30 @@
package net.moonleay.gimble.mixin;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.network.ServerPlayerInteractionManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemPlacementContext;
import net.moonleay.gimble.editor.ServerEditorManager;
import net.moonleay.gimble.editor.state.mode.ModeModifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerPlayerInteractionManager.class)
@Mixin(BlockItem.class)
public class ForcePlaceMixin {
@Inject(method = "interactBlock", at = @At("HEAD"))
private void func(ServerPlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
@Inject(method = "canPlace", at = @At("HEAD"), cancellable = true)
private void func(ItemPlacementContext context, BlockState state, CallbackInfoReturnable<Boolean> cir) {
if (context.getPlayer() == null) {
return;
}
PlayerEntity player = context.getPlayer();
if (!ServerEditorManager.INSTANCE.playerHasModifier(player.getGameProfile().getId(), ModeModifier.FORCE_PLACE)) {
return;
}
cir.setReturnValue(true);
cir.cancel();
}
}

View file

@ -0,0 +1,32 @@
package net.moonleay.gimble.mixin;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemPlacementContext;
import net.moonleay.gimble.editor.ServerEditorManager;
import net.moonleay.gimble.editor.state.mode.ModeModifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(BlockItem.class)
public class NoBlockUpdates {
@Inject(method = "place(Lnet/minecraft/item/ItemPlacementContext;Lnet/minecraft/block/BlockState;)Z", at = @At("HEAD"), cancellable = true)
private void func(ItemPlacementContext context, BlockState state, CallbackInfoReturnable<Boolean> cir) {
if (context.getPlayer() == null) {
return;
}
PlayerEntity player = context.getPlayer();
if (!ServerEditorManager.INSTANCE.playerHasModifier(player.getGameProfile().getId(), ModeModifier.NO_UPDATES)) {
return;
}
cir.setReturnValue(context.getWorld().setBlockState(context.getBlockPos(), state, Block.REDRAW_ON_MAIN_THREAD, 0)); // This is scuffed, but works
cir.cancel();
}
}

View file

@ -1,18 +0,0 @@
package net.moonleay.gimble.mixin;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(World.class)
public class WorldSetBlockStateMixin {
@Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD"))
private void func(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable<Boolean> cir) {
System.out.println("setBlockState was run");
}
}

View file

@ -22,6 +22,6 @@ object GimbleServer {
private fun handleStateUpdate(player: ServerPlayerEntity, buf: PacketByteBuf){
val state = Cbor.decodeFromByteArray<EditorState>(buf.readByteArray())
ServerEditorManager.updateEditorState(player.uuid, state)
player.sendMessage(Text.of("Mode: ${state.editorMode} with ${state.editorModifier}"))
// player.sendMessage(Text.of("Mode: ${state.editorMode} with ${state.editorModifier}"))
}
}

View file

@ -4,10 +4,9 @@
"package": "net.moonleay.gimble.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"AlwaysAllowBlock",
"ForcePlaceMixin",
"NoClipMixin",
"WorldSetBlockStateMixin"
"NoBlockUpdates",
"NoClipMixin"
],
"client": [
"HudMixin",