Skip to content

Commit

Permalink
update to 0.1.4-alpha.1
Browse files Browse the repository at this point in the history
优化了存储矿车的数据同步方法
对 pcaSyncProtocol 增加了鉴权,只有 op 可以获取别的玩家的数据,所有人都可以获取 bot 的数据(强烈建议更新)
新增了使用染料对潜影盒染色的功能
  • Loading branch information
plusls committed Jan 13, 2021
1 parent dd88437 commit 731ae07
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 88 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/plusls/carpet/PcaSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void getMaxStackSizeStackSensitive(CallbackInfoReturnable<Integer> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,27 @@

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 {
protected MixinStorageMinecartEntity(EntityType<?> entityType, World world) {
super(entityType, world);
}

@Inject(method = "getStack", at = @At(value = "RETURN"))
private void preGetStack(int slot, CallbackInfoReturnable<ItemStack> 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<ItemStack> 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<ItemStack> 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.");
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean> cir) {
if (this.world.isClient()) {
return;
Expand All @@ -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<ItemStack> stream) {
if (this.world.isClient())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/plusls/carpet/network/PcaSyncProtocol.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

This file was deleted.

Binary file modified src/main/resources/assets/pca/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/main/resources/assets/pca/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "打印更多调试信息"
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"schemaVersion": 1,
"id": "pca",
"version": "${version}",

"name": "Plusls carpet addition mod",
"description": "plusls carpet addition mod",
"authors": [
Expand All @@ -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": [
Expand All @@ -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"
}
}
4 changes: 2 additions & 2 deletions src/main/resources/pca.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinCrashReport",
"rule.shulkerBoxQuickUnpack.MixinItemEntity",
"rule.emptyShulkerBoxStack.MixinItemStack",
"rule.pcaSyncProtocol.block.MixinAbstractFurnaceBlockEntity",
"rule.pcaSyncProtocol.block.MixinBarrelBlockEntity",
Expand All @@ -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": [
Expand Down

0 comments on commit 731ae07

Please sign in to comment.