use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView 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.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.
the class AbstractBuilding method createBuildingView.
/**
* Create a AbstractBuilding View given it's saved NBTTagCompound.
*
* @param colony The owning colony.
* @param id Chunk coordinate of the block a view is created for.
* @param buf The network data.
* @return {@link AbstractBuildingView} created from reading the buf.
*/
@Nullable
public static AbstractBuildingView createBuildingView(final ColonyView colony, final BlockPos id, @NotNull final ByteBuf buf) {
@Nullable AbstractBuildingView view = null;
@Nullable Class<?> oclass = null;
try {
final int typeHash = buf.readInt();
oclass = classNameHashToViewClassMap.get(typeHash);
if (oclass != null) {
final Constructor<?> constructor = oclass.getDeclaredConstructor(ColonyView.class, BlockPos.class);
view = (AbstractBuildingView) constructor.newInstance(colony, id);
}
} catch (@NotNull NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException exception) {
Log.getLogger().error(exception);
}
if (view == null) {
Log.getLogger().warn("Unknown AbstractBuilding type, missing View subclass, or missing constructor of proper format.");
return null;
}
try {
view.deserialize(buf);
} catch (final IndexOutOfBoundsException ex) {
Log.getLogger().error(String.format("A AbstractBuilding View (%s) has thrown an exception during deserializing, its state cannot be restored. Report this to the mod author", oclass.getName()), ex);
return null;
}
return view;
}
use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.
the class AbstractWindowBuilding method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
// Or that we are on the correct page
if (switchView == null || switchView.getCurrentView().getID().equals(PAGE_ACTIONS)) {
final AbstractBuildingView buildingView = building.getColony().getBuilding(building.getID());
if (buttonPrevPage != null) {
buttonPrevPage.disable();
buttonPrevPage.hide();
}
if (title != null) {
title.setLabelText(LanguageHandler.format(getBuildingName()) + " " + buildingView.getBuildingLevel());
}
updateButtonBuild(buildingView);
updateButtonRepair(buildingView);
}
}
use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.
the class WindowCitizen method getOpenRequestsOfCitizenFromBuilding.
@SuppressWarnings(RAWTYPES)
private ImmutableList<IRequest> getOpenRequestsOfCitizenFromBuilding(final BlockPos buildingPos) {
final ColonyView colonyView = ColonyManager.getClosestColonyView(FMLClientHandler.instance().getWorldClient(), buildingPos);
if (colonyView == null) {
return ImmutableList.of();
}
final AbstractBuildingView building = colonyView.getBuilding(buildingPos);
if (building == null) {
return ImmutableList.of();
}
return building.getOpenRequests(citizen);
}
use of com.minecolonies.coremod.colony.buildings.views.AbstractBuildingView in project minecolonies by Minecolonies.
the class WindowHutBuilder method pullResourcesFromHut.
/**
* Retrieve resources from the building to display in GUI.
*/
private void pullResourcesFromHut() {
final AbstractBuildingView newView = builder.getColony().getBuilding(builder.getID());
if (newView instanceof BuildingBuilderView) {
final BuildingBuilderView updatedView = (BuildingBuilderView) newView;
final InventoryPlayer inventory = this.mc.player.inventory;
final boolean isCreative = this.mc.player.capabilities.isCreativeMode;
resources.clear();
resources.addAll(updatedView.getResources().values());
for (final BuildingBuilderResource resource : resources) {
final int amountToSet;
if (isCreative) {
amountToSet = resource.getAmount();
} else {
amountToSet = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), stack -> !ItemStackUtils.isEmpty(stack) && stack.isItemEqual(resource.getItemStack()));
}
resource.setPlayerAmount(amountToSet);
}
resources.sort(new BuildingBuilderResource.ResourceComparator());
}
}
Aggregations