mirror of
https://codeberg.org/moonleay/Gimble.git
synced 2024-11-24 15:52:11 +00:00
feat: added ForcePlace & No Updates, Modifier disabled messages moved to Toast
This commit is contained in:
parent
ff77e2b576
commit
8930d64fd0
11 changed files with 74 additions and 66 deletions
19
README.md
19
README.md
|
@ -2,23 +2,24 @@
|
||||||
This project aims to improve the experience of creating structures in Minecraft.
|
This project aims to improve the experience of creating structures in Minecraft.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
- **Modes** Use different modes to edit structures. Think Vim for Minecraft.
|
- **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.
|
- **Modifier** Use modifiers to change the behavior of the modes and your building experience. [x]
|
||||||
- **Undo/Redo** Easily undo and redo your changes. (planned)
|
- **Undo/Redo** Easily undo and redo your changes. (planned)
|
||||||
|
|
||||||
## Modes
|
## Modes
|
||||||
- **Normal** The default mode. Use it to change to other modes
|
- **Normal** The default mode. Use it to change to other modes [x]
|
||||||
- **Insert** Edit blocks in the world
|
- **Insert** Edit blocks in the world [x]
|
||||||
- **Visual** Use selection to edit (contains worldedit support) (planned)
|
- **Visual** Use selection to edit (contains worldedit support) (planned)
|
||||||
- **Replace** Replace blocks in the world
|
- **Replace** Replace blocks in the world [x]
|
||||||
|
|
||||||
## Modifiers
|
## Modifiers
|
||||||
- **Bulldozer** Basically an auto-clicker
|
- **Bulldozer** Basically an auto-clicker
|
||||||
- **Force Place** Ignore block placing restrictions
|
- **Force Place** Ignore block placing restrictions [x]
|
||||||
- **No Clip** Walk and fly through blocks
|
- **No Clip** Walk and fly through blocks [x]
|
||||||
- **No Updates** Prevent block updates
|
- **No Updates** Prevent block updates [x]
|
||||||
- **No Gravity** Prevent blocks from falling (planned)
|
- **No Gravity** Prevent blocks from falling (planned)
|
||||||
- **Better Fly** Disable floaty fly physics and set custom fly speeds(planned)
|
- **Better Fly** Disable floaty fly physics and set custom fly speeds (planned)
|
||||||
|
- **Angelic Placement** Place blocks in the air (planned)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
This mod requires Fabric, the Fabric API, aswell as the HCConfigLib.
|
This mod requires Fabric, the Fabric API, aswell as the HCConfigLib.
|
||||||
|
|
|
@ -72,8 +72,7 @@ object ClientEditor {
|
||||||
this.updateServerState()
|
this.updateServerState()
|
||||||
|
|
||||||
if(TEMP_DISABLED_MODIFIERS.isNotEmpty()) {
|
if(TEMP_DISABLED_MODIFIERS.isNotEmpty()) {
|
||||||
ChatUtil.addToChatHistory("The following modifiers are not supported by this editor mode and are therefore currently disabled: " +
|
ChatUtil.showToastToSelf("${CURRENT_MODE.displayName} Mode disabled", getListAsString(TEMP_DISABLED_MODIFIERS), MinecraftClient.getInstance())
|
||||||
getListAsString(TEMP_DISABLED_MODIFIERS), MinecraftClient.getInstance())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,9 +82,9 @@ object ClientEditor {
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
for (mod in list) {
|
for (mod in list) {
|
||||||
sb.append(mod.displayName)
|
sb.append(mod.displayName)
|
||||||
sb.append(" ")
|
sb.append(", ")
|
||||||
}
|
}
|
||||||
return sb.toString().dropLast(1)
|
return sb.toString().dropLast(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCurrentMode(): Mode {
|
fun getCurrentMode(): Mode {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package net.moonleay.gimble.client.util
|
package net.moonleay.gimble.client.util
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient
|
import net.minecraft.client.MinecraftClient
|
||||||
|
import net.minecraft.client.toast.SystemToast
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
|
|
||||||
object ChatUtil {
|
object ChatUtil {
|
||||||
|
@ -17,4 +18,9 @@ object ChatUtil {
|
||||||
fun addToChatHistory(message: String, client: MinecraftClient) {
|
fun addToChatHistory(message: String, client: MinecraftClient) {
|
||||||
client.inGameHud.chatHud.addMessage(Text.of(message))
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.UUID
|
||||||
object ServerEditorManager {
|
object ServerEditorManager {
|
||||||
private val LOGGER = LogManager.getLogger(BuildConstants.modName)
|
private val LOGGER = LogManager.getLogger(BuildConstants.modName)
|
||||||
|
|
||||||
val STATEMAP = mutableMapOf<UUID, EditorState>()
|
private val STATEMAP = mutableMapOf<UUID, EditorState>()
|
||||||
|
|
||||||
fun updateEditorState(playerUUID: UUID, editorState: EditorState) {
|
fun updateEditorState(playerUUID: UUID, editorState: EditorState) {
|
||||||
STATEMAP[playerUUID] = editorState
|
STATEMAP[playerUUID] = editorState
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package net.moonleay.gimble.editor.state.mode
|
package net.moonleay.gimble.editor.state.mode
|
||||||
|
|
||||||
enum class Mode(val displayName: String, val color: Int, val incompatibleModifiers: List<ModeModifier>){
|
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
|
NORMAL("NORMAL", 0x90a959, listOf(ModeModifier.NO_UPDATES, ModeModifier.BULLDOZER, ModeModifier.FORCE_PLACE)), // Do nothing
|
||||||
INSERT("INSERT", 0xf4bf75, listOf()), // Place and break blocks
|
INSERT("INSERT", 0xf4bf75, listOf()), // Place and break blocks
|
||||||
REPLACE("REPLACE", 0xac4242, listOf()), // Replace blocks
|
REPLACE("REPLACE", 0xac4242, listOf()), // Replace blocks
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,22 +1,30 @@
|
||||||
package net.moonleay.gimble.mixin;
|
package net.moonleay.gimble.mixin;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.server.network.ServerPlayerInteractionManager;
|
import net.minecraft.item.BlockItem;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.item.ItemPlacementContext;
|
||||||
import net.minecraft.util.Hand;
|
import net.moonleay.gimble.editor.ServerEditorManager;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.moonleay.gimble.editor.state.mode.ModeModifier;
|
||||||
import net.minecraft.world.World;
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(ServerPlayerInteractionManager.class)
|
@Mixin(BlockItem.class)
|
||||||
public class ForcePlaceMixin {
|
public class ForcePlaceMixin {
|
||||||
|
|
||||||
@Inject(method = "interactBlock", at = @At("HEAD"))
|
@Inject(method = "canPlace", at = @At("HEAD"), cancellable = true)
|
||||||
private void func(ServerPlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable<ActionResult> cir) {
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
src/main/java/net/moonleay/gimble/mixin/NoBlockUpdates.java
Normal file
32
src/main/java/net/moonleay/gimble/mixin/NoBlockUpdates.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -22,6 +22,6 @@ object GimbleServer {
|
||||||
private fun handleStateUpdate(player: ServerPlayerEntity, buf: PacketByteBuf){
|
private fun handleStateUpdate(player: ServerPlayerEntity, buf: PacketByteBuf){
|
||||||
val state = Cbor.decodeFromByteArray<EditorState>(buf.readByteArray())
|
val state = Cbor.decodeFromByteArray<EditorState>(buf.readByteArray())
|
||||||
ServerEditorManager.updateEditorState(player.uuid, state)
|
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}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
"package": "net.moonleay.gimble.mixin",
|
"package": "net.moonleay.gimble.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"AlwaysAllowBlock",
|
|
||||||
"ForcePlaceMixin",
|
"ForcePlaceMixin",
|
||||||
"NoClipMixin",
|
"NoBlockUpdates",
|
||||||
"WorldSetBlockStateMixin"
|
"NoClipMixin"
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"HudMixin",
|
"HudMixin",
|
||||||
|
|
Loading…
Reference in a new issue