use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class TileEntityWareHouse method isToolInHut.
/**
* Check all chests in the worker hut for a required tool.
* @param tool the type of tool requested (amount is ignored)
* @param requestingBuilding the building requesting it.
* @return true if a stack of that type was found
*/
private boolean isToolInHut(final String tool, @NotNull final AbstractBuilding requestingBuilding) {
@Nullable final AbstractBuilding building = getBuilding();
boolean hasItem;
if (building != null) {
if (tool.equals(Utils.PICKAXE)) {
hasItem = InventoryUtils.isPickaxeInProvider(building.getTileEntity(), requestingBuilding.getNeededPickaxeLevel(), requestingBuilding.getBuildingLevel());
} else {
hasItem = InventoryUtils.isToolInProvider(building.getTileEntity(), tool, requestingBuilding.getBuildingLevel());
}
if (hasItem) {
return true;
}
for (final BlockPos pos : building.getAdditionalCountainers()) {
@Nullable final TileEntity entity = world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
if (tool.equals(Utils.PICKAXE)) {
hasItem = InventoryUtils.isPickaxeInProvider(entity, requestingBuilding.getNeededPickaxeLevel(), requestingBuilding.getBuildingLevel());
} else {
hasItem = InventoryUtils.isToolInProvider(entity, tool, requestingBuilding.getBuildingLevel());
}
if (hasItem) {
return true;
}
}
}
}
return false;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class TileEntityWareHouse method update.
@Override
public void update() {
super.update();
if (ticksPassed != WAIT_TICKS) {
ticksPassed++;
return;
}
ticksPassed = 0;
final AbstractBuilding wareHouseBuilding = getBuilding();
if (getColony() != null && wareHouseBuilding instanceof BuildingWareHouse && !((BuildingWareHouse) wareHouseBuilding).getRegisteredDeliverymen().isEmpty()) {
final Map<BlockPos, AbstractBuilding> buildingMap = getColony().getBuildings();
if (buildingMap.size() < this.index) {
this.index = 1;
}
int i = 1;
for (@NotNull final Map.Entry<BlockPos, AbstractBuilding> buildingEntry : buildingMap.entrySet()) {
if (i == index) {
if (!taskSet.contains(buildingEntry.getValue()) && buildingEntry.getValue().needsAnything()) {
checkInWareHouse(buildingEntry.getValue(), true);
}
this.index++;
}
i++;
}
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class BuildRequestMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final BuildRequestMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony == null) {
return;
}
final AbstractBuilding building = colony.getBuilding(message.buildingId);
if (building == null) {
return;
}
//Verify player has permission to change this huts settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
if (building.hasWorkOrder()) {
building.removeWorkOrder();
} else {
switch(message.mode) {
case BUILD:
building.requestUpgrade();
break;
case REPAIR:
building.requestRepair();
break;
default:
break;
}
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class BuildToolPlaceMessage method setupBuilding.
/**
* setup the building once it has been placed.
*
* @param world World the hut is being placed into.
* @param player Who placed the hut.
* @param sn The name of the structure.
* @param workOrderName The name of the work order.
* @param rotation The number of times the structure should be rotated.
* @param buildPos The location the hut is being placed.
* @param mirror Whether or not the strcture is mirrored.
*/
private static void setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final Structures.StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
if (building == null) {
Log.getLogger().error("BuildTool: building is null!");
} else {
if (building.getTileEntity() != null) {
final Colony colony = ColonyManager.getColony(world, buildPos);
if (colony == null) {
Log.getLogger().info("No colony for " + player.getName());
} else {
building.getTileEntity().setColony(colony);
}
}
building.setStyle(sn.getStyle());
building.setRotation(rotation);
if (mirror) {
building.setMirror();
}
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class TransferItemsRequestMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final TransferItemsRequestMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony == null) {
Log.getLogger().warn("TransferItemsRequestMessage colony is null");
return;
}
final AbstractBuilding building = colony.getBuilding(message.buildingId);
if (building == null) {
Log.getLogger().warn("TransferItemsRequestMessage building is null");
return;
}
if (message.quantity <= 0) {
Log.getLogger().warn("TransferItemsRequestMessage quantity below 0");
return;
}
final Item item = message.itemStack.getItem();
final int amountToTake = Math.min(message.quantity, InventoryUtils.getItemCountInItemHandler(new InvWrapper(player.inventory), item, message.itemStack.getItemDamage()));
final ItemStack itemStackToTake = new ItemStack(item, amountToTake, message.itemStack.getItemDamage());
ItemStack remainingItemStack = InventoryUtils.addItemStackToProviderWithResult(building.getTileEntity(), itemStackToTake);
if (!InventoryUtils.isItemStackEmpty(remainingItemStack)) {
//If we still have some to drop, let's try the additional chests now
if (InventoryUtils.getItemStackSize(remainingItemStack) > 0) {
final World world = colony.getWorld();
for (final BlockPos pos : building.getAdditionalCountainers()) {
final TileEntity entity = world.getTileEntity(pos);
remainingItemStack = InventoryUtils.addItemStackToProviderWithResult(entity, remainingItemStack);
if (InventoryUtils.isItemStackEmpty(remainingItemStack)) {
break;
}
}
}
}
if (InventoryUtils.isItemStackEmpty(remainingItemStack) || InventoryUtils.getItemStackSize(remainingItemStack) != InventoryUtils.getItemStackSize(itemStackToTake)) {
//Only doing this at the moment as the additional chest do not detect new content
building.getTileEntity().markDirty();
}
int amountToRemoveFromPlayer = amountToTake - InventoryUtils.getItemStackSize(remainingItemStack);
while (amountToRemoveFromPlayer > 0) {
final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), item, message.itemStack.getItemDamage());
final ItemStack itemsTaken = player.inventory.decrStackSize(slot, amountToRemoveFromPlayer);
amountToRemoveFromPlayer -= InventoryUtils.getItemStackSize(itemsTaken);
}
}
Aggregations