use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class WindowHutBuilder method pullResourcesFromHut.
/**
* Retrieve resources from the building to display in GUI.
*/
private void pullResourcesFromHut() {
final AbstractBuilding.View newView = builder.getColony().getBuilding(builder.getID());
if (newView instanceof BuildingBuilderView) {
final BuildingBuilderView updatedView = (BuildingBuilderView) newView;
final InventoryPlayer inventory = this.mc.player.inventory;
resources.clear();
resources.addAll(updatedView.getResources().values());
for (final BuildingBuilderResource resource : resources) {
resource.setPlayerAmount(InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), resource.getItem(), resource.getDamageValue()));
}
resources.sort(new BuildingBuilderResource.ResourceComparator());
}
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class WindowHutBuilder method transferItems.
/**
* On Button click transfert Items.
*
* @param button the clicked button.
*/
private void transferItems(@NotNull final Button button) {
final Pane pane = button.getParent();
final Label idLabel = pane.findPaneOfTypeByID(RESOURCE_ID, Label.class);
final int index = Integer.parseInt(idLabel.getLabelText());
final BuildingBuilderResource res = resources.get(index);
if (res == null) {
Log.getLogger().warn("WindowHutBuilder.transferItems: Error - Could not find the resource.");
} else {
// The itemStack size should not be greater than itemStack.getMaxStackSize, We send 1 instead
// and use quantity for the size
@NotNull final ItemStack itemStack = new ItemStack(res.getItem(), 1, res.getDamageValue());
final Label quantityLabel = pane.findPaneOfTypeByID(RESOURCE_QUANTITY_MISSING, Label.class);
final int quantity = Integer.parseInt(quantityLabel.getLabelText());
MineColonies.getNetwork().sendToServer(new TransferItemsRequestMessage(this.building, itemStack, quantity));
}
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class BuildingBuilderView method deserialize.
@Override
public void deserialize(@NotNull final ByteBuf buf) {
super.deserialize(buf);
final int size = buf.readInt();
resources.clear();
for (int i = 0; i < size; i++) {
//Serialising the ItemStack give a bad ItemStack sometimes using itemId + damage instead
//final ItemStack itemStack = ByteBufUtils.readItemStack(buf);
final int itemId = buf.readInt();
final int damage = buf.readInt();
final ItemStack itemStack = new ItemStack(Item.getByNameOrId(Integer.toString(itemId)), 1, damage);
final int amountAvailable = buf.readInt();
final int amountNeeded = buf.readInt();
final BuildingBuilderResource resource = new BuildingBuilderResource(itemStack.getItem(), itemStack.getItemDamage(), amountNeeded, amountAvailable);
resources.put(itemStack.getDisplayName(), resource);
}
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class BuildingBuilder method writeToNBT.
@Override
public void writeToNBT(@NotNull final NBTTagCompound compound) {
super.writeToNBT(compound);
@NotNull final NBTTagList neededResTagList = new NBTTagList();
for (@NotNull final BuildingBuilderResource resource : neededResources.values()) {
@NotNull final NBTTagCompound neededRes = new NBTTagCompound();
final ItemStack itemStack = new ItemStack(resource.getItem(), resource.getAmount(), resource.getDamageValue());
itemStack.writeToNBT(neededRes);
neededResTagList.appendTag(neededRes);
}
compound.setTag(TAG_RESOURCE_LIST, neededResTagList);
}
use of com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource in project minecolonies by Minecolonies.
the class BuildingBuilder method serializeToView.
/**
* Method to serialize data to send it to the view.
*
* @param buf the used ByteBuffer.
*/
@Override
public void serializeToView(@NotNull final ByteBuf buf) {
super.serializeToView(buf);
updateAvailableResources();
buf.writeInt(neededResources.size());
for (@NotNull final Map.Entry<String, BuildingBuilderResource> entry : neededResources.entrySet()) {
final BuildingBuilderResource resource = neededResources.get(entry.getKey());
//ByteBufUtils.writeItemStack() is Buggy, serialize itemId and damage separately;
final int itemId = Item.getIdFromItem(resource.getItem());
final int damage = resource.getDamageValue();
buf.writeInt(itemId);
buf.writeInt(damage);
buf.writeInt(resource.getAvailable());
buf.writeInt(resource.getAmount());
}
}
Aggregations