use of com.minecolonies.coremod.tileentities.TileEntityColonyBuilding in project minecolonies by Minecolonies.
the class EntityAIWorkDeliveryman method gatherItems.
/**
* Gather item from chest.
* Gathers only one stack of the item.
*
* @param buildingToDeliver building to deliver to.
*/
private AIState gatherItems(@NotNull final AbstractBuilding buildingToDeliver, @NotNull final BlockPos position) {
final TileEntity tileEntity = world.getTileEntity(position);
if (tileEntity instanceof TileEntityChest) {
if (!(tileEntity instanceof TileEntityColonyBuilding)) {
if (((TileEntityChest) tileEntity).numPlayersUsing == 0) {
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 1);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
setDelay(DUMP_AND_GATHER_DELAY);
return GATHER_IN_WAREHOUSE;
}
this.world.addBlockEvent(tileEntity.getPos(), tileEntity.getBlockType(), 1, 0);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos(), tileEntity.getBlockType(), true);
this.world.notifyNeighborsOfStateChange(tileEntity.getPos().down(), tileEntity.getBlockType(), true);
}
if (buildingToDeliver instanceof BuildingHome) {
final int extraFood = worker.getCitizenData().getSaturation() < EntityCitizen.HIGH_SATURATION ? 1 : 0;
//Tries to extract a certain amount of the item of the chest.
if (InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), itemStack -> !InventoryUtils.isItemStackEmpty(itemStack) && itemStack.getItem() instanceof ItemFood, buildingToDeliver.getBuildingLevel() + extraFood, new InvWrapper(worker.getInventoryCitizen()))) {
worker.setHeldItem(SLOT_HAND);
setDelay(DUMP_AND_GATHER_DELAY);
return DELIVERY;
}
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
} else if (itemsToDeliver.isEmpty() && !isToolInTileEntity((TileEntityChest) tileEntity, buildingToDeliver.getRequiredTool(), buildingToDeliver.getBuildingLevel())) {
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
} else if (!itemsToDeliver.isEmpty()) {
final ItemStack stack = itemsToDeliver.get(0);
if (isInTileEntity((TileEntityChest) tileEntity, stack)) {
itemsToDeliver.remove(0);
worker.setHeldItem(SLOT_HAND);
setDelay(DUMP_AND_GATHER_DELAY);
return DELIVERY;
}
((BuildingDeliveryman) getOwnBuilding()).setBuildingToDeliver(null);
itemsToDeliver.clear();
return START_WORKING;
}
}
setDelay(DUMP_AND_GATHER_DELAY);
return GATHER_IN_WAREHOUSE;
}
use of com.minecolonies.coremod.tileentities.TileEntityColonyBuilding in project minecolonies by Minecolonies.
the class BlockHutTownHall method onBlockPlacedBy.
@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
if (worldIn.isRemote) {
return;
}
if (placer.getActiveHand().equals(EnumHand.MAIN_HAND)) {
final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
String style = Constants.DEFAULT_STYLE;
final TileEntity tileEntity = worldIn.getTileEntity(pos);
if (tileEntity instanceof TileEntityColonyBuilding && !((TileEntityColonyBuilding) tileEntity).getStyle().isEmpty()) {
style = ((TileEntityColonyBuilding) tileEntity).getStyle();
}
if (colony == null || !ColonyManager.isTooCloseToColony(worldIn, pos)) {
ColonyManager.createColony(worldIn, pos, (EntityPlayer) placer, style);
} else {
colony.setStyle(style);
}
}
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}
use of com.minecolonies.coremod.tileentities.TileEntityColonyBuilding in project minecolonies by Minecolonies.
the class AbstractBlockHut method onBlockPlacedBy.
/**
* Event-Handler for placement of this block.
* <p>
* Override for custom logic.
*
* @param worldIn the word we are in.
* @param pos the position where the block was placed.
* @param state the state the placed block is in.
* @param placer the player placing the block.
* @param stack the itemstack from where the block was placed.
* @see Block#onBlockPlacedBy(World, BlockPos, IBlockState,
* EntityLivingBase, ItemStack)
*/
@Override
public void onBlockPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final IBlockState state, final EntityLivingBase placer, final ItemStack stack) {
super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
/*
Only work on server side
*/
if (worldIn.isRemote) {
return;
}
final TileEntity tileEntity = worldIn.getTileEntity(pos);
if (placer instanceof EntityPlayer && tileEntity instanceof TileEntityColonyBuilding) {
@NotNull final TileEntityColonyBuilding hut = (TileEntityColonyBuilding) tileEntity;
@Nullable final Colony colony = ColonyManager.getColony(worldIn, hut.getPosition());
if (colony != null) {
colony.getBuildingManager().addNewBuilding(hut, worldIn);
}
}
}
use of com.minecolonies.coremod.tileentities.TileEntityColonyBuilding in project minecolonies by Minecolonies.
the class GuiHandler method getServerGuiElement.
@Override
public Object getServerGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
if (id == ID.DEFAULT.ordinal()) {
final BlockPos pos = new BlockPos(x, y, z);
final TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof ScarecrowTileEntity) {
return new ContainerField((ScarecrowTileEntity) tileEntity, player.inventory, world, pos);
} else if (tileEntity instanceof TileEntityRack) {
return new ContainerRack((TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), player.inventory);
} else {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, new BlockPos(x, y, z));
if (building != null) {
return new CraftingGUIBuilding(player.inventory, world);
}
return null;
}
} else if (id == ID.BUILDING_INVENTORY.ordinal()) {
final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
if (entity instanceof TileEntityColonyBuilding) {
final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
final Colony colony = ColonyManager.getClosestColony(world, tileEntityColonyBuilding.getPos());
return new ContainerMinecoloniesBuildingInventory(player.inventory, tileEntityColonyBuilding, colony.getID(), tileEntityColonyBuilding.getPos());
}
} else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
final Colony colony = ColonyManager.getColony(x);
final CitizenData citizen = colony.getCitizenManager().getCitizen(y);
final AbstractBuilding building = citizen.getWorkBuilding();
return new ContainerMinecoloniesCitizenInventory(player.inventory, citizen.getInventory(), colony.getID(), building == null ? null : building.getID(), citizen.getId());
}
return null;
}
use of com.minecolonies.coremod.tileentities.TileEntityColonyBuilding in project minecolonies by Minecolonies.
the class GuiHandler method getClientGuiElement.
@Override
public Object getClientGuiElement(final int id, final EntityPlayer player, final World world, final int x, final int y, final int z) {
if (id == ID.DEFAULT.ordinal()) {
final BlockPos pos = new BlockPos(x, y, z);
final TileEntity tileEntity = world.getTileEntity(pos);
if (tileEntity instanceof ScarecrowTileEntity) {
return new GuiField(player.inventory, (ScarecrowTileEntity) tileEntity, world, pos);
} else if (tileEntity instanceof TileEntityRack) {
return new GuiRack(player.inventory, (TileEntityRack) tileEntity, ((TileEntityRack) tileEntity).getOtherChest(), world, pos);
} else {
@Nullable final AbstractBuildingView building = ColonyManager.getBuildingView(new BlockPos(x, y, z));
if (building instanceof AbstractBuildingWorker.View) {
return new WindowGuiCrafting(player.inventory, world, (AbstractBuildingWorker.View) building);
}
}
} else if (id == ID.BUILDING_INVENTORY.ordinal()) {
final TileEntity entity = world.getTileEntity(new BlockPos(x, y, z));
if (entity instanceof TileEntityColonyBuilding) {
final TileEntityColonyBuilding tileEntityColonyBuilding = (TileEntityColonyBuilding) entity;
return new GuiChest(player.inventory, tileEntityColonyBuilding);
}
} else if (id == ID.CITIZEN_INVENTORY.ordinal()) {
final ColonyView view = ColonyManager.getColonyView(x);
final CitizenDataView citizenDataView = view.getCitizen(y);
return new GuiChest(player.inventory, citizenDataView.getInventory());
}
return null;
}
Aggregations