Skip to content

Commit

Permalink
✅ 召回两个规则
Browse files Browse the repository at this point in the history
  • Loading branch information
1024-byteeeee committed Nov 25, 2023
1 parent 9b8ecb8 commit 85f5480
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/club/mcams/carpet/AmsServerSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*
* 可移动方块规则
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<Float> 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));
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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);
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/amscarpet.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/carpetamsaddition/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/carpetamsaddition/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ carpetamsaddition:
desc: 更改客户端允许的最大方块放置距离,设置为“-1”禁用该规则
extra:
'0': '允许设定的范围:0 - 512'
mineBedrock:
name: 可采集基岩
desc: 玩家可以采集基岩
mineEndPortalFrame:
name: 可采集末地传送门框架
desc: 玩家可以采集末地传送门框架

# 计划刻催熟规则:
scheduledRandomTickCactus:
Expand Down

0 comments on commit 85f5480

Please sign in to comment.