use of org.spongepowered.api.item.inventory.property.InventoryDimension in project SpongeCommon by SpongePowered.
the class InventoryArchetypeRegistryModule method registerDefaults.
@Override
public void registerDefaults() {
InventoryArchetype SLOT = new SlotArchetype(ImmutableMap.of(CustomInventory.INVENTORY_DIMENSION, new InventoryDimension(1, 1)));
InventoryArchetype MENU_ROW;
InventoryArchetype MENU_COLUMN;
InventoryArchetype MENU_GRID;
InventoryArchetype CHEST;
InventoryArchetype DOUBLE_CHEST;
InventoryArchetype FURNACE;
InventoryArchetype DISPENSER;
InventoryArchetype WORKBENCH;
InventoryArchetype BREWING_STAND;
InventoryArchetype HOPPER;
InventoryArchetype BEACON;
InventoryArchetype ANVIL;
InventoryArchetype ENCHANTING_TABLE;
InventoryArchetype VILLAGER;
InventoryArchetype HORSE;
InventoryArchetype HORSE_WITH_CHEST;
InventoryArchetype PLAYER;
InventoryArchetype CRAFTING;
InventoryArchetype UNKNOWN;
final SpongeInventoryArchetypeBuilder builder = new SpongeInventoryArchetypeBuilder();
for (int i = 0; i < 9; i++) {
builder.with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(SlotIndex.of(i)).build("minecraft:slot" + i, "Slot"));
}
MENU_ROW = builder.property(new InventoryDimension(9, 1)).build("sponge:menu_row", "Menu Row");
MENU_COLUMN = builder.property(new InventoryDimension(9, 1)).build("sponge:menu_column", "Menu Column");
MENU_GRID = builder.reset().with(MENU_ROW).with(MENU_ROW).with(MENU_ROW).property(new InventoryDimension(9, 3)).build("sponge:menu_grid", "Menu Grid");
CHEST = builder.reset().with(MENU_GRID).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.chest")))).property(new GuiIdProperty(GuiIds.CHEST)).container((i, p) -> new ContainerChest(p.inventory, i, p)).build("minecraft:chest", "Chest");
DOUBLE_CHEST = builder.reset().with(CHEST).property(new InventoryDimension(9, 6)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.chestDouble")))).property(new GuiIdProperty(GuiIds.CHEST)).container((i, p) -> new ContainerChest(p.inventory, i, p)).build("minecraft:double_chest", "DoubleChest");
FURNACE = builder.reset().with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new SlotIndex(0)).build("minecraft:furnace_input", "FurnaceInput")).with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new SlotIndex(1)).property(AcceptsItems.of()).build("minecraft:furnace_fuel", "FurnaceFuel")).with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new SlotIndex(2)).property(AcceptsItems.of()).build("minecraft:furnace_output", "FurnaceOutput")).property(new InventoryTitle(Text.of(new SpongeTranslation("container.furnace")))).property(new InventoryDimension(3, 1)).property(new GuiIdProperty(GuiIds.FURNACE)).container((i, p) -> new ContainerFurnace(p.inventory, i)).build("minecraft:furnace", "Furnace");
DISPENSER = builder.reset().with(MENU_GRID).property(new InventoryDimension(3, 3)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.dispenser")))).property(new GuiIdProperty(GuiIds.DISPENSER)).container((i, p) -> new ContainerDispenser(p.inventory, i)).build("minecraft:dispenser", "Dispenser");
WORKBENCH = builder.reset().with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(3, 3)).build("minecraft:workbench_grid", "Workbench Grid")).with(SLOT).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.crafting")))).property(new GuiIdProperty(GuiIds.CRAFTING_TABLE)).container((i, p) -> {
ContainerWorkbench container = new ContainerWorkbench(p.inventory, p.getEntityWorld(), p.getPosition());
// Pre-Fills the container input with the items from the inventory
for (int index = 0; index < container.craftMatrix.getSizeInventory(); index++) {
container.craftMatrix.setInventorySlotContents(index, i.getStackInSlot(index));
}
return container;
}).build("minecraft:workbench", "Workbench");
BREWING_STAND = builder.reset().with(MENU_ROW).property(new InventoryDimension(5, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.brewing")))).property(new GuiIdProperty(GuiIds.BREWING_STAND)).container((i, p) -> new ContainerBrewingStand(p.inventory, i)).build("minecraft:brewing_stand", "BrewingStand");
HOPPER = builder.reset().with(MENU_ROW).property(new InventoryDimension(5, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.hopper")))).property(new GuiIdProperty(GuiIds.HOPPER)).container((i, p) -> new ContainerHopper(p.inventory, i, p)).build("minecraft:hopper", "Hopper");
BEACON = builder.reset().with(SLOT).property(new InventoryDimension(1, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.beacon")))).property(new GuiIdProperty(GuiIds.BEACON)).container((i, p) -> new ContainerBeacon(p.inventory, i)).build("minecraft:beacon", "Beacon");
ENCHANTING_TABLE = builder.reset().with(SLOT).with(SLOT).property(new InventoryDimension(2, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.enchant")))).property(new GuiIdProperty(GuiIds.ENCHANTING_TABLE)).container((i, p) -> {
ContainerEnchantment container = new ContainerEnchantment(p.inventory, p.getEntityWorld(), p.getPosition());
// Pre-Fills the container with the items from the inventory
for (int index = 0; index < container.tableInventory.getSizeInventory(); index++) {
container.tableInventory.setInventorySlotContents(index, i.getStackInSlot(index));
}
return container;
}).build("minecraft:enchanting_table", "EnchantingTable");
ANVIL = builder.reset().with(SLOT).with(SLOT).with(SLOT).property(new InventoryDimension(3, 1)).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.repair")))).property(new GuiIdProperty(GuiIds.ANVIL)).container((i, p) -> {
ContainerRepair container = new ContainerRepair(p.inventory, p.getEntityWorld(), p.getPosition(), p);
// Pre-Fills the container input with the items from the inventory
for (int index = 0; index < container.inputSlots.getSizeInventory(); index++) {
container.inputSlots.setInventorySlotContents(index, i.getStackInSlot(index));
}
return container;
}).build("minecraft:anvil", "Anvil");
VILLAGER = builder.reset().with(SLOT).with(SLOT).with(SLOT).property(new InventoryDimension(3, 1)).property(new GuiIdProperty(GuiIds.VILLAGER)).container((i, p) -> {
if (i instanceof CarriedInventory && ((CarriedInventory) i).getCarrier().isPresent() && ((CarriedInventory) i).getCarrier().get() instanceof IMerchant) {
IMerchant merchant = ((IMerchant) ((CarriedInventory) i).getCarrier().get());
ContainerMerchant container = new ContainerMerchant(p.inventory, merchant, p.getEntityWorld());
// TODO Pre-Fill the Container?
return container;
}
throw new IllegalArgumentException("Cannot open merchant inventory without a merchant as Carrier");
}).build("minecraft:villager", "Villager");
HORSE = builder.reset().with(SLOT).with(SLOT).property(new InventoryDimension(2, 1)).property(// hardcoded openGuiHorseInventory
new GuiIdProperty(GuiIds.HORSE)).container((i, p) -> {
if (i instanceof CarriedInventory && ((CarriedInventory) i).getCarrier().isPresent() && ((CarriedInventory) i).getCarrier().get() instanceof AbstractHorse) {
AbstractHorse horse = ((AbstractHorse) ((CarriedInventory) i).getCarrier().get());
return new ContainerHorseInventory(p.inventory, i, horse, p);
}
throw new IllegalArgumentException("Cannot open horse inventory without a horse as Carrier");
}).build("minecraft:horse", "Horse");
HORSE_WITH_CHEST = builder.reset().with(HORSE).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(5, 3)).build("horse_grid", "HorseGrid")).property(// hardcoded openGuiHorseInventory
new GuiIdProperty(GuiIds.HORSE)).container((i, p) -> {
if (i instanceof CarriedInventory && ((CarriedInventory) i).getCarrier().isPresent() && ((CarriedInventory) i).getCarrier().get() instanceof AbstractHorse) {
AbstractHorse horse = ((AbstractHorse) ((CarriedInventory) i).getCarrier().get());
// TODO size
return new ContainerHorseInventory(p.inventory, i, horse, p);
}
throw new IllegalArgumentException("Cannot open horse inventory without a horse as Carrier");
}).build("minecraft:horse_with_chest", "Horse with Chest");
CRAFTING = builder.reset().with(SLOT).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(2, 2)).build("minecraft:crafting_grid", "Crafting Grid")).property(InventoryTitle.of(Text.of(new SpongeTranslation("container.crafting")))).build("minecraft:crafting", "Crafting");
PLAYER = builder.reset().with(CRAFTING).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(1, 4)).build("minecraft:armor", "Armor")).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(9, 3)).build("minecraft:player_main", "Player Main")).with(new SpongeInventoryArchetypeBuilder().from(MENU_GRID).property(new InventoryDimension(9, 1)).build("minecraft:player_hotbar", "Player Hotbar")).with(new SpongeInventoryArchetypeBuilder().from(SLOT).property(new InventoryDimension(1, 1)).build("minecraft:player_offhand", "Player Offhand")).build("minecraft:player", "Player");
UNKNOWN = builder.reset().build("minecraft:unknown", "UKNOWN");
registerAdditionalCatalog(SLOT);
registerAdditionalCatalog(MENU_ROW);
registerAdditionalCatalog(MENU_COLUMN);
registerAdditionalCatalog(MENU_GRID);
registerAdditionalCatalog(CHEST);
SpongeInventoryBuilder.registerInventory(TileEntityChest.class, CHEST);
SpongeInventoryBuilder.registerContainer(ContainerChest.class, CHEST);
registerAdditionalCatalog(DOUBLE_CHEST);
registerAdditionalCatalog(FURNACE);
SpongeInventoryBuilder.registerInventory(TileEntityFurnace.class, FURNACE);
SpongeInventoryBuilder.registerContainer(ContainerFurnace.class, FURNACE);
registerAdditionalCatalog(DISPENSER);
SpongeInventoryBuilder.registerInventory(TileEntityDispenser.class, DISPENSER);
SpongeInventoryBuilder.registerInventory(TileEntityDropper.class, DISPENSER);
SpongeInventoryBuilder.registerContainer(ContainerDispenser.class, DISPENSER);
registerAdditionalCatalog(WORKBENCH);
SpongeInventoryBuilder.registerContainer(ContainerWorkbench.class, WORKBENCH);
registerAdditionalCatalog(BREWING_STAND);
SpongeInventoryBuilder.registerInventory(TileEntityBrewingStand.class, BREWING_STAND);
SpongeInventoryBuilder.registerContainer(ContainerBrewingStand.class, BREWING_STAND);
registerAdditionalCatalog(HOPPER);
SpongeInventoryBuilder.registerInventory(TileEntityHopper.class, HOPPER);
SpongeInventoryBuilder.registerContainer(ContainerHopper.class, HOPPER);
registerAdditionalCatalog(BEACON);
SpongeInventoryBuilder.registerInventory(TileEntityBeacon.class, BEACON);
SpongeInventoryBuilder.registerContainer(ContainerBeacon.class, BEACON);
registerAdditionalCatalog(ENCHANTING_TABLE);
SpongeInventoryBuilder.registerContainer(ContainerEnchantment.class, ENCHANTING_TABLE);
registerAdditionalCatalog(ANVIL);
SpongeInventoryBuilder.registerContainer(ContainerRepair.class, ANVIL);
registerAdditionalCatalog(VILLAGER);
// TODO internal Villager Inventory? make Villager Carrier?
SpongeInventoryBuilder.registerContainer(ContainerMerchant.class, VILLAGER);
registerAdditionalCatalog(HORSE);
// TODO Horse IInventory? SpongeInventoryBuilder.registerInventory(EntityHorse.class, HORSE);
SpongeInventoryBuilder.registerContainer(ContainerHorseInventory.class, HORSE);
registerAdditionalCatalog(HORSE_WITH_CHEST);
registerAdditionalCatalog(CRAFTING);
registerAdditionalCatalog(PLAYER);
registerAdditionalCatalog(UNKNOWN);
// Helper Archetypes for Menu
InventoryArchetype MENU_ICON;
InventoryArchetype MENU_BUTTON;
InventoryArchetype MENU_CHECKBOX;
InventoryArchetype MENU_SPINNER;
MENU_ICON = builder.reset().with(SLOT).build("sponge:menu_icon", "Menu Icon");
MENU_BUTTON = builder.reset().with(MENU_ICON).build("sponge:menu_button", "Menu Button");
MENU_CHECKBOX = builder.reset().with(MENU_ICON).build("sponge:menu_checkbox", "Menu Checkbox");
MENU_SPINNER = builder.reset().with(MENU_ICON).build("sponge:menu_spinner", "Menu Spinner");
registerAdditionalCatalog(MENU_ICON);
registerAdditionalCatalog(MENU_BUTTON);
registerAdditionalCatalog(MENU_CHECKBOX);
registerAdditionalCatalog(MENU_SPINNER);
}
use of org.spongepowered.api.item.inventory.property.InventoryDimension in project SpongeCommon by SpongePowered.
the class CustomLens method addLensFor.
private int addLensFor(InventoryProperty<?, ?> size, int base, SlotProvider<IInventory, ItemStack> slots) {
Lens<IInventory, ItemStack> lens;
int slotCount;
if (size instanceof InventoryDimension) {
InventoryDimension dimension = ((InventoryDimension) size);
slotCount = dimension.getColumns() * dimension.getRows();
lens = new GridInventoryLensImpl(base, dimension.getColumns(), dimension.getRows(), dimension.getColumns(), slots);
} else if (size instanceof InventoryCapacity) {
InventoryCapacity capacity = ((InventoryCapacity) size);
slotCount = capacity.getValue();
lens = new OrderedInventoryLensImpl(base, capacity.getValue(), 1, slots);
} else {
throw new IllegalStateException("Unknown Inventory Size Property " + size.getClass().getName());
}
this.addSpanningChild(lens);
return slotCount;
}
use of org.spongepowered.api.item.inventory.property.InventoryDimension in project SpongeCommon by SpongePowered.
the class CustomInventory method getSlotCount.
private static int getSlotCount(InventoryArchetype archetype) {
Optional<InventoryDimension> dimension = archetype.getProperty(InventoryDimension.class, INVENTORY_DIMENSION);
if (dimension.isPresent()) {
return dimension.get().getColumns() * dimension.get().getRows();
}
Optional<InventoryCapacity> capacity = archetype.getProperty(InventoryCapacity.class, INVENTORY_CAPACITY);
if (capacity.isPresent()) {
return capacity.get().getValue();
}
int count = 0;
List<InventoryArchetype> childs = archetype.getChildArchetypes();
if (childs.isEmpty()) {
throw new IllegalArgumentException("Missing dimensions!");
}
for (InventoryArchetype childArchetype : childs) {
count += getSlotCount(childArchetype);
}
return count;
}
use of org.spongepowered.api.item.inventory.property.InventoryDimension in project modules-extra by CubeEngine.
the class MarketSignManager method executeShowInventory.
private void executeShowInventory(MarketSignData data, Player player, boolean isOwner, Location<World> loc) {
if (isInEditMode(loc)) {
return;
}
if (isOwner || (!data.isAdminOwner() && player.hasPermission(module.perms().EDIT_PLAYER_OTHER.getId()))) {
Inventory inventory = signInventories.get(data.getID());
ItemStack item = data.getItem();
if (inventory != null) {
i18n.send(ACTION_BAR, player, NEGATIVE, "This signs inventory is being edited right now!");
// TODO dont allow this return;
}
Integer size = data.getSize();
if (size == -1) {
size = 6;
}
Inventory inv = Inventory.builder().of(CHEST).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(getOwnerName(data)))).property(InventoryDimension.PROPERTY_NAME, new InventoryDimension(9, size)).property("identifiable", new Identifiable()).build(plugin);
signInventories.put(data.getID(), inv);
updateSignText(data, loc);
UUID key = UUID.randomUUID();
signInventoryStock.put(/*TODO getProperty is always empty MinecraftInventoryAdapter inv.getProperty(IdentifiableProperty.class,
"IdentifiableProperty").get().getValue()*/
key, Math.min(size * 9 * item.getMaxStackQuantity(), data.getStock()));
// TODO would be nice to just offer a 64+ item stack and split it up in inventory impl.
// Offer stock to signinventory -->
Integer stockToAdd = data.getStock();
int maxStackSize = item.getMaxStackQuantity();
while (stockToAdd > 0) {
ItemStack addAll = item.copy();
addAll.setQuantity(Math.min(stockToAdd, maxStackSize));
stockToAdd -= addAll.getQuantity();
inv.offer(addAll);
}
// --<
ItemStack copy = item.copy();
Runnable onClose = () -> {
signInventories.remove(data.getID());
if (data.getStock() != null) {
int newPageStock = inv.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).totalItems();
Integer totalStock = data.getStock();
Integer oldPageStock = signInventoryStock.get(key);
oldPageStock = oldPageStock == null ? 0 : oldPageStock;
data.setStock(totalStock - (oldPageStock - newPageStock));
loc.offer(data);
updateSignText(data, loc);
}
};
igf.prepareInv(inv, player.getUniqueId()).blockPutInAll().blockTakeOutAll().onClose(onClose);
if (data.getSignType() == SignType.BUY) {
igf.notBlockPutIn(item).notBlockTakeOut(item);
} else {
igf.notBlockTakeOut(item);
// TODO permission to allow putting items into sell sign
}
igf.submitInventory(Signmarket.class, true);
return;
}
if (player.hasPermission(module.perms().INTERACT_INVENTORY.getId()) || data.isOwner(player.getUniqueId())) {
String name = getOwnerName(data);
Inventory inventory = Inventory.builder().of(DISPENSER).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(name))).build(plugin);
// middle of dispenser
inventory.query(QueryOperationTypes.INVENTORY_PROPERTY.of(SlotPos.of(1, 1))).set(data.getItem().copy());
igf.prepareInv(inventory, player.getUniqueId()).blockPutInAll().blockTakeOutAll().submitInventory(Signmarket.class, true);
return;
}
i18n.send(ACTION_BAR, player, NEGATIVE, "You are not allowed to see the market signs inventories");
}
use of org.spongepowered.api.item.inventory.property.InventoryDimension in project LanternServer by LanternPowered.
the class LanternInventoryArchetypeBuilder method property.
@Override
public InventoryArchetype.Builder property(InventoryProperty<String, ?> property) {
checkNotNull(property, "property");
if (this.baseArchetype != null && this.baseArchetype.getBuilder() instanceof AbstractSlot.Builder) {
// Disallow modifying the slot capacity
if (property instanceof InventoryCapacity && ((InventoryCapacity) property).getValue() != 1) {
throw new IllegalArgumentException("It's not possible to modify the capacity of" + "a Slot through InventoryCapacity. This is fixed at 1.");
}
// Disallow modifying the slot dimensions
if (property instanceof InventoryDimension) {
final Vector2i dim = ((InventoryDimension) property).getValue();
if (dim.getX() != 1 || dim.getY() != 1) {
throw new IllegalArgumentException("It's not possible to modify the dimensions of" + "a Slot through InventoryDimension. This is fixed at 1;1.");
}
}
}
this.properties.put(property.getClass(), property);
return this;
}
Aggregations