use of net.minecraft.screen.slot.Slot in project Rug by RubixDev.
the class PeekCommand method showInventory.
public static void showInventory(ServerPlayerEntity executingPlayer, ServerPlayerEntity targetPlayer) {
PlayerDataGui invScreen = new PlayerDataGui(ScreenHandlerType.GENERIC_9X5, executingPlayer, targetPlayer);
invScreen.setTitle(Text.of("Inventory of " + targetPlayer.getDisplayName().asString()));
for (int slot = 0; slot < executingPlayer.getInventory().size(); slot++) {
invScreen.setSlotRedirect(slot, new Slot(targetPlayer.getInventory(), slot, 0, 0));
}
invScreen.open();
}
use of net.minecraft.screen.slot.Slot in project WK by witches-kitchen.
the class WKScreenHandler method transferStack.
protected boolean transferStack(final ItemStack stackToShift, final int start, final int end) {
if (stackToShift.isEmpty()) {
return false;
}
int inCount = stackToShift.getCount();
// First lets see if we have the same item in a slot to merge with
for (int slotIndex = start; stackToShift.getCount() > 0 && slotIndex < end; slotIndex++) {
final Slot slot = this.slots.get(slotIndex);
final ItemStack stackInSlot = slot.getStack();
int maxCount = Math.min(stackToShift.getMaxCount(), slot.getMaxItemCount());
if (!stackToShift.isEmpty() && slot.canInsert(stackToShift)) {
if (ItemUtil.areItemsEqual(stackInSlot, stackToShift, true)) {
// Got 2 stacks that need merging
final int space = maxCount - stackInSlot.getCount();
if (space > 0) {
int transferAmount = Math.min(space, stackToShift.getCount());
stackInSlot.increment(transferAmount);
stackToShift.decrement(transferAmount);
}
}
}
}
// If not lets go find the next free slot to insert our remaining stack
for (int slotIndex = start; stackToShift.getCount() > 0 && slotIndex < end; slotIndex++) {
final Slot slot = this.slots.get(slotIndex);
final ItemStack stackInSlot = slot.getStack();
if (stackInSlot.isEmpty() && slot.canInsert(stackToShift)) {
int maxCount = Math.min(stackToShift.getMaxCount(), slot.getMaxItemCount());
int moveCount = Math.min(maxCount, stackToShift.getCount());
ItemStack moveStack = stackToShift.copy();
moveStack.setCount(moveCount);
slot.setStack(moveStack);
stackToShift.decrement(moveCount);
}
}
// If we moved some, but still have more left over lets try again
if (!stackToShift.isEmpty() && stackToShift.getCount() != inCount) {
transferStack(stackToShift, start, end);
}
return stackToShift.getCount() != inCount;
}
use of net.minecraft.screen.slot.Slot in project meteor-client by MeteorDevelopment.
the class InventorySorter method generateActions.
private void generateActions() {
// Find all slots and sort them
List<MySlot> slots = new ArrayList<>();
for (Slot slot : screen.getScreenHandler().slots) {
if (getInvPart(slot) == originInvPart)
slots.add(new MySlot(((ISlot) slot).getId(), slot.getStack()));
}
slots.sort(Comparator.comparingInt(value -> value.id));
// Generate actions
generateStackingActions(slots);
generateSortingActions(slots);
}
use of net.minecraft.screen.slot.Slot in project SinoCate by EverlastSino.
the class SaucepanScreenHandler method transferSlot.
@Override
public ItemStack transferSlot(PlayerEntity player, int invSlot) {
ItemStack newStack = ItemStack.EMPTY;
Slot slot = this.slots.get(invSlot);
if (slot.hasStack()) {
ItemStack originalStack = slot.getStack();
newStack = originalStack.copy();
if (invSlot < this.inventory.size()) {
if (!this.insertItem(originalStack, this.inventory.size(), this.slots.size(), true)) {
return ItemStack.EMPTY;
}
} else if (!this.insertItem(originalStack, 0, this.inventory.size(), false)) {
return ItemStack.EMPTY;
}
if (originalStack.isEmpty()) {
slot.setStack(ItemStack.EMPTY);
} else {
slot.markDirty();
}
}
return newStack;
}
use of net.minecraft.screen.slot.Slot in project Biome-Makeover by Lemonszz.
the class AltarScreenHandler method transferSlot.
@Override
public ItemStack transferSlot(PlayerEntity player, int index) {
ItemStack stackCopy = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasStack()) {
ItemStack moveStack = slot.getStack();
stackCopy = moveStack.copy();
if (index == 0) {
if (!this.insertItem(moveStack, 2, 38, true))
return ItemStack.EMPTY;
} else if (index == 1) {
if (!this.insertItem(moveStack, 2, 38, true))
return ItemStack.EMPTY;
} else if (moveStack.getItem().isIn(BMItems.CURSE_FUEL)) {
if (!this.insertItem(moveStack, 1, 2, true))
return ItemStack.EMPTY;
} else {
if (this.slots.get(0).hasStack() || !this.slots.get(0).canInsert(moveStack))
return ItemStack.EMPTY;
ItemStack finalStack = moveStack.copy();
finalStack.setCount(1);
moveStack.decrement(1);
this.slots.get(0).setStack(finalStack);
}
if (moveStack.isEmpty())
slot.setStack(ItemStack.EMPTY);
else
slot.markDirty();
if (moveStack.getCount() == stackCopy.getCount()) {
return ItemStack.EMPTY;
}
slot.onTakeItem(player, moveStack);
}
return stackCopy;
}
Aggregations