Skip to content

Commit

Permalink
update to 0.1.2-alpha.1
Browse files Browse the repository at this point in the history
添加潜影盒快速拆包
为一些逻辑增加 isclient 判断
  • Loading branch information
plusls committed Jan 5, 2021
1 parent a370a23 commit 6eb41fc
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 3 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

跟同 Minecraft 版本的 carpet mod 一起使用即可。尽可能地使用较新的 carpet mod

## 依赖

fabric-api >= 0.28

## 索引

### [规则](#规则列表)
Expand Down Expand Up @@ -63,6 +67,15 @@ Carpet 默认实现的潜影盒可堆叠只能让潜影盒在地面上堆叠,
- 参考选项: `true`, `false`
- 分类: `PCA`, `feature`

### 潜影盒快速拆包 (shulkerBoxQuickUnpack)

物品状态下的潜影盒在被摧毁时,盒中的物品会自动掉落,来自 1.17

- 类型: `boolean`
- 默认值: `false`
- 参考选项: `true`, `false`
- 分类: `PCA`, `feature`

### PCA调试模式 (pcaDebug)

开启后会打印调试信息
Expand Down
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.1-alpha.2
mod_version = 0.1.2-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 @@ -60,6 +60,12 @@ public class PcaSettings {
)
public static boolean shulkerRenewable = false;

@Rule(
desc = "shulker box items will now drop their items when destroyed. From 1.17",
category = {PCA, RuleCategory.FEATURE, RuleCategory.EXPERIMENTAL}
)
public static boolean shulkerBoxQuickUnpack = false;

// debug
@Rule(
desc = "pcaDebug mode",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.plusls.carpet.mixin.rule.shulkerBoxQuickUnpack;

import com.plusls.carpet.PcaSettings;
import net.minecraft.block.ShulkerBoxBlock;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
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;

import java.util.stream.Stream;

@Mixin(ItemEntity.class)
public abstract class MixinItemEntity extends Entity {

public MixinItemEntity(EntityType<?> type, World world) {
super(type, world);
}

@Shadow
public abstract ItemStack getStack();

@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;
}
if (!PcaSettings.shulkerBoxQuickUnpack) {
return;
}
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));
}
}
}

public void dropItems(Stream<ItemStack> stream) {
if (this.world.isClient())
return;
stream.forEach(itemStack -> this.world.spawnEntity(new ItemEntity(this.world, this.getX(), this.getY(), this.getZ(), itemStack)));
}
}
7 changes: 6 additions & 1 deletion src/main/java/com/plusls/carpet/network/PcaSyncProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ private static void syncEntityHandler(MinecraftServer server, ServerPlayerEntity
}

public static boolean syncEntityToClient(@NotNull Entity entity) {
if (entity.getEntityWorld().isClient()) {
return false;
}
lock.lock();
Set<ServerPlayerEntity> playerList = getWatchPlayerList(entity);
boolean ret = false;
Expand All @@ -227,7 +230,9 @@ public static boolean syncBlockEntityToClient(@NotNull BlockEntity blockEntity)
BlockPos pos = blockEntity.getPos();
// 在生成世界时可能会产生空指针
if (world != null) {

if (world.isClient()) {
return false;
}
BlockState blockState = world.getBlockState(pos);
lock.lock();
Set<ServerPlayerEntity> playerList = getWatchPlayerList(world, blockEntity.getPos());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"rule.emptyShulkerBoxStackInInventory.extra.1": "需要开启 emptyShulkerBoxStack 该功能才能生效",

"rule.shulkerRenewable.name": "潜影贝可再生",
"rule.shulkerRenewable.desc": "潜影贝可再生 来自 1.17",
"rule.shulkerRenewable.desc": "潜影贝可再生,来自 1.17",

"rule.shulkerBoxQuickUnpack.name": "潜影盒快速拆包",
"rule.shulkerBoxQuickUnpack.desc": "物品状态下的潜影盒在被摧毁时,盒中的物品会自动掉落,来自 1.17",

"rule.pcaDebug.name": "PCA调试模式",
"rule.pcaDebug.desc": "打印更多调试信息"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plusls_carpet_addition_mod.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinCrashReport",
"rule.shulkerBoxQuickUnpack.MixinItemEntity",
"rule.emptyShulkerBoxStack.MixinItemStack",
"rule.pcaSyncProtocol.block.MixinAbstractFurnaceBlockEntity",
"rule.pcaSyncProtocol.block.MixinBarrelBlockEntity",
Expand Down

0 comments on commit 6eb41fc

Please sign in to comment.