Skip to content

Basic Fundamentals

ZorT edited this page Feb 24, 2024 · 20 revisions

Welcome! I'm glad that you're interested in using Containr!

This page will teach you the basic concepts you will need when working with the library.
You will also find small snipets of code on this page, but please rather head to next page for real use of the library.

Element

An element is just a representation of object that can be clicked in the GUI.
Mostly it's just a object that renders item, but we have more ways of using elements, you can read about them later in this wiki.

5 Rules about elements:

  1. Elements are NOT items
  2. Elements can render items
  3. Elements can be clicked
  4. Elements can push other elements and take space even if they don't have item rendered
  5. Elements can be moved or changed it's state (You don't have to know exact location, no more hardcoded positions)

image

🟦 Element with currently rendered item
🟥 Element without currently rendered item

Container

A container is basically a space where you can put elements or other containers.
Our library has plenty of methods you can use for manipulating with container's content.

You can:

  • Append content
  • Set content to specific slots
  • Move it's content

The best representation of a container is GUI itself, as shown below:

image

Now, let's append a 2x2 container to our menu. Remember? GUI is also a container.

image

Code
gui.appendElement(element);
gui.appendContainer(container);

Now, let's append a 3 elements rendering grass to our 2x2 container.
As you can see, the elements has been added to the container and kept their position in the inner container. Also, the container has been aligned next to the one element we have here. We removed the empty element.

image

Code
for(int i = 0; i < 3; i++) {
    container.appendElement(element);
}

Now, let's add a 3x3 container and set a compass element to index 7 of the container. Also, we can set another 1x2 container to index 2.

Indexes are counted relatively to the container where the element is in.

image

Code
gui.appendContainer(container);
container.setElement(7, element);

And this is the result:

image

Now, let's move whole orange container with grass elements one slot to the bottom. It moves all it's content too!
This is the result:

image

Code
gui.moveAllByY(-1, OurContainerType.class); // Class is a filter, null moves all content.

If we use paged container and switch to next page, it becomes empty.
That's allright, because the content has been moved outside of the view!

image

Interesting, right?

Let's dig deeper and learn how to use the library!
Preparing the library