feat: noBatSpawning

This commit is contained in:
zly2006 committed 2024-07-11 12:14:01 +08:00
1 parent ddb8f3b400
commit e21dc22859
9 files changed
+94 -121

No files matched your search

@@ -16,4 +16,8 @@ public class SLSCarpetSettings {
public static int maxVillagersInABlock = -1;
@Rule(categories = {CARPET_ID, RuleCategory.CREATIVE})
public static boolean creativeNoInfinitePickup = false;
@Rule(categories = {CARPET_ID})
public static boolean autoUrl = false;
@Rule(categories = {CARPET_ID})
public static boolean noBatSpawning = false;
}
@@ -0,0 +1,54 @@
package com.github.zly2006.carpetslsaddition.mixin;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.ChestBlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.entity.InventoryOwner;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
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(AbstractSignBlock.class)
public class MixinAbstractSignBlock {
@Inject(method = "onUse", at = @At("HEAD"), cancellable = true)
private void use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable<ActionResult> cir) {
if (state.getBlock() instanceof WallSignBlock && false) {
BlockPos pos1 = pos.offset(state.get(WallSignBlock.FACING).getOpposite());
BlockState state1 = world.getBlockState(pos1);
if (state1.getBlock() instanceof ChestBlock || state1.getBlock() instanceof BarrelBlock) {
SignBlockEntity signBlockEntity = (SignBlockEntity) world.getBlockEntity(pos);
BlockEntity blockEntity = world.getBlockEntity(pos1);
if (blockEntity instanceof Inventory inventory) {
if (signBlockEntity.getTextOnRow(0, true).getString().equals("[[Once]]")) {
int i = 0;
for (; i < inventory.size(); i++) {
if (!inventory.getStack(i).isEmpty()) {
break;
}
}
if (i == inventory.size()) {
return;
}
ItemStack stack = inventory.removeStack(i);
inventory.markDirty();
if (player.getInventory().insertStack(stack)) {
cir.setReturnValue(ActionResult.SUCCESS);
}
}
}
}
}
}
}
@@ -0,0 +1,22 @@
package com.github.zly2006.carpetslsaddition.mixin;
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.SpawnHelper;
import org.jetbrains.annotations.Nullable;
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(SpawnHelper.class)
public class MixinSpawnHelper {
@Inject(method = "createMob", at = @At("HEAD"), cancellable = true)
private static void onCreateMob(ServerWorld world, EntityType<?> type, CallbackInfoReturnable<@Nullable MobEntity> cir) {
if (SLSCarpetSettings.noBatSpawning && type == EntityType.BAT) {
cir.setReturnValue(null);
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 453 B

@@ -2,5 +2,7 @@
"carpet.rule.obtainableReinforcedDeepSlate.desc": "When an anvil falls on 64 dropped deepslates, they will be turned in a reinforced deepslate instead of disappearing.",
"carpet.rule.skipTicksForJoblessVillager.desc": "Villagers will skip ticks if they have no job.",
"carpet.rule.maxVillagersInABlock.desc": "The maximum number of villagers that can be in a block, set to -1 to disable.",
"carpet.rule.creativeNoInfinitePickup.desc": "If my inventory is full, don't pick up items in creative mode."
"carpet.rule.creativeNoInfinitePickup.desc": "If my inventory is full, don't pick up items in creative mode.",
"carpet.rule.autoUrl.desc": "Automatically add click event to URLs in chat.",
"carpet.rule.noBatSpawning.desc": "Prevents bats from spawning."
}
@@ -2,5 +2,7 @@
"carpet.rule.maxVillagersInABlock.desc": "每个方块中最大村民数量,设置-1为无限制",
"carpet.rule.obtainableReinforcedDeepSlate.desc": "当铁砧在64个深板岩的凋落物上时,可以获得强化深板岩",
"carpet.rule.skipTicksForJoblessVillager.desc": "村民没有工作时,跳过村民的tick",
"carpet.rule.creativeNoInfinitePickup.desc": "创造模式下,玩家不能无限制地拾取物品"
"carpet.rule.creativeNoInfinitePickup.desc": "创造模式下,玩家不能无限制地拾取物品",
"carpet.rule.autoUrl.desc": "自动识别URL并添加点击事件",
"carpet.rule.noBatSpawning.desc": "禁止蝙蝠生成"
}
+1 -2
View File
@@ -11,8 +11,7 @@
"contact": {
},
"license": "CC0-1.0",
"icon": "assets/slsaddition/icon.png",
"license": "MIT",
"environment": "*",
"entrypoints": {
@@ -5,9 +5,11 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"AccessorPlayerAbilities",
"MixinAbstractSignBlock",
"MixinFallingBlockEntity",
"MixinItemEntity",
"MixinPlayerInventory",
"MixinSpawnHelper",
"MixinVillagerEntity"
],
"client": [