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

@ -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");
}
}