Search in sources :

Example 1 with WalletItem

use of io.github.lightman314.lightmanscurrency.items.WalletItem in project LightmansCurrency by Lightman314.

the class WalletMenu method init.

private void init() {
    NonNullList<Slot> newSlots = NonNullList.create();
    Item item = this.getWallet().getItem();
    if (item instanceof WalletItem)
        this.walletItem = (WalletItem) item;
    else
        this.walletItem = null;
    int yOffset = this.getVerticalOffset();
    this.coinInput = new SimpleContainer(WalletItem.InventorySize(this.walletItem));
    NonNullList<ItemStack> walletInventory = WalletItem.getWalletInventory(getWallet());
    for (int i = 0; i < this.coinInput.getContainerSize() && i < walletInventory.size(); i++) {
        this.coinInput.setItem(i, walletInventory.get(i));
    }
    // Wallet Slot
    WalletSlot walletSlot = new WalletSlot(this.walletInventory, 0, -22, 6 + yOffset).addListener(this::onWalletSlotChanged);
    if (this.walletStackIndex >= 0)
        walletSlot.setBlacklist(this.inventory, this.walletStackIndex);
    newSlots.add(walletSlot);
    // Should make the Player Inventory slot indexes constant regardless of the wallet state.
    for (int y = 0; y < 3; y++) {
        for (int x = 0; x < 9; x++) {
            int index = x + (y * 9) + 9;
            if (index == this.walletStackIndex)
                newSlots.add(new DisplaySlot(this.inventory, index, 8 + x * 18, 32 + (y + getRowCount()) * 18 + yOffset));
            else
                newSlots.add(new BlacklistSlot(this.inventory, index, 8 + x * 18, 32 + (y + getRowCount()) * 18 + yOffset, this.inventory, this.walletStackIndex));
        }
    }
    // Player hotbar
    for (int x = 0; x < 9; x++) {
        if (x == this.walletStackIndex)
            newSlots.add(new DisplaySlot(this.inventory, x, 8 + x * 18, 90 + getRowCount() * 18 + yOffset));
        else
            newSlots.add(new BlacklistSlot(this.inventory, x, 8 + x * 18, 90 + getRowCount() * 18 + yOffset, this.inventory, this.walletStackIndex));
    }
    // Coin Slots last as they may vary between client and server at times.
    for (int y = 0; (y * 9) < this.coinInput.getContainerSize(); y++) {
        for (int x = 0; x < 9 && (x + y * 9) < this.coinInput.getContainerSize(); x++) {
            newSlots.add(new CoinSlot(this.coinInput, x + y * 9, 8 + x * 18, 18 + y * 18 + yOffset).addListener(this::saveWalletContents));
        }
    }
    while (newSlots.size() < 37 + maxWalletSlots) {
        newSlots.add(new DisplaySlot(dummyInventory, 0, Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2));
    }
    this.autoConvert = WalletItem.getAutoConvert(getWallet());
    this.listeners.forEach(listener -> listener.onReload());
    // Reset the slots at the very end to prevent conflict with any for loops that may or may not be going on atm.
    this.setSlots(newSlots);
}
Also used : Item(net.minecraft.world.item.Item) WalletItem(io.github.lightman314.lightmanscurrency.items.WalletItem) WalletSlot(io.github.lightman314.lightmanscurrency.menus.slots.WalletSlot) DisplaySlot(io.github.lightman314.lightmanscurrency.menus.slots.DisplaySlot) WalletSlot(io.github.lightman314.lightmanscurrency.menus.slots.WalletSlot) BlacklistSlot(io.github.lightman314.lightmanscurrency.menus.slots.BlacklistSlot) CoinSlot(io.github.lightman314.lightmanscurrency.menus.slots.CoinSlot) DisplaySlot(io.github.lightman314.lightmanscurrency.menus.slots.DisplaySlot) Slot(net.minecraft.world.inventory.Slot) SimpleContainer(net.minecraft.world.SimpleContainer) CoinSlot(io.github.lightman314.lightmanscurrency.menus.slots.CoinSlot) ItemStack(net.minecraft.world.item.ItemStack) BlacklistSlot(io.github.lightman314.lightmanscurrency.menus.slots.BlacklistSlot) WalletItem(io.github.lightman314.lightmanscurrency.items.WalletItem)

Example 2 with WalletItem

use of io.github.lightman314.lightmanscurrency.items.WalletItem in project LightmansCurrency by Lightman314.

the class WalletMenu method quickMoveStack.

@Override
public ItemStack quickMoveStack(Player playerEntity, int index) {
    if (index + this.coinInput.getContainerSize() == this.walletStackIndex)
        return ItemStack.EMPTY;
    ItemStack clickedStack = ItemStack.EMPTY;
    Slot slot = this.slots.get(index);
    if (slot != null && slot.hasItem()) {
        ItemStack slotStack = slot.getItem();
        clickedStack = slotStack.copy();
        if (index == 0) {
            if (!this.moveItemStackTo(slotStack, 1, 37, false))
                return ItemStack.EMPTY;
        } else if (index < 37) {
            if (clickedStack.getItem() instanceof WalletItem) {
                if (!this.moveItemStackTo(slotStack, 0, 1, true))
                    return ItemStack.EMPTY;
            }
            if (!this.moveItemStackTo(slotStack, 37, this.slots.size(), false)) {
                return ItemStack.EMPTY;
            }
        } else if (!this.moveItemStackTo(slotStack, 1, 37, true)) {
            return ItemStack.EMPTY;
        }
        if (slotStack.isEmpty()) {
            slot.set(ItemStack.EMPTY);
        } else {
            slot.setChanged();
        }
    }
    return clickedStack;
}
Also used : WalletSlot(io.github.lightman314.lightmanscurrency.menus.slots.WalletSlot) BlacklistSlot(io.github.lightman314.lightmanscurrency.menus.slots.BlacklistSlot) CoinSlot(io.github.lightman314.lightmanscurrency.menus.slots.CoinSlot) DisplaySlot(io.github.lightman314.lightmanscurrency.menus.slots.DisplaySlot) Slot(net.minecraft.world.inventory.Slot) ItemStack(net.minecraft.world.item.ItemStack) WalletItem(io.github.lightman314.lightmanscurrency.items.WalletItem)

Example 3 with WalletItem

use of io.github.lightman314.lightmanscurrency.items.WalletItem in project LightmansCurrency by Lightman314.

the class WalletLayer method render.

@Override
public void render(PoseStack poseStack, MultiBufferSource bufferSource, int light, T entity, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
    ItemStack wallet = LightmansCurrency.getWalletStack(entity);
    if (wallet.getItem() instanceof WalletItem) {
        WalletItem walletItem = (WalletItem) wallet.getItem();
        this.model.prepareMobModel(entity, limbSwing, limbSwingAmount, partialTicks);
        this.model.setupAnim(entity, limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch);
        this.getParentModel().copyPropertiesTo(this.model);
        VertexConsumer vertexConsumer = ItemRenderer.getFoilBuffer(bufferSource, this.model.renderType(walletItem.getModelTexture()), false, wallet.hasFoil());
        this.model.renderToBuffer(poseStack, vertexConsumer, light, OverlayTexture.NO_OVERLAY, 1f, 1f, 1f, 1f);
    }
}
Also used : VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) ItemStack(net.minecraft.world.item.ItemStack) WalletItem(io.github.lightman314.lightmanscurrency.items.WalletItem)

Example 4 with WalletItem

use of io.github.lightman314.lightmanscurrency.items.WalletItem in project LightmansCurrency by Lightman314.

the class EventHandler method pickupItem.

// Pickup Event for wallet coin collection functionality
@SubscribeEvent
public static void pickupItem(EntityItemPickupEvent event) {
    ItemStack pickupItem = event.getItem().getItem();
    CoinData coinData = MoneyUtil.getData(pickupItem.getItem());
    if (coinData == null || coinData.isHidden)
        return;
    Player player = event.getPlayer();
    ItemStack coinStack = event.getItem().getItem();
    WalletMenu activeContainer = null;
    // Check if the open container is a wallet that is pickup capable
    if (player.containerMenu instanceof WalletMenu) {
        // CurrencyMod.LOGGER.info("Wallet Container was open. Adding to the wallet using this method.");
        WalletMenu container = (WalletMenu) player.containerMenu;
        if (container.canPickup())
            activeContainer = container;
    }
    boolean cancelEvent = false;
    // Get the currently equipped wallet
    ItemStack wallet = LightmansCurrency.getWalletStack(player);
    if (!wallet.isEmpty()) {
        WalletItem walletItem = (WalletItem) wallet.getItem();
        if (WalletItem.CanPickup(walletItem)) {
            cancelEvent = true;
            if (activeContainer != null && activeContainer.getWalletIndex() < 0) {
                coinStack = activeContainer.PickupCoins(coinStack);
            } else {
                coinStack = WalletItem.PickupCoin(wallet, coinStack);
            }
        }
    }
    if (event.isCancelable() && cancelEvent) {
        // CurrencyMod.LOGGER.info("Canceling the event as the pickup item is being handled by this event instead of vanilla means.");
        event.getItem().setItem(ItemStack.EMPTY);
        if (!coinStack.isEmpty()) {
            if (!player.addItem(coinStack)) {
                // Spawn the leftovers into the world
                ItemEntity itemEntity = new ItemEntity(player.level, player.getX(), player.getY(), player.getZ(), coinStack);
                itemEntity.setPickUpDelay(40);
                player.level.addFreshEntity(itemEntity);
            }
        }
        if (!player.level.isClientSide)
            LightmansCurrencyPacketHandler.instance.send(LightmansCurrencyPacketHandler.getTarget(player), new MessagePlayPickupSound());
        event.setCanceled(true);
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) ItemEntity(net.minecraft.world.entity.item.ItemEntity) CoinData(io.github.lightman314.lightmanscurrency.money.CoinData) MessagePlayPickupSound(io.github.lightman314.lightmanscurrency.network.message.wallet.MessagePlayPickupSound) ItemStack(net.minecraft.world.item.ItemStack) WalletMenu(io.github.lightman314.lightmanscurrency.menus.WalletMenu) WalletItem(io.github.lightman314.lightmanscurrency.items.WalletItem) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

WalletItem (io.github.lightman314.lightmanscurrency.items.WalletItem)4 ItemStack (net.minecraft.world.item.ItemStack)4 BlacklistSlot (io.github.lightman314.lightmanscurrency.menus.slots.BlacklistSlot)2 CoinSlot (io.github.lightman314.lightmanscurrency.menus.slots.CoinSlot)2 DisplaySlot (io.github.lightman314.lightmanscurrency.menus.slots.DisplaySlot)2 WalletSlot (io.github.lightman314.lightmanscurrency.menus.slots.WalletSlot)2 Slot (net.minecraft.world.inventory.Slot)2 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)1 WalletMenu (io.github.lightman314.lightmanscurrency.menus.WalletMenu)1 CoinData (io.github.lightman314.lightmanscurrency.money.CoinData)1 MessagePlayPickupSound (io.github.lightman314.lightmanscurrency.network.message.wallet.MessagePlayPickupSound)1 SimpleContainer (net.minecraft.world.SimpleContainer)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 Player (net.minecraft.world.entity.player.Player)1 Item (net.minecraft.world.item.Item)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1