mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Minecraft 1.21.5
Co-authored-by: Ven <[email protected]> Co-authored-by: Jonathing <[email protected]>
This commit is contained in:
548 files changed
+5432
-7867
No files matched your search
+8
-15
@@ -10,39 +10,32 @@ import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PlayerArmorInvWrapper extends RangedWrapper
|
||||
{
|
||||
public class PlayerEquipmentInvWrapper extends RangedWrapper {
|
||||
private final Inventory inventoryPlayer;
|
||||
|
||||
public PlayerArmorInvWrapper(Inventory inv)
|
||||
{
|
||||
super(new InvWrapper(inv), inv.items.size(), inv.items.size() + inv.armor.size());
|
||||
public PlayerEquipmentInvWrapper(Inventory inv) {
|
||||
super(new InvWrapper(inv), inv.getNonEquipmentItems().size(), inv.getNonEquipmentItems().size() + inv.getEquipment().size());
|
||||
inventoryPlayer = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate)
|
||||
{
|
||||
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
|
||||
EquipmentSlot equ = null;
|
||||
for (EquipmentSlot s : EquipmentSlot.values())
|
||||
{
|
||||
if (s.getType() == EquipmentSlot.Type.HUMANOID_ARMOR && s.getIndex() == slot)
|
||||
{
|
||||
for (EquipmentSlot s : EquipmentSlot.values()) {
|
||||
if (s.getType() == EquipmentSlot.Type.HUMANOID_ARMOR && s.getIndex() == slot) {
|
||||
equ = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// check if it's valid for the armor slot
|
||||
if (equ != null && slot < 4 && !stack.isEmpty() && stack.canEquip(equ, getInventoryPlayer().player))
|
||||
{
|
||||
return super.insertItem(slot, stack, simulate);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
public Inventory getInventoryPlayer()
|
||||
{
|
||||
public Inventory getInventoryPlayer() {
|
||||
return inventoryPlayer;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class PlayerInvWrapper extends CombinedInvWrapper
|
||||
{
|
||||
public PlayerInvWrapper(Inventory inv)
|
||||
{
|
||||
super(new PlayerMainInvWrapper(inv), new PlayerArmorInvWrapper(inv), new PlayerOffhandInvWrapper(inv));
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class PlayerMainInvWrapper extends RangedWrapper {
|
||||
private final Inventory inventoryPlayer;
|
||||
|
||||
public PlayerMainInvWrapper(Inventory inv) {
|
||||
super(new InvWrapper(inv), 0, inv.items.size());
|
||||
super(new InvWrapper(inv), 0, inv.getNonEquipmentItems().size());
|
||||
inventoryPlayer = inv;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.items.wrapper;
|
||||
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
|
||||
public class PlayerOffhandInvWrapper extends RangedWrapper
|
||||
{
|
||||
public PlayerOffhandInvWrapper(Inventory inv)
|
||||
{
|
||||
super(new InvWrapper(inv), inv.items.size() + inv.armor.size(),
|
||||
inv.items.size() + inv.armor.size() + inv.offhand.size());
|
||||
}
|
||||
}
|
||||
@@ -15,13 +15,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
* Shifting of slot indices is handled automatically for you.
|
||||
*/
|
||||
public class RangedWrapper implements IItemHandlerModifiable {
|
||||
|
||||
private final IItemHandlerModifiable compose;
|
||||
private final int minSlot;
|
||||
private final int maxSlot;
|
||||
|
||||
public RangedWrapper(IItemHandlerModifiable compose, int minSlot, int maxSlotExclusive)
|
||||
{
|
||||
public RangedWrapper(IItemHandlerModifiable compose, int minSlot, int maxSlotExclusive) {
|
||||
Preconditions.checkArgument(maxSlotExclusive > minSlot, "Max slot must be greater than min slot");
|
||||
this.compose = compose;
|
||||
this.minSlot = minSlot;
|
||||
@@ -29,81 +27,60 @@ public class RangedWrapper implements IItemHandlerModifiable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
public int getSlots() {
|
||||
return maxSlot - minSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ItemStack getStackInSlot(int slot)
|
||||
{
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if (checkSlot(slot))
|
||||
{
|
||||
return compose.getStackInSlot(slot + minSlot);
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate)
|
||||
{
|
||||
public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
|
||||
if (checkSlot(slot))
|
||||
{
|
||||
return compose.insertItem(slot + minSlot, stack, simulate);
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate)
|
||||
{
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (checkSlot(slot))
|
||||
{
|
||||
return compose.extractItem(slot + minSlot, amount, simulate);
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @NotNull ItemStack stack)
|
||||
{
|
||||
public void setStackInSlot(int slot, @NotNull ItemStack stack) {
|
||||
if (checkSlot(slot))
|
||||
{
|
||||
compose.setStackInSlot(slot + minSlot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit(int slot)
|
||||
{
|
||||
public int getSlotLimit(int slot) {
|
||||
if (checkSlot(slot))
|
||||
{
|
||||
return compose.getSlotLimit(slot + minSlot);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(int slot, @NotNull ItemStack stack)
|
||||
{
|
||||
public boolean isItemValid(int slot, @NotNull ItemStack stack) {
|
||||
if (checkSlot(slot))
|
||||
{
|
||||
return compose.isItemValid(slot + minSlot, stack);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean checkSlot(int localSlot)
|
||||
{
|
||||
private boolean checkSlot(int localSlot) {
|
||||
return localSlot + minSlot < maxSlot;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user