feat: noBatSpawning
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user