diff --git a/src/main/java/club/mcams/carpet/AmsServerSettings.java b/src/main/java/club/mcams/carpet/AmsServerSettings.java index 7058b6a4..075d9dc0 100644 --- a/src/main/java/club/mcams/carpet/AmsServerSettings.java +++ b/src/main/java/club/mcams/carpet/AmsServerSettings.java @@ -220,6 +220,12 @@ public class AmsServerSettings { ) public static double maxClientBlockReachDistance = -1.0; + @Rule(categories = {AMS, FEATURE}) + public static boolean mineBedrock = false; + + @Rule(categories = {AMS, FEATURE}) + public static boolean mineEndPortalFrame = false; + /* * 可移动方块规则 */ diff --git a/src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/AbstractBlockStateMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/AbstractBlockStateMixin.java new file mode 100644 index 00000000..046b3017 --- /dev/null +++ b/src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/AbstractBlockStateMixin.java @@ -0,0 +1,53 @@ +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition 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. + * + * Carpet AMS Addition 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 Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.mineBedrock_mineEndPortalFrame; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.block.AbstractBlock; +import net.minecraft.block.Block; +import net.minecraft.block.Blocks; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(AbstractBlock.AbstractBlockState.class) +public abstract class AbstractBlockStateMixin { + + @Shadow + public abstract Block getBlock(); + + @Inject(method = "getHardness", at = @At("HEAD"), cancellable = true) + public void getHardness(BlockView world, BlockPos pos, CallbackInfoReturnable cir) { + if (AmsServerSettings.mineBedrock && this.getBlock() == Blocks.BEDROCK) { + cir.setReturnValue(Blocks.OBSIDIAN.getDefaultState().getHardness(world, pos)); + } + + if (AmsServerSettings.mineEndPortalFrame && this.getBlock() == Blocks.END_PORTAL_FRAME) { + cir.setReturnValue(Blocks.END_STONE.getDefaultState().getHardness(world, pos)); + } + } +} diff --git a/src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/BlockMixin.java b/src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/BlockMixin.java new file mode 100644 index 00000000..3794f3cc --- /dev/null +++ b/src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/BlockMixin.java @@ -0,0 +1,55 @@ +/* + * This file is part of the Carpet AMS Addition project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2023 A Minecraft Server and contributors + * + * Carpet AMS Addition 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. + * + * Carpet AMS Addition 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 Carpet AMS Addition. If not, see . + */ + +package club.mcams.carpet.mixin.rule.mineBedrock_mineEndPortalFrame; + +import club.mcams.carpet.AmsServerSettings; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +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.CallbackInfo; + +import static net.minecraft.block.Block.dropStack; + +@Mixin(Block.class) +public abstract class BlockMixin { + @Inject(method = "onBreak", at = @At("HEAD")) + public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo ci) { + if (AmsServerSettings.mineBedrock && state.getBlock() == Blocks.BEDROCK) { + ItemStack bedrockStack = new ItemStack(Items.BEDROCK); + dropStack(world, pos, bedrockStack); + } + + if (AmsServerSettings.mineEndPortalFrame && state.getBlock() == Blocks.END_PORTAL_FRAME) { + ItemStack endPortalFrameStack = new ItemStack(Items.END_PORTAL_FRAME); + dropStack(world, pos, endPortalFrameStack); + } + } +} diff --git a/src/main/resources/amscarpet.mixins.json b/src/main/resources/amscarpet.mixins.json index 19f95e45..eb426ec0 100644 --- a/src/main/resources/amscarpet.mixins.json +++ b/src/main/resources/amscarpet.mixins.json @@ -34,6 +34,8 @@ "rule.largeShulkerBox.ShulkerBoxBlockEntityMixin", "rule.maxBlockInteractionDistance.ServerPlayerInteractionManagerMixin", "rule.maxBlockInteractionDistance.ServerPlayNetworkHandlerMixin", + "rule.mineBedrock_mineEndPortalFrame.AbstractBlockStateMixin", + "rule.mineBedrock_mineEndPortalFrame.BlockMixin", "rule.movableBlocks.PistonBlockMixin", "rule.netherWaterPlacement.DimensionTypeMixin", "rule.noCakeEating.CakeBlockMixin", diff --git a/src/main/resources/assets/carpetamsaddition/lang/en_us.yml b/src/main/resources/assets/carpetamsaddition/lang/en_us.yml index e41a3904..f416b22b 100644 --- a/src/main/resources/assets/carpetamsaddition/lang/en_us.yml +++ b/src/main/resources/assets/carpetamsaddition/lang/en_us.yml @@ -137,6 +137,10 @@ carpetamsaddition: desc: Change the maximum block placement distance allowed by the client, set to "-1" to disable this rule extra: '0': 'The range of values: 0 - 512' + mineBedrock: + desc: Players can mine bedrock + mineEndPortalFrame: + desc: Players can collect End portal frames # 计划刻催熟规则: scheduledRandomTickCactus: diff --git a/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml b/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml index cb7601bd..fafdb476 100644 --- a/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml +++ b/src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml @@ -183,6 +183,12 @@ carpetamsaddition: desc: 更改客户端允许的最大方块放置距离,设置为“-1”禁用该规则 extra: '0': '允许设定的范围:0 - 512' + mineBedrock: + name: 可采集基岩 + desc: 玩家可以采集基岩 + mineEndPortalFrame: + name: 可采集末地传送门框架 + desc: 玩家可以采集末地传送门框架 # 计划刻催熟规则: scheduledRandomTickCactus: