use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method getTotalAmount.
/**
* Check how much of a certain stuck is actually required.
*
* @param stack the stack to check.
* @return the new stack with the correct amount.
*/
@Override
@Nullable
public ItemStack getTotalAmount(@Nullable final ItemStack stack) {
final AbstractBuildingWorker buildingWorker = getOwnBuilding();
if (stack == null || stack.getItem() == null) {
return null;
}
final BuildingBuilderResource resource = ((BuildingBuilder) buildingWorker).getNeededResources().get(stack.getUnlocalizedName());
return resource == null ? stack : new ItemStack(resource.getItem(), resource.getAmount(), resource.getDamageValue());
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class BuildingBuilder method addNeededResource.
/**
* Add a new resource to the needed list.
*
* @param res the resource.
* @param amount the amount.
*/
public void addNeededResource(@Nullable final ItemStack res, final int amount) {
if (res.isEmpty() || amount == 0) {
return;
}
BuildingBuilderResource resource = this.neededResources.get(res.getUnlocalizedName());
if (resource == null) {
resource = new BuildingBuilderResource(res.getItem(), res.getItemDamage(), amount);
} else {
resource.setAmount(resource.getAmount() + amount);
}
this.neededResources.put(res.getUnlocalizedName(), resource);
this.markDirty();
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class BuildingBuilder method updateAvailableResources.
/**
* Update the available resources.
* <p>
* which are needed for the build and in the builder's chest or inventory
*/
private void updateAvailableResources() {
final EntityCitizen builder = getWorkerEntity();
InventoryCitizen builderInventory = null;
if (builder != null) {
builderInventory = builder.getInventoryCitizen();
}
for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
final BuildingBuilderResource resource = entry.getValue();
resource.setAvailable(0);
if (builderInventory != null) {
resource.addAvailable(InventoryUtils.getItemCountInItemHandler(new InvWrapper(builderInventory), resource.getItem(), resource.getDamageValue()));
}
final TileEntity chestInventory = this.getTileEntity();
if (chestInventory != null) {
resource.addAvailable(InventoryUtils.getItemCountInProvider(chestInventory, resource.getItem(), resource.getDamageValue()));
}
//Count in the additional chests as well
if (builder != null) {
for (final BlockPos pos : getAdditionalCountainers()) {
final TileEntity entity = builder.world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
resource.addAvailable(InventoryUtils.getItemCountInProvider(entity, resource.getItem(), resource.getDamageValue()));
}
}
}
}
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class BuildingBuilder method readFromNBT.
@Override
public void readFromNBT(@NotNull final NBTTagCompound compound) {
super.readFromNBT(compound);
final NBTTagList neededResTagList = compound.getTagList(TAG_RESOURCE_LIST, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < neededResTagList.tagCount(); ++i) {
final NBTTagCompound neededRes = neededResTagList.getCompoundTagAt(i);
final ItemStack stack = new ItemStack(neededRes);
final BuildingBuilderResource resource = new BuildingBuilderResource(stack.getItem(), stack.getItemDamage(), stack.getCount());
neededResources.put(stack.getUnlocalizedName(), resource);
}
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class WindowHutBuilder method updateResourcePane.
/**
* Update one row pad with its resource informations.
*
* @param index index in the list of resources.
* @param rowPane The Pane to use to display the information.
*/
private void updateResourcePane(final int index, @NotNull final Pane rowPane) {
final BuildingBuilderResource resource = resources.get(index);
final Label resourceLabel = rowPane.findPaneOfTypeByID(RESOURCE_NAME, Label.class);
final Label resourceMissingLabel = rowPane.findPaneOfTypeByID(RESOURCE_MISSING, Label.class);
final Label neededLabel = rowPane.findPaneOfTypeByID(RESOURCE_AVAILABLE_NEEDED, Label.class);
final Button addButton = rowPane.findPaneOfTypeByID(RESOURCE_ADD, Button.class);
switch(resource.getAvailabilityStatus()) {
case DONT_HAVE:
addButton.disable();
resourceLabel.setColor(RED, RED);
resourceMissingLabel.setColor(RED, RED);
neededLabel.setColor(RED, RED);
break;
case NEED_MORE:
addButton.enable();
resourceLabel.setColor(RED, RED);
resourceMissingLabel.setColor(RED, RED);
neededLabel.setColor(RED, RED);
break;
case HAVE_ENOUGH:
addButton.enable();
resourceLabel.setColor(DARKGREEN, DARKGREEN);
resourceMissingLabel.setColor(DARKGREEN, DARKGREEN);
neededLabel.setColor(DARKGREEN, DARKGREEN);
break;
case NOT_NEEDED:
default:
addButton.disable();
resourceLabel.setColor(BLACK, BLACK);
resourceMissingLabel.setColor(BLACK, BLACK);
neededLabel.setColor(BLACK, BLACK);
break;
}
//position the addResource Button to the right
final int buttonX = rowPane.getWidth() - addButton.getWidth() - (rowPane.getHeight() - addButton.getHeight()) / 2;
final int buttonY = rowPane.getHeight() - addButton.getHeight() - 2;
addButton.setPosition(buttonX, buttonY);
resourceLabel.setLabelText(resource.getName());
final int missing = resource.getMissingFromPlayer();
if (missing < 0) {
resourceMissingLabel.setLabelText(Integer.toString(missing));
} else {
resourceMissingLabel.setLabelText("");
}
neededLabel.setLabelText(Integer.toString(resource.getAvailable()) + " / " + Integer.toString(resource.getAmount()));
rowPane.findPaneOfTypeByID(RESOURCE_ID, Label.class).setLabelText(Integer.toString(index));
rowPane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class).setLabelText(Integer.toString(resource.getAmount() - resource.getAvailable()));
rowPane.findPaneOfTypeByID(RESOURCE_ICON, ItemIcon.class).setItem(new ItemStack(resource.getItem(), 1, resource.getDamageValue()));
}
Aggregations