From 3adfb1b29b1d508bb3ff32cb0200676adb4f68fb Mon Sep 17 00:00:00 2001 From: JoakimThorsen Date: Tue, 2 Jan 2024 14:03:18 +0100 Subject: [PATCH] Made blocktickling per-player. Added the /blocktickling command, which lets you configure blockUpdates, shapeUpdates, and overrideRightclick toggles individually. Added two miscellaneous enderman griefing and elytra rocketing toggles for survival. Bump version to 2.1.0 --- gradle.properties | 2 +- .../com/joacarpet/BlockTicklingSetting.java | 83 +++++++++++++++ .../com/joacarpet/HelloWorldTemplate.java | 55 ---------- src/main/java/com/joacarpet/JoaCarpetMod.java | 4 +- .../java/com/joacarpet/JoaCarpetSettings.java | 43 +++++--- .../commands/BlockTicklingCommand.java | 100 ++++++++++++++++++ .../joacarpet/mixin/MinecraftServerMixin.java | 53 ---------- .../mixin/blockTickling/ItemMixin.java | 29 +++-- .../mixin/blockTickling/PlayerMixin.java | 8 +- .../DefaultDispenseItemBehaviorMixin.java | 16 ++- .../insaneBehaviors/PistonBaseBlockMixin.java | 16 +-- .../insaneBehaviors/ProjectileMixin.java | 10 +- .../DisableElytraRocketsMixin.java | 42 ++++++++ .../DisableEndermanGriefingMixin.java | 49 +++++++++ .../assets/joacarpet/lang/en_us.json | 4 +- src/main/resources/joacarpet.mixins.json | 7 +- versions/1.17.1/gradle.properties | 2 +- versions/1.18.2/gradle.properties | 2 +- versions/1.19.4/gradle.properties | 4 +- versions/1.20.2/gradle.properties | 2 +- 20 files changed, 370 insertions(+), 161 deletions(-) create mode 100644 src/main/java/com/joacarpet/BlockTicklingSetting.java delete mode 100644 src/main/java/com/joacarpet/HelloWorldTemplate.java create mode 100644 src/main/java/com/joacarpet/commands/BlockTicklingCommand.java delete mode 100644 src/main/java/com/joacarpet/mixin/MinecraftServerMixin.java create mode 100644 src/main/java/com/joacarpet/mixin/miscSurvival/DisableElytraRocketsMixin.java create mode 100644 src/main/java/com/joacarpet/mixin/miscSurvival/DisableEndermanGriefingMixin.java diff --git a/gradle.properties b/gradle.properties index 8809119..8b17b1b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ # Mod Properties mod_id=joacarpet mod_name=JoaCarpet - mod_version=2.0.0 + mod_version=2.1.0 maven_group=me.fallenbreath archives_base_name=joacarpet diff --git a/src/main/java/com/joacarpet/BlockTicklingSetting.java b/src/main/java/com/joacarpet/BlockTicklingSetting.java new file mode 100644 index 0000000..4f5a9c5 --- /dev/null +++ b/src/main/java/com/joacarpet/BlockTicklingSetting.java @@ -0,0 +1,83 @@ +/* + * This file is part of the JoaCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Joa and contributors + * + * JoaCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * JoaCarpet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JoaCarpet. If not, see . + */ + +package com.joacarpet; + +import net.minecraft.world.item.context.UseOnContext; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public enum BlockTicklingSetting { + + BLOCKUPDATES ("blockUpdates", "Block Updates", false), + SHAPEUPDATES ("shapeUpdates", "Shape Updates", false), + OVERRIDERIGHTCLICK ("overrideRightclick", "Override Rightclick", false); + + private static final Map> playerSettingMap = new HashMap<>(); + private static final Map fromCommandKey = new HashMap<>(); + + private final String commandKey; + private final String name; + private final Boolean defaultSetting; + BlockTicklingSetting(String commandKey, String name, Boolean defaultSetting) { + this.commandKey = commandKey; + this.name = name; + this.defaultSetting = defaultSetting; + } + + static + { + for(BlockTicklingSetting i : values()) + { + fromCommandKey.put(i.commandKey, i); + } + } + public static BlockTicklingSetting fromCommandKey(String key) { + return fromCommandKey.get(key); + } + + public static Iterable commandKeys() { + return fromCommandKey.keySet(); + } + + public static Boolean get(BlockTicklingSetting setting, UUID uuid) { + return playerSettingMap + .getOrDefault(uuid, new HashMap<>()) + .getOrDefault(setting, setting.defaultSetting); + } + + public static Boolean get(BlockTicklingSetting setting, UseOnContext useOnContext) { + var player = useOnContext.getPlayer(); + if (player == null) + return setting.defaultSetting; + return get(setting, player.getUUID()); + } + + public static void set(BlockTicklingSetting setting, UUID uuid, Boolean bool) { + playerSettingMap.computeIfAbsent(uuid, k -> new HashMap<>()).put(setting, bool); + } + + public String getName() + { + return name; + } +} \ No newline at end of file diff --git a/src/main/java/com/joacarpet/HelloWorldTemplate.java b/src/main/java/com/joacarpet/HelloWorldTemplate.java deleted file mode 100644 index c1f77af..0000000 --- a/src/main/java/com/joacarpet/HelloWorldTemplate.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of the TemplateMod project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 Joa and contributors - * - * TemplateMod is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * TemplateMod is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with TemplateMod. If not, see . - */ - -package com.joacarpet; - -import net.fabricmc.api.ModInitializer; -import net.fabricmc.loader.api.FabricLoader; -import net.fabricmc.loader.api.metadata.ModMetadata; - -//#if MC >= 11800 -import com.mojang.logging.LogUtils; -import org.slf4j.Logger; -//#else -//$$ import org.apache.logging.log4j.LogManager; -//$$ import org.apache.logging.log4j.Logger; -//#endif - -public class HelloWorldTemplate implements ModInitializer -{ - public static final Logger LOGGER = - //#if MC >= 11800 - LogUtils.getLogger(); - //#else - //$$ LogManager.getLogger(); - //#endif - - public static final String MOD_ID = "com/joacarpet"; - public static String MOD_VERSION = "2.0.0"; - public static String MOD_NAME = "JoaCarpet"; - - @Override - public void onInitialize() - { - ModMetadata metadata = FabricLoader.getInstance().getModContainer(MOD_ID).orElseThrow(RuntimeException::new).getMetadata(); - MOD_NAME = metadata.getName(); - MOD_VERSION = metadata.getVersion().getFriendlyString(); - } -} diff --git a/src/main/java/com/joacarpet/JoaCarpetMod.java b/src/main/java/com/joacarpet/JoaCarpetMod.java index d3b6d6f..4de6e3a 100644 --- a/src/main/java/com/joacarpet/JoaCarpetMod.java +++ b/src/main/java/com/joacarpet/JoaCarpetMod.java @@ -24,6 +24,7 @@ import carpet.CarpetServer; import carpet.utils.Messenger; import carpet.utils.Translations; +import com.joacarpet.commands.BlockTicklingCommand; import com.joacarpet.commands.InsaneBehaviorsCommand; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.api.ModInitializer; @@ -49,7 +50,7 @@ public class JoaCarpetMod implements ModInitializer, CarpetExtension { public static final Logger LOGGER = //#if MC >= 11800 - LoggerFactory.getLogger("joacarpet"); + LoggerFactory.getLogger("joacarpet"); //#else //$$ LogManager.getLogger("joacarpet"); //#endif @@ -69,6 +70,7 @@ public void registerCommands(CommandDispatcher dispatcher //#endif ) { InsaneBehaviorsCommand.register(dispatcher); + BlockTicklingCommand.register(dispatcher); } @Override diff --git a/src/main/java/com/joacarpet/JoaCarpetSettings.java b/src/main/java/com/joacarpet/JoaCarpetSettings.java index 8f2ef3c..3db6376 100644 --- a/src/main/java/com/joacarpet/JoaCarpetSettings.java +++ b/src/main/java/com/joacarpet/JoaCarpetSettings.java @@ -22,19 +22,12 @@ //#if MC >= 11900 import carpet.api.settings.Rule; +import static carpet.api.settings.RuleCategory.*; //#else //$$ import carpet.settings.Rule; +//$$ import static carpet.settings.RuleCategory.*; //#endif -//#if MC >= 11900 -import static carpet.api.settings.RuleCategory.COMMAND; -import static carpet.api.settings.RuleCategory.CREATIVE; -//#else -//$$ import static carpet.settings.RuleCategory.COMMAND; -//$$ import static carpet.settings.RuleCategory.CREATIVE; -//#endif - - public class JoaCarpetSettings { public static final String JOA = "JoaCarpet"; @@ -62,12 +55,34 @@ public class JoaCarpetSettings { @Rule( //#if MC >= 11900 - categories = {CREATIVE, JOA}, + categories = {COMMAND, CREATIVE, JOA}, //#else -//$$ category = {CREATIVE, JOA}, -//$$ desc="Lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with update interations off or with budded blocks.", +//$$ category = {COMMAND, CREATIVE, JOA}, +//$$ desc="Controls who can use the `/blocktickling` command, which lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with budded blocks, with /carpet interactionUpdates off, or with intricarpet's /interaction command.", + //#endif + options = {"true", "ops", "false", "0", "1", "2", "3", "4"} + ) + public static String commandBlockTickling = "ops"; + + @Rule( + //#if MC >= 11900 + categories = {SURVIVAL, JOA}, + //#else +//$$ category = {SURVIVAL, JOA}, +//$$ desc="Disables enderman griefing.", + //#endif + options = {"true", "false"} + ) + public static String disableEndermanGriefing = "false"; + + @Rule( + //#if MC >= 11900 + categories = {SURVIVAL, JOA}, + //#else +//$$ category = {SURVIVAL, JOA}, +//$$ desc="Disables using rockets with elytra.", //#endif - options = {"off", "blockupdates", "shapeupdates", "both"} + options = {"true", "false"} ) - public static String blockTickling = "off"; + public static String disableElytraRockets = "false"; } diff --git a/src/main/java/com/joacarpet/commands/BlockTicklingCommand.java b/src/main/java/com/joacarpet/commands/BlockTicklingCommand.java new file mode 100644 index 0000000..8a8938a --- /dev/null +++ b/src/main/java/com/joacarpet/commands/BlockTicklingCommand.java @@ -0,0 +1,100 @@ +/* + * This file is part of the JoaCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Joa and contributors + * + * JoaCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * JoaCarpet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JoaCarpet. If not, see . + */ + +package com.joacarpet.commands; + +import com.joacarpet.BlockTicklingSetting; +import com.joacarpet.JoaCarpetSettings; +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import carpet.utils.Messenger; +import carpet.settings.SettingsManager; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerPlayer; + +import static com.mojang.brigadier.arguments.StringArgumentType.getString; +import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; +import static net.minecraft.commands.Commands.argument; +import static net.minecraft.commands.Commands.literal; +import static net.minecraft.commands.SharedSuggestionProvider.suggest; + +public class BlockTicklingCommand { + public static void register(CommandDispatcher dispatcher) + { + dispatcher.register(literal("blocktickling") + .requires((player) -> SettingsManager.canUseCommand(player, JoaCarpetSettings.commandBlockTickling)) + .then(argument("BlockTicklingSetting", StringArgumentType.word()) + .suggests((c, b) -> suggest(BlockTicklingSetting.commandKeys(), b)) + .then(argument("value", BoolArgumentType.bool()) + .executes(BlockTicklingCommand::setBlockTicklingSetting) + ) + .executes(BlockTicklingCommand::getBlockTicklingSetting) + ) + ); + } + + private static String k(BlockTicklingSetting blockTicklingSetting) + { + return "c " + blockTicklingSetting.getName(); + } + + private static String v(boolean value) + { + return (value ? "l " : "r ") + value; + } + + private static int setBlockTicklingSetting(CommandContext c) + { + try + { + ServerPlayer player = c.getSource().getPlayerOrException(); + BlockTicklingSetting i = BlockTicklingSetting.fromCommandKey(getString(c, "BlockTicklingSetting")); + boolean value = getBool(c, "value"); + BlockTicklingSetting.set(i, player.getUUID(), value); + Messenger.m(c.getSource(), "g BlockTickling setting ", k(i), "g set to ", v(value)); + return 0; + } + catch(CommandSyntaxException e) + { + Messenger.m(c.getSource(), "r BlockTickling command must be executed by a player"); + return 1; + } + } + + private static int getBlockTicklingSetting(CommandContext c) + { + try + { + ServerPlayer player = c.getSource().getPlayerOrException(); + BlockTicklingSetting i = BlockTicklingSetting.fromCommandKey(getString(c, "BlockTicklingSetting")); + Messenger.m(c.getSource(), "g BlockTickling setting ", k(i), "g is currently set to ", v(BlockTicklingSetting.get(i, player.getUUID()))); + return 0; + } + catch(CommandSyntaxException e) + { + Messenger.m(c.getSource(), "r BlockTickling command must be executed by a player"); + return 1; + } + } +} diff --git a/src/main/java/com/joacarpet/mixin/MinecraftServerMixin.java b/src/main/java/com/joacarpet/mixin/MinecraftServerMixin.java deleted file mode 100644 index 859b193..0000000 --- a/src/main/java/com/joacarpet/mixin/MinecraftServerMixin.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * This file is part of the TemplateMod project, licensed under the - * GNU Lesser General Public License v3.0 - * - * Copyright (C) 2023 Joa and contributors - * - * TemplateMod is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * TemplateMod is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with TemplateMod. If not, see . - */ - -package com.joacarpet.mixin; - -import net.minecraft.nbt.CompoundTag; -import net.minecraft.server.MinecraftServer; -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.CallbackInfo; - -@Mixin(MinecraftServer.class) -public abstract class MinecraftServerMixin -{ - @Inject( - //#if MC >= 11600 - method = "runServer", - //#else - //$$ method = "run", - //#endif - at = @At("HEAD") - ) - private void onRun(CallbackInfo ci) - { - //#if MC >= 11500 - System.err.println("Hello world from mc11500 branch"); - //#elseif MC >= 11400 - //$$ System.err.println("Hello world from mc11400 branch"); - //#endif - - CompoundTag nbt = new CompoundTag(); - nbt.putString("key", "value"); - System.err.println("nbt: " + nbt); - } -} diff --git a/src/main/java/com/joacarpet/mixin/blockTickling/ItemMixin.java b/src/main/java/com/joacarpet/mixin/blockTickling/ItemMixin.java index 0792fb6..799c2fb 100644 --- a/src/main/java/com/joacarpet/mixin/blockTickling/ItemMixin.java +++ b/src/main/java/com/joacarpet/mixin/blockTickling/ItemMixin.java @@ -20,26 +20,37 @@ package com.joacarpet.mixin.blockTickling; -import com.joacarpet.JoaCarpetMod; -import com.joacarpet.JoaCarpetSettings; +import com.joacarpet.BlockTicklingSetting; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +//#if MC < 11900 +//$$ import net.minecraft.world.level.block.Block; +//#endif + @Mixin(Item.class) class ItemMixin { + + @Unique + private static final int mysteryFlag = 2; + @Unique + private static final int mysteryNumber = 512; + @Inject(method = "useOn", at = @At("RETURN"), cancellable = true) public void useOn(UseOnContext useOnContext, CallbackInfoReturnable cir) { - if (JoaCarpetSettings.blockTickling.equals("off") || !useOnContext.getItemInHand().is(Items.FEATHER)) { + if (!(BlockTicklingSetting.get(BlockTicklingSetting.BLOCKUPDATES, useOnContext) + || BlockTicklingSetting.get(BlockTicklingSetting.SHAPEUPDATES, useOnContext)) + || !useOnContext.getItemInHand().is(Items.FEATHER)) { return; } Level level = useOnContext.getLevel(); @@ -50,18 +61,16 @@ public void useOn(UseOnContext useOnContext, CallbackInfoReturnable= 11900 - level.neighborShapeChanged(useOnContext.getClickedFace(), neighborBlockState, clickedPos, neighborPos, 2, 512); + level.neighborShapeChanged(useOnContext.getClickedFace(), neighborBlockState, clickedPos, neighborPos, mysteryFlag, mysteryNumber); //#else //$$ BlockState clickedBlockState = level.getBlockState(clickedPos); //$$ BlockState newState = clickedBlockState.updateShape(useOnContext.getClickedFace(), neighborBlockState, level, clickedPos, neighborPos); -//$$ Block.updateOrDestroy(clickedBlockState, newState, level, clickedPos, 2, 512); +//$$ Block.updateOrDestroy(clickedBlockState, newState, level, clickedPos, mysteryFlag, mysteryNumber); //#endif } cir.setReturnValue(InteractionResult.SUCCESS); diff --git a/src/main/java/com/joacarpet/mixin/blockTickling/PlayerMixin.java b/src/main/java/com/joacarpet/mixin/blockTickling/PlayerMixin.java index c4dbbd8..6df4060 100644 --- a/src/main/java/com/joacarpet/mixin/blockTickling/PlayerMixin.java +++ b/src/main/java/com/joacarpet/mixin/blockTickling/PlayerMixin.java @@ -20,6 +20,8 @@ package com.joacarpet.mixin.blockTickling; +import com.joacarpet.BlockTicklingSetting; +import com.joacarpet.JoaCarpetMod; import com.joacarpet.JoaCarpetSettings; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -40,7 +42,11 @@ protected PlayerMixin(EntityType entityType, Level level @Inject(method="isSecondaryUseActive", at = @At("HEAD"), cancellable = true) public void isSecondaryUseActive(CallbackInfoReturnable cir) { - if (JoaCarpetSettings.blockTickling.equals("off") && this.getMainHandItem().is(Items.FEATHER)) { + if (this.getMainHandItem().is(Items.FEATHER) + && BlockTicklingSetting.get(BlockTicklingSetting.OVERRIDERIGHTCLICK, this.getUUID()) + && (BlockTicklingSetting.get(BlockTicklingSetting.BLOCKUPDATES, this.getUUID()) + || BlockTicklingSetting.get(BlockTicklingSetting.SHAPEUPDATES, this.getUUID()))) + { cir.setReturnValue(true); } } diff --git a/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java b/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java index 471ca37..98079e4 100644 --- a/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java +++ b/src/main/java/com/joacarpet/mixin/insaneBehaviors/DefaultDispenseItemBehaviorMixin.java @@ -21,6 +21,8 @@ package com.joacarpet.mixin.insaneBehaviors; import com.joacarpet.JoaCarpetSettings; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.core.Direction; import net.minecraft.core.Position; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; @@ -29,7 +31,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.At; import java.util.ArrayList; @@ -39,13 +40,18 @@ @Mixin(DefaultDispenseItemBehavior.class) public class DefaultDispenseItemBehaviorMixin { - @Redirect(method = "spawnItem", at = @At( + @WrapOperation(method = "spawnItem", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/entity/item/ItemEntity;setDeltaMovement(DDD)V" )) - private static void setDeltaMovement(ItemEntity itemEntity, double d, double e, double f, Level _level, ItemStack _itemStack, int i, Direction direction, Position _position) { + private static void setDeltaMovement( + ItemEntity itemEntity, + double d, double e, double f, + Operation original, + Level _level, ItemStack _itemStack, int i, Direction direction, Position _position + ) { if (JoaCarpetSettings.insaneBehaviors.equals("off")) { - itemEntity.setDeltaMovement(d, e, f); + original.call(itemEntity, d, e, f); return; } ArrayList unitVelocity = nextEvenlyDistributedPoint(3); @@ -68,6 +74,6 @@ private static void setDeltaMovement(ItemEntity itemEntity, double d, double e, ); default -> throw new IllegalStateException("Unexpected value: " + JoaCarpetSettings.insaneBehaviors); }; - itemEntity.setDeltaMovement(velocity); + original.call(itemEntity, velocity.x, velocity.y, velocity.z); } } diff --git a/src/main/java/com/joacarpet/mixin/insaneBehaviors/PistonBaseBlockMixin.java b/src/main/java/com/joacarpet/mixin/insaneBehaviors/PistonBaseBlockMixin.java index 1973d29..33844e7 100644 --- a/src/main/java/com/joacarpet/mixin/insaneBehaviors/PistonBaseBlockMixin.java +++ b/src/main/java/com/joacarpet/mixin/insaneBehaviors/PistonBaseBlockMixin.java @@ -21,6 +21,8 @@ package com.joacarpet.mixin.insaneBehaviors; import com.joacarpet.JoaCarpetSettings; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.EntityType; @@ -44,20 +46,20 @@ @Mixin(PistonBaseBlock.class) public class PistonBaseBlockMixin { - @Redirect(method = "moveBlocks", at = @At( + @WrapOperation(method = "moveBlocks", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/block/piston/PistonBaseBlock;dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;)V" )) - private void dropResources(BlockState blockState, LevelAccessor levelAccessor, BlockPos blockPos, @Nullable BlockEntity blockEntity) { + private void dropResources(BlockState blockState, LevelAccessor levelAccessor, BlockPos blockPos, @Nullable BlockEntity blockEntity, Operation original) { + if (JoaCarpetSettings.insaneBehaviors.equals("off")) { + original.call(blockState, levelAccessor, blockPos, blockEntity); + return; + } // net.minecraft.world.level.block.Block.dropResources(net.minecraft.world.level.block.state.BlockState, net.minecraft.world.level.LevelAccessor, net.minecraft.core.BlockPos, net.minecraft.world.level.block.entity.BlockEntity) if (levelAccessor instanceof ServerLevel) { Level level = (ServerLevel) levelAccessor; Block.getDrops(blockState, (ServerLevel)levelAccessor, blockPos, blockEntity).forEach(itemStack -> { - if (JoaCarpetSettings.insaneBehaviors.equals("off")) { - Block.popResource(level, blockPos, itemStack); - } else { - customPopResource(level, blockPos, itemStack); - } + customPopResource(level, blockPos, itemStack); }); //#if MC >= 11900 blockState.spawnAfterBreak((ServerLevel)levelAccessor, blockPos, ItemStack.EMPTY, true); diff --git a/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java b/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java index 38739b0..f6eb22a 100644 --- a/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java +++ b/src/main/java/com/joacarpet/mixin/insaneBehaviors/ProjectileMixin.java @@ -22,6 +22,8 @@ import com.joacarpet.InsaneBehaviors; import com.joacarpet.JoaCarpetSettings; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.minecraft.world.entity.projectile.Projectile; import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; @@ -34,13 +36,13 @@ @Mixin(Projectile.class) public class ProjectileMixin { - @Redirect(method = "shoot", at = @At( + @WrapOperation(method = "shoot", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/phys/Vec3;add(DDD)Lnet/minecraft/world/phys/Vec3;" )) - private Vec3 add(Vec3 vec3, double d, double e, double f, double deltaMovementX, double deltaMovementY, double deltaMovementZ, float deltaMovementMultiplier, float divergence) { + private Vec3 add(Vec3 vec3, double d, double e, double f, Operation original, double deltaMovementX, double deltaMovementY, double deltaMovementZ, float deltaMovementMultiplier, float divergence) { if (JoaCarpetSettings.insaneBehaviors.equals("off")) { - return new Vec3(vec3.x + d, vec3.y + e, vec3.z + f); + return original.call(vec3, d, e, f); } ArrayList unitVelocity = InsaneBehaviors.nextEvenlyDistributedPoint(3); @@ -63,7 +65,7 @@ private Vec3 add(Vec3 vec3, double d, double e, double f, double deltaMovementX, ); default -> throw new IllegalStateException("Unexpected value: " + JoaCarpetSettings.insaneBehaviors); }; - return new Vec3(vec3.x + velocity.x, vec3.y + velocity.y, vec3.z + velocity.z); + return original.call(vec3, vec3.x + velocity.x, vec3.y + velocity.y, vec3.z + velocity.z); } } diff --git a/src/main/java/com/joacarpet/mixin/miscSurvival/DisableElytraRocketsMixin.java b/src/main/java/com/joacarpet/mixin/miscSurvival/DisableElytraRocketsMixin.java new file mode 100644 index 0000000..8257441 --- /dev/null +++ b/src/main/java/com/joacarpet/mixin/miscSurvival/DisableElytraRocketsMixin.java @@ -0,0 +1,42 @@ +/* + * This file is part of the JoaCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Joa and contributors + * + * JoaCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * JoaCarpet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JoaCarpet. If not, see . + */ + +package com.joacarpet.mixin.miscSurvival; + +import com.joacarpet.JoaCarpetSettings; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.FireworkRocketItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +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(FireworkRocketItem.class) +public abstract class DisableElytraRocketsMixin { + @Inject(method = "use", at = @At("HEAD"), cancellable = true) + public void use(Level level, Player player, InteractionHand interactionHand, CallbackInfoReturnable> cir) { + if (JoaCarpetSettings.disableElytraRockets.equals("true")) + cir.setReturnValue(InteractionResultHolder.pass(player.getItemInHand(interactionHand))); + } +} diff --git a/src/main/java/com/joacarpet/mixin/miscSurvival/DisableEndermanGriefingMixin.java b/src/main/java/com/joacarpet/mixin/miscSurvival/DisableEndermanGriefingMixin.java new file mode 100644 index 0000000..ec2ec11 --- /dev/null +++ b/src/main/java/com/joacarpet/mixin/miscSurvival/DisableEndermanGriefingMixin.java @@ -0,0 +1,49 @@ +/* + * This file is part of the JoaCarpet project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 Joa and contributors + * + * JoaCarpet is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * JoaCarpet is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with JoaCarpet. If not, see . + */ + +package com.joacarpet.mixin.miscSurvival; + +import com.joacarpet.JoaCarpetSettings; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +//#if MC >= 11800 +import net.minecraft.tags.TagKey; +//#else +//$$ import net.minecraft.tags.Tag; +//#endif + +@Mixin(targets = "net.minecraft.world.entity.monster.EnderMan$EndermanTakeBlockGoal") +public abstract class DisableEndermanGriefingMixin { + //#if MC >= 11800 + @WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/tags/TagKey;)Z")) + public boolean isHoldable(BlockState instance, TagKey tagKey, Operation original) { + //#else +//$$ @WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/state/BlockState;is(Lnet/minecraft/tags/Tag;)Z")) +//$$ public boolean isHoldable(BlockState instance, Tag tagKey, Operation original) { + //#endif + + return original.call(instance, tagKey) && JoaCarpetSettings.disableEndermanGriefing.equals("false"); + } +} diff --git a/src/main/resources/assets/joacarpet/lang/en_us.json b/src/main/resources/assets/joacarpet/lang/en_us.json index 1c06f87..64bb208 100644 --- a/src/main/resources/assets/joacarpet/lang/en_us.json +++ b/src/main/resources/assets/joacarpet/lang/en_us.json @@ -1,5 +1,7 @@ { "carpet.rule.insaneBehaviors.desc": "Makes the random velocities of droppers and projectiles (as well as both the position and velocity of blocks broken by pistons) systematically iterate through the most extreme values possible, and then repeatedly iterate through all the halfway points in between, in a sense attempting every point in a 3d/5d \"grid\" that slowly increases in resolution.\nFor droppers and projectiles, this setting determines whether the max value corresponds to the old gaussian randomness limits (\"extreme\"), or the limits of the triangular randomness introduced in 1.19 (\"sensible\"). Both settings function the same for blocks being broken by pistons.\nFor the `/insanebehaviors ` command, see `/carpet commandInsaneBehaviors`.\nDo note that insaneBehaviors works on a global iterator: any triggering event will step through an iteration from all other insaneBehaviors events, too.", "carpet.rule.commandInsaneBehaviors.desc": "The command used for the `insaneBehaviors` rule.\n\"reset\" sets the `resolution` and `counter` back to the default values. \"getstate\" and \"setstate\" are used to manually read and write the current iteration state.", - "carpet.rule.blockTickling.desc": "Lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with update interations off or with budded blocks." + "carpet.rule.commandBlockTickling.desc": "Controls who can use the `/blocktickling` command, which lets you send manual block and/or shape updates to blocks using a feather item. Updates are sent from the block in front of the face you're clicking on. Useful if you're working with budded blocks, with /carpet interactionUpdates off, or with intricarpet's /interaction command.", + "carpet.rule.disableEndermanGriefing.desc": "Disables enderman griefing.", + "carpet.rule.disableElytraRockets.desc": "Disables using rockets with elytra." } \ No newline at end of file diff --git a/src/main/resources/joacarpet.mixins.json b/src/main/resources/joacarpet.mixins.json index d63d31f..b63b2df 100644 --- a/src/main/resources/joacarpet.mixins.json +++ b/src/main/resources/joacarpet.mixins.json @@ -4,16 +4,15 @@ "package": "com.joacarpet.mixin", "compatibilityLevel": "{{COMPATIBILITY_LEVEL}}", "mixins": [ - "MinecraftServerMixin", - "blockTickling.ItemMixin", "blockTickling.PlayerMixin", - "insaneBehaviors.BlockMixin", "insaneBehaviors.ContainersMixin", "insaneBehaviors.DefaultDispenseItemBehaviorMixin", "insaneBehaviors.PistonBaseBlockMixin", - "insaneBehaviors.ProjectileMixin" + "insaneBehaviors.ProjectileMixin", + "miscSurvival.DisableEndermanGriefingMixin", + "miscSurvival.DisableElytraRocketsMixin" ], "client": [ ], diff --git a/versions/1.17.1/gradle.properties b/versions/1.17.1/gradle.properties index 353c74c..fc47970 100644 --- a/versions/1.17.1/gradle.properties +++ b/versions/1.17.1/gradle.properties @@ -8,7 +8,7 @@ # Build Information # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.17.1 + game_versions=1.17.1\n1.17.0\n1.17 # Dependencies # fabric_api_version=0.46.1+1.17 diff --git a/versions/1.18.2/gradle.properties b/versions/1.18.2/gradle.properties index 7292cc4..1c07adf 100644 --- a/versions/1.18.2/gradle.properties +++ b/versions/1.18.2/gradle.properties @@ -8,7 +8,7 @@ # Build Information # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.18.2 + game_versions=1.18.2\n1.18.1\n1.18.0\n1.18 # Dependencies # fabric_api_version=0.76.0+1.18.2 diff --git a/versions/1.19.4/gradle.properties b/versions/1.19.4/gradle.properties index fd9ce76..2641801 100644 --- a/versions/1.19.4/gradle.properties +++ b/versions/1.19.4/gradle.properties @@ -8,11 +8,11 @@ # Build Information # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.19.4 + game_versions=1.19.4\n1.19.3\n1.19.2\n1.19.1\n1.19.0\n1.19 # Dependencies # fabric_api_version=0.87.2+1.19.4 # https://masa.dy.fi/maven/carpet/fabric-carpet/ -carpet_core_version=1.4.101+v230319 +carpet_core_version=1.4.100+v230314 carpet_minecraft_version=1.19.4 diff --git a/versions/1.20.2/gradle.properties b/versions/1.20.2/gradle.properties index e4d07fc..7937e3a 100644 --- a/versions/1.20.2/gradle.properties +++ b/versions/1.20.2/gradle.properties @@ -8,7 +8,7 @@ # Build Information # The target mc versions for the mod during mod publishing, separated with \n - game_versions=1.20.2\n1.20.1 + game_versions=1.20.3\n1.20.2\n1.20.1\n1.20.0\n1.20 # Dependencies # fabric_api_version=0.91.3+1.20.4