diff --git a/gradle.properties b/gradle.properties index 2629070..c45083a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1G carpet_core_version=1.4.21+v201216 # Mod Properties - mod_version = 0.1.3-alpha.3 + mod_version = 0.1.4-alpha.1 maven_group = net.fabricmc archives_base_name = plusls-carpet-addition diff --git a/src/main/java/com/plusls/carpet/PcaSettings.java b/src/main/java/com/plusls/carpet/PcaSettings.java index 7cb52ae..1d85235 100644 --- a/src/main/java/com/plusls/carpet/PcaSettings.java +++ b/src/main/java/com/plusls/carpet/PcaSettings.java @@ -66,6 +66,12 @@ public class PcaSettings { ) public static boolean shulkerBoxQuickUnpack = false; + @Rule( + desc = "use dye on shulker box", + category = {PCA, RuleCategory.FEATURE, RuleCategory.EXPERIMENTAL} + ) + public static boolean useDyeOnShulkerBox = false; + // debug @Rule( desc = "pcaDebug mode", diff --git a/src/main/java/com/plusls/carpet/mixin/rule/emptyShulkerBoxStack/MixinItemStack.java b/src/main/java/com/plusls/carpet/mixin/rule/emptyShulkerBoxStack/MixinItemStack.java index 07a037d..53d5782 100644 --- a/src/main/java/com/plusls/carpet/mixin/rule/emptyShulkerBoxStack/MixinItemStack.java +++ b/src/main/java/com/plusls/carpet/mixin/rule/emptyShulkerBoxStack/MixinItemStack.java @@ -33,7 +33,6 @@ public void getMaxStackSizeStackSensitive(CallbackInfoReturnable ci) { if (this.getItem() instanceof BlockItem && ((BlockItem) item).getBlock() instanceof ShulkerBoxBlock && !shulkerBoxHasItems((ItemStack) (Object) this)) { - // new Exception().printStackTrace(System.out); // 效率很低 但是 it works // 通过栈帧判断调用者来过滤返回值 StackTraceElement[] steArray = Thread.currentThread().getStackTrace(); diff --git a/src/main/java/com/plusls/carpet/mixin/rule/pcaSyncProtocol/entity/MixinStorageMinecartEntity.java b/src/main/java/com/plusls/carpet/mixin/rule/pcaSyncProtocol/entity/MixinStorageMinecartEntity.java index b2133f6..d8ac1d8 100644 --- a/src/main/java/com/plusls/carpet/mixin/rule/pcaSyncProtocol/entity/MixinStorageMinecartEntity.java +++ b/src/main/java/com/plusls/carpet/mixin/rule/pcaSyncProtocol/entity/MixinStorageMinecartEntity.java @@ -2,19 +2,16 @@ import com.plusls.carpet.PcaMod; import com.plusls.carpet.network.PcaSyncProtocol; -import com.plusls.carpet.util.rule.pcaSyncProtocol.IItemStackMonitor; import net.minecraft.entity.EntityType; import net.minecraft.entity.vehicle.AbstractMinecartEntity; import net.minecraft.entity.vehicle.StorageMinecartEntity; import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; import net.minecraft.screen.NamedScreenHandlerFactory; 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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(StorageMinecartEntity.class) public abstract class MixinStorageMinecartEntity extends AbstractMinecartEntity implements Inventory, NamedScreenHandlerFactory { @@ -22,29 +19,10 @@ protected MixinStorageMinecartEntity(EntityType entityType, World world) { super(entityType, world); } - @Inject(method = "getStack", at = @At(value = "RETURN")) - private void preGetStack(int slot, CallbackInfoReturnable cir) { - ((IItemStackMonitor) (Object) cir.getReturnValue()).setEntityMonitor(this); - } - - @Inject(method = "removeStack(II)Lnet/minecraft/item/ItemStack;", at = @At(value = "RETURN")) - private void preRemoveStack(int slot, int amount, CallbackInfoReturnable cir) { - if (PcaSyncProtocol.syncEntityToClient(this)) { - PcaMod.LOGGER.debug("update StorageMinecartEntity inventory: removeStack(II)."); - } - } - - @Inject(method = "removeStack(I)Lnet/minecraft/item/ItemStack;", at = @At(value = "RETURN")) - private void preRemoveStack(int slot, CallbackInfoReturnable cir) { - if (PcaSyncProtocol.syncEntityToClient(this)) { - PcaMod.LOGGER.debug("update StorageMinecartEntity inventory: removeStack(I)."); - } - } - - @Inject(method = "setStack", at = @At(value = "RETURN")) - void preSetStack(int slot, ItemStack stack, CallbackInfo ci) { + @Inject(method = "markDirty", at = @At(value = "RETURN")) + private void updateInventory(CallbackInfo ci) { if (PcaSyncProtocol.syncEntityToClient(this)) { - PcaMod.LOGGER.debug("update StorageMinecartEntity inventory: setStack."); + PcaMod.LOGGER.debug("update StorageMinecartEntity inventory."); } } } diff --git a/src/main/java/com/plusls/carpet/mixin/rule/pcaSyncProtocol/item/MixinItemStack.java b/src/main/java/com/plusls/carpet/mixin/rule/pcaSyncProtocol/item/MixinItemStack.java deleted file mode 100644 index d3906e7..0000000 --- a/src/main/java/com/plusls/carpet/mixin/rule/pcaSyncProtocol/item/MixinItemStack.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.plusls.carpet.mixin.rule.pcaSyncProtocol.item; - -import com.plusls.carpet.PcaMod; -import com.plusls.carpet.network.PcaSyncProtocol; -import com.plusls.carpet.util.rule.pcaSyncProtocol.IItemStackMonitor; -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -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; - -@Mixin(ItemStack.class) -public abstract class MixinItemStack implements IItemStackMonitor { - private Entity entityMonitor = null; - - @Shadow - private int count; - - @Shadow - protected abstract void updateEmptyState(); - - @Inject(method = "setCount", at = @At("HEAD")) - public void preSetCount(int count, CallbackInfo ci) { - if (entityMonitor != null && count != ((ItemStack)(Object)this).getCount()) { - this.count = count; - this.updateEmptyState(); - if (PcaSyncProtocol.syncEntityToClient(entityMonitor)) { - PcaMod.LOGGER.debug("update blockEntity ItemStack.setCount"); - } - entityMonitor = null; - } - } - - @Override - public void setEntityMonitor(Entity entity) { - entityMonitor = entity; - } -} \ No newline at end of file diff --git a/src/main/java/com/plusls/carpet/mixin/rule/shulkerBoxQuickUnpack/MixinItemEntity.java b/src/main/java/com/plusls/carpet/mixin/rule/shulkerBoxQuickUnpack/MixinItemEntity.java index db4391b..384b6f7 100644 --- a/src/main/java/com/plusls/carpet/mixin/rule/shulkerBoxQuickUnpack/MixinItemEntity.java +++ b/src/main/java/com/plusls/carpet/mixin/rule/shulkerBoxQuickUnpack/MixinItemEntity.java @@ -30,7 +30,7 @@ public MixinItemEntity(EntityType type, World world) { @Shadow public abstract ItemStack getStack(); - @Inject(method = "damage", at=@At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;remove()V", ordinal = 0)) + @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;remove()V", ordinal = 0)) private void shulkerBoxItemUnpack(DamageSource source, float amount, CallbackInfoReturnable cir) { if (this.world.isClient()) { return; @@ -40,14 +40,14 @@ private void shulkerBoxItemUnpack(DamageSource source, float amount, CallbackInf } ItemStack itemStack = getStack(); Item item = itemStack.getItem(); - if (item instanceof BlockItem && ((BlockItem)item).getBlock() instanceof ShulkerBoxBlock) { - CompoundTag lv = itemStack.getTag(); - if (lv != null) { - ListTag itemList = lv.getCompound("BlockEntityTag").getList("Items", 10); - dropItems(itemList.stream().map(CompoundTag.class::cast).map(ItemStack::fromTag)); - } + if (item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof ShulkerBoxBlock) { + CompoundTag lv = itemStack.getTag(); + if (lv != null) { + ListTag itemList = lv.getCompound("BlockEntityTag").getList("Items", 10); + dropItems(itemList.stream().map(CompoundTag.class::cast).map(ItemStack::fromTag)); } } + } public void dropItems(Stream stream) { if (this.world.isClient()) diff --git a/src/main/java/com/plusls/carpet/mixin/rule/useDyeOnShulkerBox/MixinDyeItem.java b/src/main/java/com/plusls/carpet/mixin/rule/useDyeOnShulkerBox/MixinDyeItem.java new file mode 100644 index 0000000..caa2926 --- /dev/null +++ b/src/main/java/com/plusls/carpet/mixin/rule/useDyeOnShulkerBox/MixinDyeItem.java @@ -0,0 +1,55 @@ +package com.plusls.carpet.mixin.rule.useDyeOnShulkerBox; + +import com.plusls.carpet.PcaSettings; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.ShulkerBoxBlock; +import net.minecraft.block.entity.ShulkerBoxBlockEntity; +import net.minecraft.item.DyeItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.ActionResult; +import net.minecraft.util.DyeColor; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(DyeItem.class) +public abstract class MixinDyeItem extends Item { + @Shadow public abstract DyeColor getColor(); + + public MixinDyeItem(Settings settings) { + super(settings); + } + + @Override + public ActionResult useOnBlock(ItemUsageContext context) { + if (!PcaSettings.useDyeOnShulkerBox) { + return ActionResult.PASS; + } + World world = context.getWorld(); + BlockPos pos = context.getBlockPos(); + BlockState blockState = world.getBlockState(pos); + + if (blockState.isOf(Blocks.SHULKER_BOX)) { + if (!world.isClient()) { + ShulkerBoxBlockEntity blockEntity = (ShulkerBoxBlockEntity)world.getBlockEntity(pos); + BlockState newBlockState = ShulkerBoxBlock.get(getColor()).getDefaultState(). + with(ShulkerBoxBlock.FACING, blockState.get(ShulkerBoxBlock.FACING)); + + if (world.setBlockState(pos, newBlockState)) { + ShulkerBoxBlockEntity newBlockEntity = (ShulkerBoxBlockEntity)world.getBlockEntity(pos); + assert blockEntity != null; + assert newBlockEntity != null; + newBlockEntity.deserializeInventory(blockEntity.serializeInventory(new CompoundTag())); + newBlockEntity.markDirty(); + context.getStack().decrement(1); + } + } + return ActionResult.success(world.isClient); + } + return ActionResult.PASS; + } +} diff --git a/src/main/java/com/plusls/carpet/network/PcaSyncProtocol.java b/src/main/java/com/plusls/carpet/network/PcaSyncProtocol.java index 113edbd..1c00175 100644 --- a/src/main/java/com/plusls/carpet/network/PcaSyncProtocol.java +++ b/src/main/java/com/plusls/carpet/network/PcaSyncProtocol.java @@ -1,5 +1,6 @@ package com.plusls.carpet.network; +import carpet.patches.EntityPlayerMPFake; import com.plusls.carpet.PcaMod; import com.plusls.carpet.PcaSettings; import io.netty.buffer.Unpooled; @@ -11,6 +12,7 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.enums.ChestType; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.PacketByteBuf; import net.minecraft.server.MinecraftServer; @@ -210,6 +212,12 @@ private static void syncEntityHandler(MinecraftServer server, ServerPlayerEntity PcaMod.LOGGER.debug("Can't find entity {}.", entityId); } else { clearPlayerWatchData(player); + // 判断 op 只有 op 才能看玩家信息 + if (entity instanceof PlayerEntity && !(entity instanceof EntityPlayerMPFake)) { + if (server.getPermissionLevel(player.getGameProfile()) < 2) { + return; + } + } PcaMod.LOGGER.debug("{} watch entity {}: {}", player.getName().asString(), entityId, entity); updateEntity(player, entity); diff --git a/src/main/java/com/plusls/carpet/util/rule/pcaSyncProtocol/IItemStackMonitor.java b/src/main/java/com/plusls/carpet/util/rule/pcaSyncProtocol/IItemStackMonitor.java deleted file mode 100644 index 881894e..0000000 --- a/src/main/java/com/plusls/carpet/util/rule/pcaSyncProtocol/IItemStackMonitor.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.plusls.carpet.util.rule.pcaSyncProtocol; - -import net.minecraft.entity.Entity; - -public interface IItemStackMonitor { - void setEntityMonitor(Entity entity); -} diff --git a/src/main/resources/assets/pca/icon.png b/src/main/resources/assets/pca/icon.png index 047b91f..81cba56 100644 Binary files a/src/main/resources/assets/pca/icon.png and b/src/main/resources/assets/pca/icon.png differ diff --git a/src/main/resources/assets/pca/lang/zh_cn.json b/src/main/resources/assets/pca/lang/zh_cn.json index 9227abc..1c2d098 100644 --- a/src/main/resources/assets/pca/lang/zh_cn.json +++ b/src/main/resources/assets/pca/lang/zh_cn.json @@ -20,6 +20,9 @@ "rule.shulkerBoxQuickUnpack.name": "潜影盒快速拆包", "rule.shulkerBoxQuickUnpack.desc": "物品状态下的潜影盒在被摧毁时,盒中的物品会自动掉落,来自 1.17", + "rule.useDyeOnShulkerBox.name": "潜影盒使用染料染色", + "rule.useDyeOnShulkerBox.desc": "可以使用染料直接对地上的潜影盒染色", + "rule.pcaDebug.name": "PCA调试模式", "rule.pcaDebug.desc": "打印更多调试信息" } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 71a5e92..3514607 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -2,7 +2,6 @@ "schemaVersion": 1, "id": "pca", "version": "${version}", - "name": "Plusls carpet addition mod", "description": "plusls carpet addition mod", "authors": [ @@ -12,10 +11,8 @@ "homepage": "https://blog.pluglg.com/", "sources": "https://github.com/plusls/plusls-carpet-addition" }, - "license": "CC0-1.0", "icon": "assets/pca/icon.png", - "environment": "*", "entrypoints": { "main": [ @@ -24,14 +21,16 @@ "mixins": [ "pca.mixins.json" ], - "depends": { "fabricloader": ">=0.7.4", "fabric": ">=0.28.0", - "minecraft": "1.16.x", + "minecraft": ">=1.16.2", "carpet": "*" }, "suggests": { "another-mod": "*" + }, + "custom": { + "modmenu:parent": "carpet" } } diff --git a/src/main/resources/pca.mixins.json b/src/main/resources/pca.mixins.json index fc87d7f..a01cca8 100644 --- a/src/main/resources/pca.mixins.json +++ b/src/main/resources/pca.mixins.json @@ -5,7 +5,6 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "MixinCrashReport", - "rule.shulkerBoxQuickUnpack.MixinItemEntity", "rule.emptyShulkerBoxStack.MixinItemStack", "rule.pcaSyncProtocol.block.MixinAbstractFurnaceBlockEntity", "rule.pcaSyncProtocol.block.MixinBarrelBlockEntity", @@ -18,7 +17,8 @@ "rule.pcaSyncProtocol.entity.MixinHorseBaseEntity", "rule.pcaSyncProtocol.entity.MixinMerchantEntity", "rule.pcaSyncProtocol.entity.MixinStorageMinecartEntity", - "rule.pcaSyncProtocol.item.MixinItemStack", + "rule.useDyeOnShulkerBox.MixinDyeItem", + "rule.shulkerBoxQuickUnpack.MixinItemEntity", "rule.shulkerRenewable.MixinShulkerEntity" ], "client": [