From 85f54801c202612f8dc1ae9537fa21471b5afaf0 Mon Sep 17 00:00:00 2001
From: 1024_byteeeee <2270484921@qq.com>
Date: Sat, 25 Nov 2023 13:33:05 +0800
Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20=E5=8F=AC=E5=9B=9E?=
=?UTF-8?q?=E4=B8=A4=E4=B8=AA=E8=A7=84=E5=88=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../club/mcams/carpet/AmsServerSettings.java | 6 ++
.../AbstractBlockStateMixin.java | 53 ++++++++++++++++++
.../BlockMixin.java | 55 +++++++++++++++++++
src/main/resources/amscarpet.mixins.json | 2 +
.../assets/carpetamsaddition/lang/en_us.yml | 4 ++
.../assets/carpetamsaddition/lang/zh_cn.yml | 6 ++
6 files changed, 126 insertions(+)
create mode 100644 src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/AbstractBlockStateMixin.java
create mode 100644 src/main/java/club/mcams/carpet/mixin/rule/mineBedrock_mineEndPortalFrame/BlockMixin.java
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: