use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class GuiHandler method getServerGuiElement.
@Override
public Object getServerGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
if (id == ID.DEFAULT.ordinal()) {
final BlockPos pos = new BlockPos(x, y, z);
final TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof ScarecrowTileEntity) {
return new ContainerField((ScarecrowTileEntity) tileEntity, player.inventory, world, pos);
} else if (tileEntity instanceof TileEntityRack) {
return new ContainerRack((TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), player.inventory);
} else {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, new BlockPos(x, y, z));
if (building != null) {
return new CraftingGUIBuilding(player.inventory, world);
}
return null;
}
} else if (id == ID.BUILDING_INVENTORY.ordinal()) {
final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
if (entity instanceof TileEntityColonyBuilding) {
final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
final Colony colony = ColonyManager.getClosestColony(world, tileEntityColonyBuilding.getPos());
return new ContainerMinecoloniesBuildingInventory(player.inventory, tileEntityColonyBuilding, colony.getID(), tileEntityColonyBuilding.getPos());
}
} else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
final Colony colony = ColonyManager.getColony(x);
final CitizenData citizen = colony.getCitizenManager().getCitizen(y);
final AbstractBuilding building = citizen.getWorkBuilding();
return new ContainerMinecoloniesCitizenInventory(player.inventory, citizen.getInventory(), colony.getID(), building == null ? null : building.getID(), citizen.getId());
}
return null;
}
use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class GuiHandler method getClientGuiElement.
@Override
public Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
if (id == ID.DEFAULT.ordinal()) {
final BlockPos pos = new BlockPos(x, y, z);
final TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof ScarecrowTileEntity) {
return new GuiField(player.inventory, (ScarecrowTileEntity) tileEntity, world, pos);
} else if (tileEntity instanceof TileEntityRack) {
return new GuiRack(player.inventory, (TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), world, pos);
} else {
@Nullable final AbstractBuildingView building = ColonyManager.getBuildingView(new BlockPos(x, y, z));
if (building instanceof AbstractBuildingWorker.View) {
return new WindowGuiCrafting(player.inventory, world, (AbstractBuildingWorker.View) building);
}
}
} else if (id == ID.BUILDING_INVENTORY.ordinal()) {
final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
if (entity instanceof TileEntityColonyBuilding) {
final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
return new GuiChest(player.inventory, tileEntityColonyBuilding);
}
} else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
final ColonyView view = ColonyManager.getColonyView(x);
final CitizenDataView citizenDataView = view.getCitizen(y);
return new GuiChest(player.inventory, citizenDataView.getInventory());
}
return null;
}
use of com.minecolonies.coremod.tileentities.TileEntityRack in project minecolonies by Minecolonies.
the class AbstractBuilding method getCapability.
@Nullable
@Override
public <T> T getCapability(@Nonnull final Capability<T> capability, @Nullable final EnumFacing facing) {
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && facing == null) {
final Set<ICapabilityProvider> providers = new HashSet<>();
// Add myself
providers.add(getTileEntity());
// Add additional containers
providers.addAll(getAdditionalCountainers().stream().map(getTileEntity().getWorld()::getTileEntity).filter(entity -> (entity instanceof TileEntityChest) || (entity instanceof TileEntityRack)).collect(Collectors.toSet()));
providers.removeIf(Objects::isNull);
// Map all providers to IItemHandlers.
final Set<IItemHandlerModifiable> modifiables = providers.stream().flatMap(provider -> InventoryUtils.getItemHandlersFromProvider(provider).stream()).filter(handler -> handler instanceof IItemHandlerModifiable).map(handler -> (IItemHandlerModifiable) handler).collect(Collectors.toSet());
return (T) new CombinedItemHandler(getSchematicName(), modifiables.toArray(new IItemHandlerModifiable[modifiables.size()]));
}
return null;
}
Aggregations