Skip to content
vini2003 edited this page Jan 23, 2020 · 12 revisions

Setup:

Spinnery uses Loom 0.2.6-SNAPSHOT with v2 mappings!

To use them, in build.gradle:

plugins {
	id 'fabric-loom' version '0.2.6-SNAPSHOT'
}

It is necessary to specify :v2 after the Yarn version:

dependencies {
	mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
}

Spinnery itself is hosted on JitPack. As such, you must add it as a repository:

repositories {
	maven {
		name = "JitPack"
		url "https://jitpack.io"
	}
}

With that done, simply add the library as a dependency, checking the version on JitPack (74514c2b0b, at the time of writing):

dependencies {
	modCompile "com.github.vini2003:Spinnery:74514c2b0b"
	include "com.github.vini2003:Spinnery:74514c2b0b"
}

Example:

Create a class that extends BaseContainer:

package spinnery.container.common;

import net.minecraft.entity.player.PlayerInventory;

import spinnery.container.common.widget.WPanel;

public class TestContainer extends BaseContainer {
	public TestContainer(int synchronizationID, PlayerInventory newLinkedPlayerInventory) {
		super(synchronizationID, newLinkedPlayerInventory);
	}
}

Then, add a main panel to the container:

setLinkedPanel(new WPanel(x, y, z, sizeX, sizeY, this));

Afterwards, register the container on the server:

ContainerProviderRegistry.INSTANCE.registerFactory(ID, (syncId, id, player, buffer) -> new TestContainer(syncId, player.inventory))

As you may have realized, buffer is a PacketByteBuf which can be used to pass customized data to the container constructor. Once your TestContainer is registered, you can open it with:

ContainerProviderRegistry.INSTANCE.openContainer(ID, player, (buffer) -> {});

You may pass data to buffer with the lambda expression which we left empty in (buffer) -> {}. Before moving on, we must register our TestContainer to a screen so we can actually play with it. That's done in the client, with:

ScreenProviderRegistry.INSTANCE.registerFactory(ID, (syncId, identifier, player, buffer) -> new BaseScreen(ID, new TestContainer(syncId, player.inventory), player));

Given we don't need anything fancier than a BaseScreen, we register one to TestContainer.

Once that's done, congratulations, you have a working container and screen that can be summoned at any time!

Here's some example code so you have something to base yourself on:

import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.BasicInventory;
import net.minecraft.item.Items;
import net.minecraft.text.LiteralText;
import spinnery.common.BaseContainer;
import spinnery.widget.WButton;
import spinnery.widget.WDropdown;
import spinnery.widget.WDynamicText;
import spinnery.widget.WHorizontalSlider;
import spinnery.widget.WInterface;
import spinnery.widget.WList;
import spinnery.widget.WPosition;
import spinnery.widget.WSize;
import spinnery.widget.WSlot;
import spinnery.widget.WStaticText;
import spinnery.widget.WTabHolder;
import spinnery.widget.WToggle;
import spinnery.widget.WType;

public class TestContainer extends BaseContainer {
	public TestContainer(int synchronizationID, PlayerInventory newLinkedPlayerInventory) {
		super(synchronizationID, newLinkedPlayerInventory);

		BasicInventory basicInventory = new BasicInventory(16);

		getInventories().put(PLAYER_INVENTORY, newLinkedPlayerInventory);
		getInventories().put(1, basicInventory);

		// WInterface
		WInterface mainInterface = new WInterface(WPosition.of(WType.FREE, 0, 0, 0), WSize.of(170, 96), this);

		getInterfaces().add(mainInterface);

		mainInterface.center();
		mainInterface.setY(32);

		mainInterface.setOnAlign(() -> {
			mainInterface.center();
			mainInterface.setY(32);
		});
		// WInterface



		// WDropdown
		WDropdown dropdownA = new WDropdown(WPosition.of(WType.ANCHORED, 174, 0, 0, mainInterface), WSize.of(64, 16, 64, 154), mainInterface);

		WToggle toggleA = new WToggle(WPosition.of(WType.ANCHORED, 0, 0, 1, dropdownA), WSize.of(18, 9), mainInterface);

		dropdownA.add(toggleA);
		dropdownA.setLabel(new LiteralText("Dropdown"));
		// WDropdown



		// WList
		WList listA = new WList(WPosition.of(WType.ANCHORED, -70, 0, 1, mainInterface), WSize.of(64, 154), mainInterface);

		WToggle toggleB = new WToggle(WPosition.of(WType.ANCHORED, 0, 0, 1, listA), WSize.of(18, 9), mainInterface);

		listA.add(toggleB);
		listA.setLabel(new LiteralText("List"));
		// WList



		// WTabHolder
		WTabHolder tabHolderA = new WTabHolder(WPosition.of(WType.ANCHORED, 0, 100, 1, mainInterface), WSize.of(170, 64), mainInterface);

		WTabHolder.WTab tabA = tabHolderA.addTab(Items.EMERALD, new LiteralText("Tab A"));
		WTabHolder.WTab tabB = tabHolderA.addTab(Items.EMERALD, new LiteralText("Tab B"));
		// WTabHolder



		// WButton
		WButton buttonA = new WButton(WPosition.of(WType.ANCHORED, 8, 8, 1, mainInterface), WSize.of(48, 18), mainInterface);
		WButton buttonB = new WButton(WPosition.of(WType.ANCHORED, 8, 28, 1, mainInterface), WSize.of(27, 18), mainInterface);

		buttonA.setLabel(new LiteralText("Button A"));
		buttonB.setLabel(new LiteralText("Button B"));
		// WButton



		// WDynamicText
		WDynamicText dynamicTextA = new WDynamicText(WPosition.of(WType.ANCHORED, 8, 130, 0, mainInterface), WSize.of(156, 18), mainInterface);

		dynamicTextA.setLabel(new LiteralText("§oDynamicText A..."));

		tabA.add(dynamicTextA);
		// WDynamicText



		// WStaticText
		WStaticText staticTextA = new WStaticText(WPosition.of(WType.ANCHORED, 8, 74, 0, mainInterface), mainInterface, new LiteralText("StaticText A"));
		// WStaticText



		// WHorizontalSlider
		WHorizontalSlider horizontalSliderA = new WHorizontalSlider(WPosition.of(WType.ANCHORED, 8, 48, 0, mainInterface), WSize.of(48, 12), mainInterface, 9);
		// WHorizontalSlider



		// WSlot
		WSlot.addArray(WPosition.of(WType.ANCHORED, 90, 8, 0, mainInterface), WSize.of(18, 18), mainInterface, 0, 1, 4, 4);
		// WSlot


		
		mainInterface.add(dropdownA, listA, tabHolderA, buttonA, buttonB, staticTextA, horizontalSliderA);
	}
}

Notice that the TestContainer constructor was altered to take a BlockPos, meaning the registries were changed, and the call to open the container writes the BlockPos to buffer.

The end result?

Spinnery

Spinnery is licensed under the LGPL-3.0 license.

Clone this wiki locally