generated from FabricMC/fabric-example-mod
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加潜影盒快速拆包 为一些逻辑增加 isclient 判断
- Loading branch information
Showing
7 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/com/plusls/carpet/mixin/rule/shulkerBoxQuickUnpack/MixinItemEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters