use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class MarkBuildingDirtyMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final MarkBuildingDirtyMessage 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;
}
building.getTileEntity().markDirty();
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method connectBlockToBuildingIfNecessary.
@Override
public void connectBlockToBuildingIfNecessary(@NotNull final Block block, @NotNull final BlockPos pos) {
final BlockPos buildingLocation = job.getWorkOrder().getBuildingLocation();
final AbstractBuilding building = this.getOwnBuilding().getColony().getBuilding(buildingLocation);
if (building != null) {
building.registerBlockPosition(block, pos);
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method initiate.
private void initiate() {
if (!job.hasStructure()) {
workFrom = null;
loadStructure();
final WorkOrderBuildDecoration wo = job.getWorkOrder();
if (wo == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Starting and missing work order(%d)", worker.getColony().getID(), worker.getCitizenData().getId(), job.getWorkOrderId()));
return;
}
if (wo instanceof WorkOrderBuild) {
final AbstractBuilding building = job.getColony().getBuilding(wo.getBuildingLocation());
if (building == null) {
Log.getLogger().error(String.format("Builder (%d:%d) ERROR - Starting and missing building(%s)", worker.getColony().getID(), worker.getCitizenData().getId(), wo.getBuildingLocation()));
return;
}
worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, job.getStructure().getName());
//Don't go through the CLEAR stage for repairs and upgrades
if (building.getBuildingLevel() > 0) {
wo.setCleared(true);
}
} else {
worker.sendLocalizedChat(COM_MINECOLONIES_COREMOD_ENTITY_BUILDER_BUILDSTART, wo.getName());
}
}
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class ItemScepterGuard method handleItemUsage.
/**
* Handles the usage of the item.
*
* @param worldIn the world it is used in.
* @param pos the position.
* @param compound the compound.
* @param playerIn the player using it.
* @return if it has been successful.
*/
@NotNull
private static EnumActionResult handleItemUsage(final World worldIn, final BlockPos pos, final NBTTagCompound compound, final EntityPlayer playerIn) {
final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
if (colony == null) {
return EnumActionResult.FAIL;
}
final BlockPos guardTower = BlockPosUtil.readFromNBT(compound, "pos");
final AbstractBuilding hut = colony.getBuilding(guardTower);
if (hut == null || !(hut instanceof BuildingGuardTower)) {
return EnumActionResult.FAIL;
}
if (BlockPosUtil.getDistance2D(pos, guardTower) > ((BuildingGuardTower) hut).getPatrolDistance()) {
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuardTooFar");
return EnumActionResult.FAIL;
}
final BuildingGuardTower.Task task = BuildingGuardTower.Task.values()[compound.getInteger("task")];
final CitizenData citizen = ((BuildingGuardTower) hut).getWorker();
String name = "";
if (citizen != null) {
name = " " + citizen.getName();
}
if (task.equals(BuildingGuardTower.Task.GUARD)) {
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuard", pos, name);
((BuildingGuardTower) hut).setGuardTarget(pos);
playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem);
} else {
if (!compound.hasKey(TAG_LAST_POS)) {
((BuildingGuardTower) hut).resetPatrolTargets();
}
((BuildingGuardTower) hut).addPatrolTargets(pos);
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickPatrol", pos, name);
}
BlockPosUtil.writeToNBT(compound, TAG_LAST_POS, pos);
return EnumActionResult.SUCCESS;
}
use of com.minecolonies.coremod.colony.buildings.AbstractBuilding in project minecolonies by Minecolonies.
the class EntityAIGoHome method handleSaturation.
/**
* Handle the saturation of the citizen.
*
* @param pos the position.
*/
private void handleSaturation(@NotNull final BlockPos pos) {
if (citizen.isWorkerAtSiteWithMove(pos, 2) && citizen.getColony() != null && citizen.getCitizenData() != null && citizen.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION) {
final double currentSaturation = citizen.getCitizenData().getSaturation();
boolean tookFood = false;
final AbstractBuilding home = citizen.getColony().getBuilding(pos);
if (home instanceof BuildingHome && currentSaturation < EntityCitizen.FULL_SATURATION) {
final int slot = InventoryUtils.findFirstSlotInProviderNotEmptyWith(home.getTileEntity(), itemStack -> itemStack.getItem() instanceof ItemFood);
if (slot != -1) {
final ItemStack stack = home.getTileEntity().getStackInSlot(slot);
if (!InventoryUtils.isItemStackEmpty(stack)) {
final int slotToSet = InventoryUtils.getFirstOpenSlotFromItemHandler(new InvWrapper(citizen.getInventoryCitizen()));
if (slotToSet == -1) {
InventoryUtils.forceItemStackToItemHandler(new InvWrapper(citizen.getInventoryCitizen()), new ItemStack(stack.getItem(), 1), stack1 -> citizen.getWorkBuilding() == null || !citizen.getWorkBuilding().neededForWorker(stack1));
} else {
citizen.getInventoryCitizen().setInventorySlotContents(slotToSet, new ItemStack(stack.getItem(), 1));
}
tookFood = true;
stack.setCount(stack.getCount() - 1);
}
((BuildingHome) home).setFoodNeeded(false);
}
}
if (!tookFood) {
requestFoodIfRequired(currentSaturation, home);
}
}
}
Aggregations