Skip to content

Commit

Permalink
修改背包物品掉落逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Oct 3, 2024
1 parent f30aaa1 commit 4460c93
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.tartaricacid.touhoulittlemaid.api.backpack;

import com.github.tartaricacid.touhoulittlemaid.entity.backpack.BackpackManager;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityTombstone;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.item.BackpackLevel;
Expand Down Expand Up @@ -60,4 +61,11 @@ public IBackpackData getBackpackData(EntityMaid maid) {
protected final void dropAllItems(EntityMaid maid) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.EMPTY_CAPACITY);
}

protected final void dropRelativeItems(ItemStack stack, EntityMaid maid) {
BackpackManager.findBackpack(stack).ifPresentOrElse(backpack -> {
int startIndex = backpack.getAvailableMaxContainerIndex();
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), startIndex);
}, () -> this.dropAllItems(maid));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.github.tartaricacid.touhoulittlemaid.inventory.container.AbstractMaidContainer;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.backpack.BigBackpackContainer;
import com.github.tartaricacid.touhoulittlemaid.item.BackpackLevel;
import com.github.tartaricacid.touhoulittlemaid.util.ItemsUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.EntityModelSet;
Expand All @@ -34,19 +33,7 @@ public void onPutOn(ItemStack stack, Player player, EntityMaid maid) {

@Override
public void onTakeOff(ItemStack stack, Player player, EntityMaid maid) {
Item item = stack.getItem();
if (item == InitItems.MAID_BACKPACK_SMALL.get()) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.SMALL_CAPACITY);
return;
}
if (item == InitItems.MAID_BACKPACK_MIDDLE.get()) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.MIDDLE_CAPACITY);
return;
}
if (item == InitItems.MAID_BACKPACK_BIG.get()) {
return;
}
this.dropAllItems(maid);
dropRelativeItems(stack, maid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.github.tartaricacid.touhoulittlemaid.inventory.container.AbstractMaidContainer;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.backpack.CraftingTableBackpackContainer;
import com.github.tartaricacid.touhoulittlemaid.item.BackpackLevel;
import com.github.tartaricacid.touhoulittlemaid.util.ItemsUtil;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.EntityModel;
import net.minecraft.client.model.geom.EntityModelSet;
Expand All @@ -33,15 +32,7 @@ public void onPutOn(ItemStack stack, Player player, EntityMaid maid) {

@Override
public void onTakeOff(ItemStack stack, Player player, EntityMaid maid) {
Item item = stack.getItem();
if (item == InitItems.MAID_BACKPACK_SMALL.get()) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.SMALL_CAPACITY);
return;
}
if (item == InitItems.MAID_BACKPACK_MIDDLE.get() || item == InitItems.MAID_BACKPACK_BIG.get()) {
return;
}
this.dropAllItems(maid);
dropRelativeItems(stack, maid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public ResourceLocation getBackpackTexture() {
}

@OnlyIn(Dist.CLIENT)
@Override
public void offsetBackpackItem(PoseStack poseStack) {
poseStack.translate(0, 0.625, 0.2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,7 @@ public void onTakeOff(ItemStack stack, Player player, EntityMaid maid) {
InvWrapper inv = new InvWrapper(furnaceBackpackData);
ItemsUtil.dropEntityItems(maid, inv);
}

Item item = stack.getItem();
if (item == InitItems.MAID_BACKPACK_SMALL.get()) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.SMALL_CAPACITY);
return;
}
if (item == InitItems.MAID_BACKPACK_MIDDLE.get() || item == InitItems.MAID_BACKPACK_BIG.get()) {
return;
}
this.dropAllItems(maid);
dropRelativeItems(stack, maid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,7 @@ public void onPutOn(ItemStack stack, Player player, EntityMaid maid) {

@Override
public void onTakeOff(ItemStack stack, Player player, EntityMaid maid) {
Item item = stack.getItem();
if (item == InitItems.MAID_BACKPACK_SMALL.get()) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.SMALL_CAPACITY);
return;
}
if (item == InitItems.MAID_BACKPACK_MIDDLE.get() || item == InitItems.MAID_BACKPACK_BIG.get()) {
return;
}
this.dropAllItems(maid);
dropRelativeItems(stack, maid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ public void onPutOn(ItemStack stack, Player player, EntityMaid maid) {

@Override
public void onTakeOff(ItemStack stack, Player player, EntityMaid maid) {
Item item = stack.getItem();
if (item == InitItems.MAID_BACKPACK_SMALL.get() || item == InitItems.MAID_BACKPACK_MIDDLE.get() || item == InitItems.MAID_BACKPACK_BIG.get()) {
return;
}
this.dropAllItems(maid);
dropRelativeItems(stack, maid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,7 @@ public void onTakeOff(ItemStack stack, Player player, EntityMaid maid) {
InvWrapper inv = new InvWrapper(tankBackpackData);
ItemsUtil.dropEntityItems(maid, inv);
}

Item item = stack.getItem();
if (item == InitItems.MAID_BACKPACK_SMALL.get()) {
ItemsUtil.dropEntityItems(maid, maid.getMaidInv(), BackpackLevel.SMALL_CAPACITY);
return;
}
if (item == InitItems.MAID_BACKPACK_MIDDLE.get() || item == InitItems.MAID_BACKPACK_BIG.get()) {
return;
}
this.dropAllItems(maid);
dropRelativeItems(stack, maid);
}

@Override
Expand Down

0 comments on commit 4460c93

Please sign in to comment.