use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class BuildingLumberjack method writeToNBT.
@Override
public void writeToNBT(@NotNull final NBTTagCompound compound) {
super.writeToNBT(compound);
@NotNull final NBTTagList saplingTagList = new NBTTagList();
for (@NotNull final Map.Entry<ItemStorage, Boolean> entry : treesToFell.entrySet()) {
@NotNull final NBTTagCompound saplingCompound = new NBTTagCompound();
entry.getKey().getItemStack().writeToNBT(saplingCompound);
saplingCompound.setBoolean(TAG_CUT, entry.getValue());
saplingTagList.appendTag(saplingCompound);
}
compound.setTag(TAG_SAPLINGS, saplingTagList);
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class BuildingLumberjack method readFromNBT.
@Override
public void readFromNBT(@NotNull final NBTTagCompound compound) {
super.readFromNBT(compound);
if (treesToFell.isEmpty()) {
final NBTTagList saplingTagList = compound.getTagList(TAG_SAPLINGS, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < saplingTagList.tagCount(); ++i) {
final NBTTagCompound saplingCompound = saplingTagList.getCompoundTagAt(i);
final ItemStack stack = new ItemStack(saplingCompound);
final boolean cut = saplingCompound.getBoolean(TAG_CUT);
treesToFell.put(new ItemStorage(stack), cut);
}
}
checkTreesToFell();
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class WindowBuildBuilding 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 (ItemStackUtils.isEmpty(res) || amount == 0) {
return;
}
ItemStorage resource = resources.get(res.getUnlocalizedName());
if (resource == null) {
resource = new ItemStorage(res);
resource.setAmount(amount);
} else {
resource.setAmount(resource.getAmount() + amount);
}
resources.put(res.getUnlocalizedName(), resource);
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class WindowHutLumberjack method onButtonClicked.
@Override
public void onButtonClicked(@NotNull final Button button) {
if (button.getID().equals(BUTTON_CURRENT_SAPLING)) {
final int row = saplingsList.getListElementIndexByPane(button);
final ItemStorage saplingStack = treesToFell.keySet().toArray(new ItemStorage[treesToFell.size()])[row];
final boolean shouldCut = !treesToFell.get(saplingStack);
treesToFell.put(saplingStack, shouldCut);
MineColonies.getNetwork().sendToServer(new LumberjackSaplingSelectorMessage(building, saplingStack.getItemStack(), shouldCut));
this.ownBuilding.treesToFell.clear();
this.ownBuilding.treesToFell.putAll(treesToFell);
} else if (button.getID().equals(BUTTON_TOGGLE_ALL)) {
final boolean on = button.getLabel().equals(LanguageHandler.format(TOGGLE_ALL_OPTIONS_ON));
if (on) {
button.setLabel(LanguageHandler.format(TOGGLE_ALL_OPTIONS_OFF));
} else {
button.setLabel(LanguageHandler.format(TOGGLE_ALL_OPTIONS_ON));
}
for (final Map.Entry<ItemStorage, Boolean> entry : new HashSet<Map.Entry<ItemStorage, Boolean>>(treesToFell.entrySet())) {
treesToFell.put(entry.getKey(), on);
}
this.ownBuilding.treesToFell.clear();
this.ownBuilding.treesToFell.putAll(treesToFell);
} else {
super.onButtonClicked(button);
}
}
use of com.minecolonies.api.crafting.ItemStorage in project minecolonies by Minecolonies.
the class CompatabilityManager method connectLeaveToSapling.
@Override
public void connectLeaveToSapling(final IBlockState leave, final ItemStack stack) {
final ItemStack tempStack = new ItemStack(leave.getBlock(), 1, leave.getBlock().getMetaFromState(leave));
final IBlockState tempLeave = BlockLeaves.getBlockFromItem(tempStack.getItem()).getStateFromMeta(tempStack.getMetadata());
if (!leavesToSaplingMap.containsKey(tempLeave) && !leavesToSaplingMap.containsValue(new ItemStorage(stack))) {
leavesToSaplingMap.put(tempLeave, new ItemStorage(stack));
}
}
Aggregations