-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from cdqtzrc/fabric/1.20.x
更好的假人背包快速移动物品
- Loading branch information
Showing
4 changed files
with
75 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
package dev.dubhe.gugle.carpet.mixin; | ||
|
||
import carpet.fakes.ServerPlayerInterface; | ||
import carpet.helpers.EntityPlayerActionPack; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import java.util.Map; | ||
|
||
@Mixin(EntityPlayerActionPack.class) | ||
public interface APAccessor { | ||
@Accessor | ||
@Accessor(remap = false) | ||
Map<EntityPlayerActionPack.ActionType, EntityPlayerActionPack.Action> getActions(); | ||
|
||
@Accessor | ||
@Accessor(remap = false) | ||
boolean getSneaking(); | ||
|
||
@Accessor | ||
@Accessor(remap = false) | ||
boolean getSprinting(); | ||
|
||
@Accessor | ||
@Accessor(remap = false) | ||
float getForward(); | ||
|
||
@Accessor | ||
@Accessor(remap = false) | ||
float getStrafing(); | ||
} |
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
67 changes: 67 additions & 0 deletions
67
src/main/java/dev/dubhe/gugle/carpet/tools/FakePlayerInventoryMenu.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,67 @@ | ||
package dev.dubhe.gugle.carpet.tools; | ||
|
||
import net.minecraft.world.Container; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.ChestMenu; | ||
import net.minecraft.world.inventory.MenuType; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ArmorItem; | ||
import net.minecraft.world.item.ItemStack; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class FakePlayerInventoryMenu extends ChestMenu { | ||
public FakePlayerInventoryMenu(int i, Inventory inventory, Container container) { | ||
super(MenuType.GENERIC_9x6, i, inventory, container, 6); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack quickMoveStack(@NotNull Player player, int slotIndex) { | ||
ItemStack remainingItem = ItemStack.EMPTY; | ||
Slot slot = this.slots.get(slotIndex); | ||
if (slot.hasItem()) { | ||
ItemStack slotStack = slot.getItem(); | ||
remainingItem = slotStack.copy(); | ||
if (slotIndex < 54) { | ||
if (!this.moveItemStackTo(slotStack, 54, this.slots.size(), true)) { | ||
return ItemStack.EMPTY; | ||
} | ||
} else if (slotStack.getItem() instanceof ArmorItem armorItem) { | ||
// 如果是盔甲,移动的盔甲槽 | ||
int ordinal = armorItem.getType().ordinal(); | ||
if (moveToArmor(slotStack, ordinal) || moveToInventory(slotStack)) { | ||
return ItemStack.EMPTY; | ||
} | ||
} else if (slotStack.isEdible()) { | ||
// 如果是食物,移动到副手 | ||
if (moveToOffHand(slotStack) || (moveToInventory(slotStack))) { | ||
return ItemStack.EMPTY; | ||
} | ||
} else if (moveToInventory(slotStack)) { | ||
// 其它物品移动的物品栏中 | ||
return ItemStack.EMPTY; | ||
} | ||
if (slotStack.isEmpty()) { | ||
slot.setByPlayer(ItemStack.EMPTY); | ||
} else { | ||
slot.setChanged(); | ||
} | ||
} | ||
return remainingItem; | ||
} | ||
|
||
// 移动到副手 | ||
private boolean moveToOffHand(ItemStack slotStack) { | ||
return this.moveItemStackTo(slotStack, 7, 8, false); | ||
} | ||
|
||
// 移动到盔甲槽 | ||
private boolean moveToArmor(ItemStack slotStack, int ordinal) { | ||
return this.moveItemStackTo(slotStack, ordinal + 1, ordinal + 2, false); | ||
} | ||
|
||
// 将物品移动的物品栏 | ||
private boolean moveToInventory(ItemStack slotStack) { | ||
return !this.moveItemStackTo(slotStack, 18, 54, false); | ||
} | ||
} |