fix: 修复了强化深板岩可获取功能不可用的问题

This commit is contained in:
Disy authored and zly2006 committed 2024-07-11 12:14:01 +08:00
1 parent a0ffb5eb6a
commit e8dc993ed2
13 files changed
+77 -68

No files matched your search

@@ -37,6 +37,9 @@ public class SLSCarpetSettings {
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
public static boolean canUseSitCommand = false;
@Rule(categories = {CARPET_ID, RuleCategory.CREATIVE})
public static int maxUpdateQueueSize = -1;
@Rule(categories = {CARPET_ID, PCA, PROTOCOL})
public static boolean pcaSyncProtocol = false;
@@ -131,7 +131,7 @@ public class ServerMain implements ModInitializer, CarpetExtension {
ServerPlayerEntity player = context.getSource().getPlayer();
assert player != null;
if (player.getVehicle() != null) { // 防止重复的坐下行为
if (player.getVehicle() != null || !player.isOnGround()) { // 防止错误的坐下行为
return 1;
}
@@ -1,50 +0,0 @@
package com.github.zly2006.carpetslsaddition.mixin.block;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.SignBlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
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.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);
}
}
}
}
}
}
}
@@ -1,8 +1,15 @@
package com.github.zly2006.carpetslsaddition.mixin.entity;
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.FallingBlockEntity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.world.World;
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;
@@ -11,9 +18,17 @@ import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.function.Predicate;
@Mixin(FallingBlockEntity.class)
public class MixinFallingBlockEntity {
@Inject(method = "handleFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;"), locals = LocalCapture.CAPTURE_FAILSOFT)
private void handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource, CallbackInfoReturnable<Boolean> cir, int i, Predicate<?> predicate, DamageSource damageSource2, float f) {
public abstract class MixinFallingBlockEntity extends Entity {
public MixinFallingBlockEntity(EntityType<?> type, World world) {
super(type, world);
}
@Inject(method = "handleFallDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getOtherEntities(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/Box;Ljava/util/function/Predicate;)Ljava/util/List;", shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILSOFT)
private void handleFallDamage(float fallDistance, float damageMultiplier, DamageSource damageSource, CallbackInfoReturnable<Boolean> cir, int i, Predicate<Entity> predicate, DamageSource damageSource2, float f) {
if (SLSCarpetSettings.obtainableReinforcedDeepSlate) {
predicate = entity -> entity instanceof ItemEntity;
this.getWorld().getOtherEntities(this, this.getBoundingBox(), predicate).forEach((entity) -> entity.damage(damageSource2, f));
}
}
}
@@ -14,10 +14,11 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(ServerPlayerEntity.class)
public abstract class MixinServerPlayerEntity extends PlayerEntity {
public abstract class MixinServerPlayerEntity extends PlayerEntity {
@Shadow
public ServerPlayNetworkHandler networkHandler;
private int sneakTimes = 0;
private long lastSneakTime = 0;
@@ -42,9 +43,9 @@ public abstract class MixinServerPlayerEntity extends PlayerEntity {
if (this.isOnGround() && nowTime - lastSneakTime < 400) {
sneakTimes += 1;
if (sneakTimes == 3) {
ArmorStandEntity armorStandEntity = new ArmorStandEntity(world, this.getX(), this.getY() - 0.16, this.getZ());
ArmorStandEntity armorStandEntity = new ArmorStandEntity(getWorld(), this.getX(), this.getY() - 0.16, this.getZ());
((SitEntity) armorStandEntity).setSitEntity(true);
world.spawnEntity(armorStandEntity);
getWorld().spawnEntity(armorStandEntity);
this.setSneaking(false);
this.startRiding(armorStandEntity);
sneakTimes = 0;
@@ -33,7 +33,7 @@ public abstract class MixinMerchantEntity extends PassiveEntity implements Npc,
@Inject(method = "<init>(Lnet/minecraft/entity/EntityType;Lnet/minecraft/world/World;)V", at = @At(value = "RETURN"))
private void addInventoryListener(EntityType<? extends MerchantEntity> entityType, World world, CallbackInfo info) {
if (this.world.isClient()) {
if (this.getWorld().isClient()) {
return;
}
this.inventory.addListener(this);
@@ -0,0 +1,31 @@
package com.github.zly2006.carpetslsaddition.mixin.world;
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
import net.minecraft.world.block.ChainRestrictedNeighborUpdater;
import org.spongepowered.asm.mixin.Final;
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.CallbackInfo;
import java.util.ArrayDeque;
@Mixin(ChainRestrictedNeighborUpdater.class)
public class MixinChainRestrictedNeighborUpdater {
@Shadow
@Final
private ArrayDeque<?> queue;
@Inject(method = "runQueuedUpdates", at = @At(value = "INVOKE", target = "Ljava/util/List;clear()V", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true)
public void injectRunQueuedUpdates(CallbackInfo ci) {
int maxSize = SLSCarpetSettings.maxUpdateQueueSize;
if (maxSize > 0) {
if (this.queue.size() > maxSize) {
ci.cancel();
// throw new OutOfMemoryError("The update queue exceeded the maximum allowed allocation of heap space set by SLS Addition!");
}
}
}
}
@@ -164,7 +164,7 @@ public class PcaSyncProtocol {
return;
}
BlockPos pos = buf.readBlockPos();
ServerWorld world = player.getWorld();
ServerWorld world = player.getServerWorld();
BlockState blockState = world.getBlockState(pos);
clearPlayerWatchData(player);
ServerMain.LOGGER.debug("{} watch blockpos {}: {}", player.getName().getString(), pos, blockState);
@@ -219,7 +219,7 @@ public class PcaSyncProtocol {
return;
}
int entityId = buf.readInt();
ServerWorld world = player.getWorld();
ServerWorld world = player.getServerWorld();
Entity entity = world.getEntityById(entityId);
if (entity == null) {
ServerMain.LOGGER.debug("Can't find entity {}.", entityId);
@@ -19,6 +19,7 @@
"carpet.rule.playerSit.name": "Player can sit",
"carpet.rule.canUseHatCommand.name": "Enable hat command",
"carpet.rule.canUseSitCommand.name": "Enable sit command",
"carpet.rule.maxUpdateQueueSize.name": "Maximum allowed capacity of update queue",
"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": "For jobless/nitwit villagers, after performing a set number of tick operations, skip the 1 tick operation.",
@@ -35,11 +36,14 @@
"carpet.rule.playerSit.desc": "Player can sit down when fast sneak 3 times.",
"carpet.rule.canUseHatCommand.desc": "Allows all players to use the /hat command to place their main hand items in the helmet slot",
"carpet.rule.canUseSitCommand.desc": "Allows all players to use the /sit command to sit down",
"carpet.rule.maxUpdateQueueSize.desc": "Set the maximum allowed length of the update queue",
"carpet.rule.autoUrl.extra.0": "The URL sent by players to be directly clicked and redirected by other players",
"carpet.rule.skipTicksForJoblessVillager.extra.0": "Set to 0 to maintain the vanilla behavior",
"carpet.rule.skipTicksForJoblessVillager.extra.1": "Set to a number greater than 0, the value will be +1 based on the setting",
"carpet.rule.skipTicksForJoblessVillager.extra.2": "To prevents villagers from getting completely stuck when set to 1",
"carpet.rule.maxUpdateQueueSize.extra.0": "If set to a value not greater than 0, turn off this function and run according to Vanilla",
"carpet.rule.maxUpdateQueueSize.extra.1": "Otherwise, when the number of single updates exceeds the set value, an OutOfMemoryError will be thrown to generate update suppression",
"carpet.rule.pcaSyncPlayerEntity.extra.0": "NOBODY: nobody will be sync",
"carpet.rule.pcaSyncPlayerEntity.extra.1": "BOT: carpet bot will be sync",
"carpet.rule.pcaSyncPlayerEntity.extra.2": "OPS: carpet bot will be sync, and op can sync everyone's player entity data.",
@@ -19,6 +19,7 @@
"carpet.rule.playerSit.name": "玩家可坐下",
"carpet.rule.canUseHatCommand.name": "启用戴帽指令",
"carpet.rule.canUseSitCommand.name": "启用坐下指令",
"carpet.rule.maxUpdateQueueSize.name": "最大更新队列容量",
"carpet.rule.maxVillagersInABlock.desc": "每个方块中最大村民数量,设置-1为无限制",
"carpet.rule.obtainableReinforcedDeepSlate.desc": "当铁砧在64个深板岩的掉落物上时,可以获得强化深板岩",
@@ -35,11 +36,14 @@
"carpet.rule.playerSit.desc": "在快速潜行 3 次后玩家可以坐下",
"carpet.rule.canUseHatCommand.desc": "可让所有玩家使用/hat指令,将手中的物品置于头盔位",
"carpet.rule.canUseSitCommand.desc": "可让所有玩家使用/sit指令,以在原地坐下",
"carpet.rule.maxUpdateQueueSize.desc": "设定最大允许的更新队列长度",
"carpet.rule.autoUrl.extra.0": "使玩家发出的URL可以被其他玩家直接点击跳转",
"carpet.rule.skipTicksForJoblessVillager.extra.0": "设置为0则保持原版行为",
"carpet.rule.skipTicksForJoblessVillager.extra.1": "设置为大于0的数,将在设置的基础上将该值+1",
"carpet.rule.skipTicksForJoblessVillager.extra.2": "以此避免在设置为1的时候,村民完全卡死",
"carpet.rule.maxUpdateQueueSize.extra.0": "如果设定了不超过0的值,将关闭该功能,更新机制继续依照Vanilla运行",
"carpet.rule.maxUpdateQueueSize.extra.1": "否则,在单次更新数量超过设定最大容量后,服务器将抛出OutOfMemoryError,以达到快速更新抑制的效果",
"carpet.rule.pcaSyncPlayerEntity.extra.0": "NOBODY:所有玩家数据都无法同步",
"carpet.rule.pcaSyncPlayerEntity.extra.1": "BOT:地毯 mod 召唤出的 bot 的数据可以被同步",
"carpet.rule.pcaSyncPlayerEntity.extra.2": "OPS:地毯 mod 召唤出的 bot 的数据可以被同步, op 可以同步所有玩家的数据",
+1 -1
View File
@@ -27,7 +27,7 @@
"depends": {
"fabricloader": ">=0.13",
"fabric-api": "*",
"minecraft": "~1.19",
"minecraft": ">=1.20",
"java": ">=17",
"carpet": "*"
},
+1 -1
View File
@@ -4,7 +4,6 @@
"package": "com.github.zly2006.carpetslsaddition.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"block.MixinAbstractSignBlock",
"block.MixinBlock",
"carpet.MixinFakePlayer",
"carpet.MixinSettingsManager",
@@ -34,6 +33,7 @@
"screen.MixinScreenHandler",
"screen.MixinSlot",
"server.MixinPlayerManager",
"world.MixinChainRestrictedNeighborUpdater",
"world.MixinSpawnHelper"
],
"client": [