Skip to content

Commit

Permalink
use Container providing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed Jan 8, 2017
1 parent 70692cb commit 66a4365
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Expand Up @@ -44,6 +44,7 @@
import org.spongepowered.api.item.inventory.property.InventoryTitle;
import org.spongepowered.api.text.TranslatableText;
import org.spongepowered.api.text.serializer.TextSerializers;
import org.spongepowered.common.item.inventory.property.ContainerProperty;
import org.spongepowered.common.item.inventory.property.GuiIDProperty;

import java.util.HashSet;
Expand Down Expand Up @@ -139,6 +140,13 @@ public Container createContainer(InventoryPlayer playerInventory, EntityPlayer p
// TODO custom container including filters and other slot stuff
this.viewers.add(playerIn);

// Container provided by archetype?
Optional<ContainerProperty> cp = this.archetype.getProperty(ContainerProperty.class, ContainerProperty.class.getSimpleName().toLowerCase());
if (cp.isPresent()) {
return cp.get().getValue().provide(this, playerIn);
}

// Fallback to best guess
return new CustomContainer(playerIn.inventory, this);
}

Expand Down
Expand Up @@ -26,8 +26,8 @@

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import org.spongepowered.api.data.Property;
import org.spongepowered.api.item.inventory.Inventory;
import org.spongepowered.api.item.inventory.property.AbstractInventoryProperty;

/**
Expand All @@ -40,7 +40,7 @@ public ContainerProperty(ContainerProvider value) {
}

public interface ContainerProvider {
Container provide(Inventory inventory, EntityPlayer player);
Container provide(IInventory inventory, EntityPlayer player);
}

@Override
Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.spongepowered.common.item.inventory.archetype.SlotArchetype;
import org.spongepowered.common.item.inventory.archetype.SpongeInventoryArchetypeBuilder;
import org.spongepowered.common.item.inventory.custom.CustomInventory;
import org.spongepowered.common.item.inventory.property.ContainerProperty;
import org.spongepowered.common.item.inventory.property.GuiIDProperty;
import org.spongepowered.common.registry.SpongeAdditionalCatalogRegistryModule;
import org.spongepowered.common.text.translation.SpongeTranslation;
Expand Down Expand Up @@ -156,6 +157,7 @@ public void registerDefaults() {
.with(MENU_GRID)
.property(InventoryTitle.of(Text.of(new SpongeTranslation("container.chest"))))
.property(new GuiIDProperty("minecraft:chest"))
.property(new ContainerProperty((inventory, player) -> new ContainerChest(player.inventory, inventory, player)))
.build("minecraft:chest", "Chest");

DOUBLE_CHEST = builder.reset()
Expand All @@ -164,6 +166,7 @@ public void registerDefaults() {
.property(new InventoryDimension(9, 6))
.property(InventoryTitle.of(Text.of(new SpongeTranslation("container.chestDouble"))))
.property(new GuiIDProperty("minecraft:chest"))
.property(new ContainerProperty((inventory, player) -> new ContainerChest(player.inventory, inventory, player)))
.build("minecraft:double_chest", "DoubleChest");

FURNACE = builder.reset()
Expand All @@ -184,13 +187,15 @@ public void registerDefaults() {
.property(new InventoryTitle(Text.of(new SpongeTranslation("container.furnace"))))
.property(new InventoryDimension(3, 1))
.property(new GuiIDProperty("minecraft:furnace"))
.property(new ContainerProperty((inventory, player) -> new ContainerFurnace(player.inventory, inventory)))
.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("minecraft:dispenser"))
.property(new ContainerProperty((inventory, player) -> new ContainerDispenser(player.inventory, inventory)))
.build("minecraft:dispenser", "Dispenser");

WORKBENCH = builder.reset()
Expand All @@ -201,27 +206,34 @@ public void registerDefaults() {
.with(SLOT)
.property(InventoryTitle.of(Text.of(new SpongeTranslation("container.crafting"))))
.property(new GuiIDProperty("minecraft:crafting_table"))
.property(new ContainerProperty((inventory, player) -> {
return new ContainerWorkbench(player.inventory, player.getEntityWorld(), player.getPosition());
// TODO inventory (craftMatrix;craftResult)
}))
.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("minecraft:brewing_stand"))
.property(new ContainerProperty((inventory, player) -> new ContainerBrewingStand(player.inventory, inventory)))
.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("minecraft:hopper"))
.property(new ContainerProperty((inventory, player) -> new ContainerHopper(player.inventory, inventory, player)))
.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("minecraft:beacon"))
.property(new ContainerProperty((inventory, player) -> new ContainerBeacon(player.inventory, inventory)))
.build("minecraft:beacon", "Beacon");

ENCHANTING_TABLE = builder.reset()
Expand All @@ -230,6 +242,10 @@ public void registerDefaults() {
.property(new InventoryDimension(2, 1))
.property(InventoryTitle.of(Text.of(new SpongeTranslation("container.enchant"))))
.property(new GuiIDProperty("minecraft:enchanting_table"))
.property(new ContainerProperty((inventory, player) -> {
return new ContainerEnchantment(player.inventory, player.getEntityWorld(), player.getPosition());
// TODO inventory (tableInventory)
}))
.build("minecraft:enchanting_table", "EnchantingTable");

ANVIL = builder.reset()
Expand All @@ -239,6 +255,10 @@ public void registerDefaults() {
.property(new InventoryDimension(3, 1))
.property(InventoryTitle.of(Text.of(new SpongeTranslation("container.repair"))))
.property(new GuiIDProperty("minecraft:anvil"))
.property(new ContainerProperty((inventory, player) -> {
return new ContainerRepair(player.inventory, player.getEntityWorld(), player.getPosition(), player);
// TODO inventory (outputSlot;inputSlots)
}))
.build("minecraft:anvil", "Anvil");

VILLAGER = builder.reset()
Expand All @@ -247,13 +267,15 @@ public void registerDefaults() {
.with(SLOT)
.property(new InventoryDimension(3, 1))
.property(new GuiIDProperty("minecraft:villager"))
// TODO ContainerMerchant
.build("minecraft:villager", "Villager");

HORSE = builder.reset()
.with(SLOT)
.with(SLOT)
.property(new InventoryDimension(2, 1))
.property(new GuiIDProperty("EntityHorse")) // hardcoded openGuiHorseInventory
// TODO ContainerHorse
.build("minecraft:horse", "Horse");

HORSE_WITH_CHEST = builder.reset()
Expand All @@ -264,6 +286,7 @@ public void registerDefaults() {
.build("horse_grid", "HorseGrid"))
// TODO Size
.property(new GuiIDProperty("EntityHorse")) // hardcoded openGuiHorseInventory
// TODO ContainerHorse
.build("minecraft:horse_with_chest", "Horse with Chest");

CRAFTING = builder.reset()
Expand Down

0 comments on commit 66a4365

Please sign in to comment.