Search in sources :

Example 1 with BackpackContainer

use of net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer in project SophisticatedBackpacks by P3pp3rF1y.

the class ClientProxy method tryCallSort.

private static boolean tryCallSort(Screen gui) {
    Minecraft mc = Minecraft.getInstance();
    if (mc.player != null && mc.player.containerMenu instanceof BackpackContainer && gui instanceof BackpackScreen) {
        BackpackScreen screen = (BackpackScreen) gui;
        MouseHelper mh = mc.mouseHandler;
        double mouseX = mh.xpos() * mc.getWindow().getGuiScaledWidth() / mc.getWindow().getScreenWidth();
        double mouseY = mh.ypos() * mc.getWindow().getGuiScaledHeight() / mc.getWindow().getScreenHeight();
        BackpackContainer container = (BackpackContainer) mc.player.containerMenu;
        Slot selectedSlot = screen.findSlot(mouseX, mouseY);
        if (selectedSlot != null && !container.isPlayersInventorySlot(selectedSlot.index)) {
            container.sort();
            return true;
        }
    }
    return false;
}
Also used : BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) MouseHelper(net.minecraft.client.MouseHelper) Slot(net.minecraft.inventory.container.Slot) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) Minecraft(net.minecraft.client.Minecraft)

Example 2 with BackpackContainer

use of net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer in project SophisticatedBackpacks by P3pp3rF1y.

the class BackpackBlock method use.

@Override
public ActionResultType use(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult hit) {
    if (world.isClientSide) {
        return ActionResultType.SUCCESS;
    }
    ItemStack heldItem = player.getItemInHand(hand);
    if (player.isShiftKeyDown() && heldItem.isEmpty()) {
        putInPlayersHandAndRemove(state, world, pos, player, hand);
        return ActionResultType.SUCCESS;
    }
    if (!heldItem.isEmpty() && heldItem.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).isPresent()) {
        WorldHelper.getTile(world, pos, BackpackTileEntity.class).flatMap(te -> te.getBackpackWrapper().getFluidHandler()).ifPresent(backpackFluidHandler -> player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(playerInventory -> {
            FluidActionResult resultOfEmptying = FluidUtil.tryEmptyContainerAndStow(heldItem, backpackFluidHandler, playerInventory, FluidAttributes.BUCKET_VOLUME, player, true);
            if (resultOfEmptying.isSuccess()) {
                player.setItemInHand(hand, resultOfEmptying.getResult());
            } else {
                FluidActionResult resultOfFilling = FluidUtil.tryFillContainerAndStow(heldItem, backpackFluidHandler, playerInventory, FluidAttributes.BUCKET_VOLUME, player, true);
                if (resultOfFilling.isSuccess()) {
                    player.setItemInHand(hand, resultOfFilling.getResult());
                }
            }
        }));
        return ActionResultType.SUCCESS;
    }
    BackpackContext.Block backpackContext = new BackpackContext.Block(pos);
    NetworkHooks.openGui((ServerPlayerEntity) player, new SimpleNamedContainerProvider((w, p, pl) -> new BackpackContainer(w, pl, backpackContext), getBackpackDisplayName(world, pos)), backpackContext::toBuffer);
    return ActionResultType.SUCCESS;
}
Also used : FluidState(net.minecraft.fluid.FluidState) ServerWorld(net.minecraft.world.server.ServerWorld) BackpackContext(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContext) Explosion(net.minecraft.world.Explosion) IUpgradeRenderer(net.p3pp3rf1y.sophisticatedbackpacks.api.IUpgradeRenderer) Random(java.util.Random) Direction(net.minecraft.util.Direction) UpgradeRenderDataType(net.p3pp3rf1y.sophisticatedbackpacks.api.UpgradeRenderDataType) FluidAttributes(net.minecraftforge.fluids.FluidAttributes) IBlockReader(net.minecraft.world.IBlockReader) Block(net.minecraft.block.Block) InventoryHelper(net.p3pp3rf1y.sophisticatedbackpacks.util.InventoryHelper) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) EverlastingUpgradeItem(net.p3pp3rf1y.sophisticatedbackpacks.upgrades.everlasting.EverlastingUpgradeItem) BlockState(net.minecraft.block.BlockState) SoundCategory(net.minecraft.util.SoundCategory) Fluids(net.minecraft.fluid.Fluids) CapabilityBackpackWrapper(net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BooleanProperty(net.minecraft.state.BooleanProperty) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) Vector3d(net.minecraft.util.math.vector.Vector3d) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) DirectionProperty(net.minecraft.state.DirectionProperty) ActionResultType(net.minecraft.util.ActionResultType) IBackpackWrapper(net.p3pp3rf1y.sophisticatedbackpacks.api.IBackpackWrapper) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FluidUtil(net.minecraftforge.fluids.FluidUtil) BackpackRenderInfo(net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.BackpackRenderInfo) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) IWorld(net.minecraft.world.IWorld) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ITextComponent(net.minecraft.util.text.ITextComponent) WorldHelper(net.p3pp3rf1y.sophisticatedbackpacks.util.WorldHelper) ItemStack(net.minecraft.item.ItemStack) StateContainer(net.minecraft.state.StateContainer) Minecraft(net.minecraft.client.Minecraft) NetworkHooks(net.minecraftforge.fml.network.NetworkHooks) ISelectionContext(net.minecraft.util.math.shapes.ISelectionContext) Hand(net.minecraft.util.Hand) IWaterLoggable(net.minecraft.block.IWaterLoggable) UpgradeRenderRegistry(net.p3pp3rf1y.sophisticatedbackpacks.client.render.UpgradeRenderRegistry) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) Nullable(javax.annotation.Nullable) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) SoundType(net.minecraft.block.SoundType) Entity(net.minecraft.entity.Entity) WATERLOGGED(net.minecraft.state.properties.BlockStateProperties.WATERLOGGED) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) PushReaction(net.minecraft.block.material.PushReaction) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) ModItems(net.p3pp3rf1y.sophisticatedbackpacks.init.ModItems) IUpgradeRenderData(net.p3pp3rf1y.sophisticatedbackpacks.api.IUpgradeRenderData) Material(net.minecraft.block.material.Material) MathHelper(net.minecraft.util.math.MathHelper) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) TileEntity(net.minecraft.tileentity.TileEntity) SimpleNamedContainerProvider(net.minecraft.inventory.container.SimpleNamedContainerProvider) ItemEntity(net.minecraft.entity.item.ItemEntity) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) ServerBackpackSoundHandler(net.p3pp3rf1y.sophisticatedbackpacks.upgrades.jukebox.ServerBackpackSoundHandler) BackpackContext(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContext) SimpleNamedContainerProvider(net.minecraft.inventory.container.SimpleNamedContainerProvider) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult)

Example 3 with BackpackContainer

use of net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer in project SophisticatedBackpacks by P3pp3rF1y.

the class TankClickMessage method handleMessage.

private static void handleMessage(@Nullable ServerPlayerEntity sender, TankClickMessage msg) {
    if (sender == null || !(sender.containerMenu instanceof BackpackContainer)) {
        return;
    }
    UpgradeContainerBase<?, ?> upgradeContainer = ((BackpackContainer) sender.containerMenu).getUpgradeContainers().get(msg.upgradeSlot);
    if (!(upgradeContainer instanceof TankUpgradeContainer)) {
        return;
    }
    TankUpgradeContainer tankContainer = (TankUpgradeContainer) upgradeContainer;
    ItemStack cursorStack = sender.inventory.getCarried();
    cursorStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY).ifPresent(fluidHandler -> {
        TankUpgradeWrapper tankWrapper = tankContainer.getUpgradeWrapper();
        FluidStack tankContents = tankWrapper.getContents();
        if (tankContents.isEmpty()) {
            drainHandler(sender, fluidHandler, tankWrapper);
        } else {
            if (!tankWrapper.fillHandler(fluidHandler, itemStackIn -> {
                sender.inventory.setCarried(itemStackIn);
                sender.connection.send(new SSetSlotPacket(-1, -1, sender.inventory.getCarried()));
            })) {
                drainHandler(sender, fluidHandler, tankWrapper);
            }
        }
    });
}
Also used : ItemStack(net.minecraft.item.ItemStack) SSetSlotPacket(net.minecraft.network.play.server.SSetSlotPacket) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) FluidStack(net.minecraftforge.fluids.FluidStack) UpgradeContainerBase(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.UpgradeContainerBase) Supplier(java.util.function.Supplier) PacketBuffer(net.minecraft.network.PacketBuffer) Nullable(javax.annotation.Nullable) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) SSetSlotPacket(net.minecraft.network.play.server.SSetSlotPacket) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with BackpackContainer

use of net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer in project SophisticatedBackpacks by P3pp3rF1y.

the class SBPPlugin method registerGuiHandlers.

@Override
public void registerGuiHandlers(IGuiHandlerRegistration registration) {
    registration.addGuiContainerHandler(BackpackScreen.class, new IGuiContainerHandler<BackpackScreen>() {

        @Override
        public List<Rectangle2d> getGuiExtraAreas(BackpackScreen gui) {
            List<Rectangle2d> ret = new ArrayList<>();
            gui.getUpgradeSlotsRectangle().ifPresent(ret::add);
            ret.addAll(gui.getUpgradeSettingsControl().getTabRectangles());
            gui.getSortButtonsRectangle().ifPresent(ret::add);
            return ret;
        }
    });
    registration.addGuiContainerHandler(SettingsScreen.class, new IGuiContainerHandler<SettingsScreen>() {

        @Override
        public List<Rectangle2d> getGuiExtraAreas(SettingsScreen gui) {
            return new ArrayList<>(gui.getSettingsTabControl().getTabRectangles());
        }
    });
    registration.addGhostIngredientHandler(BackpackScreen.class, new IGhostIngredientHandler<BackpackScreen>() {

        @Override
        public <I> List<Target<I>> getTargets(BackpackScreen screen, I i, boolean b) {
            List<Target<I>> targets = new ArrayList<>();
            if (!(i instanceof ItemStack)) {
                return targets;
            }
            ItemStack ghostStack = (ItemStack) i;
            BackpackContainer container = screen.getMenu();
            container.getOpenContainer().ifPresent(c -> c.getSlots().forEach(s -> {
                if (s instanceof IFilterSlot && s.mayPlace(ghostStack)) {
                    targets.add(new Target<I>() {

                        @Override
                        public Rectangle2d getArea() {
                            return new Rectangle2d(screen.getGuiLeft() + s.x, screen.getGuiTop() + s.y, 17, 17);
                        }

                        @Override
                        public void accept(I i) {
                            PacketHandler.sendToServer(new SetGhostSlotMessage(ghostStack, s.index));
                        }
                    });
                }
            }));
            return targets;
        }

        @Override
        public void onComplete() {
        // noop
        }
    });
}
Also used : IRecipeCatalystRegistration(mezz.jei.api.registration.IRecipeCatalystRegistration) SophisticatedBackpacks(net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks) IStackHelper(mezz.jei.api.helpers.IStackHelper) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) ArrayList(java.util.ArrayList) IModPlugin(mezz.jei.api.IModPlugin) ItemStack(net.minecraft.item.ItemStack) JeiPlugin(mezz.jei.api.JeiPlugin) IGhostIngredientHandler(mezz.jei.api.gui.handlers.IGhostIngredientHandler) IRecipeTransferRegistration(mezz.jei.api.registration.IRecipeTransferRegistration) IRecipeRegistration(mezz.jei.api.registration.IRecipeRegistration) IRecipeTransferHandlerHelper(mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper) SettingsScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.SettingsScreen) PacketHandler(net.p3pp3rf1y.sophisticatedbackpacks.network.PacketHandler) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) VanillaRecipeCategoryUid(mezz.jei.api.constants.VanillaRecipeCategoryUid) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) CapabilityBackpackWrapper(net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper) IGuiHandlerRegistration(mezz.jei.api.registration.IGuiHandlerRegistration) IGuiContainerHandler(mezz.jei.api.gui.handlers.IGuiContainerHandler) ModItems(net.p3pp3rf1y.sophisticatedbackpacks.init.ModItems) ISubtypeInterpreter(mezz.jei.api.ingredients.subtypes.ISubtypeInterpreter) List(java.util.List) IFilterSlot(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.IFilterSlot) ISubtypeRegistration(mezz.jei.api.registration.ISubtypeRegistration) ResourceLocation(net.minecraft.util.ResourceLocation) Rectangle2d(net.minecraft.client.renderer.Rectangle2d) IFilterSlot(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.IFilterSlot) BackpackScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen) BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) SettingsScreen(net.p3pp3rf1y.sophisticatedbackpacks.client.gui.SettingsScreen)

Example 5 with BackpackContainer

use of net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer in project SophisticatedBackpacks by P3pp3rF1y.

the class TransferMessage method handleMessage.

private static void handleMessage(@Nullable ServerPlayerEntity player, TransferMessage msg) {
    if (player == null || !(player.containerMenu instanceof BackpackContainer)) {
        return;
    }
    BackpackContainer backpackContainer = (BackpackContainer) player.containerMenu;
    BackpackInventoryHandler backpackInventory = backpackContainer.getBackpackWrapper().getInventoryHandler();
    if (msg.isRestock) {
        player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(playerInv -> {
            InventoryHelper.transfer(backpackInventory, playerInv, s -> {
            });
        });
    } else {
        PlayerInventory inv = player.inventory;
        for (int i = PlayerInventory.getSelectionSize(); i < inv.items.size(); i++) {
            ItemStack stackAt = inv.getItem(i);
            if (!stackAt.isEmpty()) {
                inv.setItem(i, backpackInventory.insertItem(stackAt, false));
            }
        }
    }
}
Also used : BackpackContainer(net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer) BackpackInventoryHandler(net.p3pp3rf1y.sophisticatedbackpacks.backpack.wrapper.BackpackInventoryHandler) PlayerInventory(net.minecraft.entity.player.PlayerInventory) ItemStack(net.minecraft.item.ItemStack)

Aggregations

BackpackContainer (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContainer)15 ItemStack (net.minecraft.item.ItemStack)10 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)5 Nullable (javax.annotation.Nullable)4 Supplier (java.util.function.Supplier)3 ClientPlayerEntity (net.minecraft.client.entity.player.ClientPlayerEntity)3 Slot (net.minecraft.inventory.container.Slot)3 BackpackContext (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackContext)3 List (java.util.List)2 BlockState (net.minecraft.block.BlockState)2 SoundType (net.minecraft.block.SoundType)2 Minecraft (net.minecraft.client.Minecraft)2 PlayerContainer (net.minecraft.inventory.container.PlayerContainer)2 SimpleNamedContainerProvider (net.minecraft.inventory.container.SimpleNamedContainerProvider)2 CapabilityFluidHandler (net.minecraftforge.fluids.capability.CapabilityFluidHandler)2 NetworkHooks (net.minecraftforge.fml.network.NetworkHooks)2 SophisticatedBackpacks (net.p3pp3rf1y.sophisticatedbackpacks.SophisticatedBackpacks)2 CapabilityBackpackWrapper (net.p3pp3rf1y.sophisticatedbackpacks.api.CapabilityBackpackWrapper)2 BackpackScreen (net.p3pp3rf1y.sophisticatedbackpacks.client.gui.BackpackScreen)2 IContextAwareContainer (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.IContextAwareContainer)2