use of net.minecraft.tileentity.TileEntityChest 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 net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class TileEntityWareHouse method searchMostEmptySlot.
/**
* Search for the chest with the least items in it.
* @return the tileEntity of this chest.
*/
@Nullable
private TileEntityChest searchMostEmptySlot() {
int freeSlots = 0;
TileEntityChest emptiestChest = null;
for (@NotNull final BlockPos pos : getBuilding().getAdditionalCountainers()) {
final TileEntity entity = world.getTileEntity(pos);
if (entity == null) {
getBuilding().removeContainerPosition(pos);
continue;
}
if (entity instanceof TileEntityChest && InventoryUtils.getFirstOpenSlotFromProvider(entity) != -1) {
final int tempFreeSlots = ((TileEntityChest) entity).getSizeInventory() - InventoryUtils.getAmountOfStacksInProvider(entity);
if (freeSlots < tempFreeSlots) {
freeSlots = tempFreeSlots;
emptiestChest = (TileEntityChest) entity;
}
}
}
return emptiestChest;
}
use of net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class OpenInventoryMessage method doHutInventory.
private static void doHutInventory(final OpenInventoryMessage message, final EntityPlayerMP player) {
if (checkPermissions(ColonyManager.getClosestColony(player.getEntityWorld(), message.tePos), player)) {
@NotNull final TileEntityChest chest = (TileEntityChest) BlockPosUtil.getTileEntity(player.world, message.tePos);
if (!StringUtils.isNullOrEmpty(message.name)) {
chest.setCustomName(message.name);
}
player.displayGUIChest(chest);
}
}
use of net.minecraft.tileentity.TileEntityChest in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method isToolInHut.
/**
* Check all chests in the worker hut for a required tool.
*
* @param tool the type of tool requested (amount is ignored)
* @return true if a stack of that type was found
*/
public boolean isToolInHut(final String tool) {
@Nullable final AbstractBuildingWorker building = getOwnBuilding();
boolean hasItem;
if (building != null) {
hasItem = isToolInTileEntity(building.getTileEntity(), tool);
if (hasItem) {
return true;
}
for (final BlockPos pos : building.getAdditionalCountainers()) {
final TileEntity entity = world.getTileEntity(pos);
if (entity instanceof TileEntityChest) {
hasItem = isToolInTileEntity((TileEntityChest) entity, tool);
if (hasItem) {
return true;
}
}
}
}
return false;
}
use of net.minecraft.tileentity.TileEntityChest in project LogisticsPipes by RS485.
the class LogisticsEventListener method onPlayerInteract.
@SubscribeEvent
public void onPlayerInteract(final PlayerInteractEvent event) {
if (MainProxy.isServer(event.entityPlayer.worldObj)) {
if (event.action == Action.LEFT_CLICK_BLOCK) {
final TileEntity tile = event.entityPlayer.worldObj.getTileEntity(event.x, event.y, event.z);
if (tile instanceof LogisticsTileGenericPipe) {
if (((LogisticsTileGenericPipe) tile).pipe instanceof CoreRoutedPipe) {
if (!((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).canBeDestroyedByPlayer(event.entityPlayer)) {
event.setCanceled(true);
event.entityPlayer.addChatComponentMessage(new ChatComponentTranslation("lp.chat.permissiondenied"));
((LogisticsTileGenericPipe) tile).scheduleNeighborChange();
event.entityPlayer.worldObj.markBlockForUpdate(tile.xCoord, tile.yCoord, tile.zCoord);
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).delayTo = System.currentTimeMillis() + 200;
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).repeatFor = 10;
} else {
((CoreRoutedPipe) ((LogisticsTileGenericPipe) tile).pipe).setDestroyByPlayer();
}
}
}
}
if (event.action == Action.RIGHT_CLICK_BLOCK) {
WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(event.entityPlayer.worldObj, event.x, event.y, event.z);
TileEntity tileEntity = worldCoordinates.getTileEntity();
if (tileEntity instanceof TileEntityChest || SimpleServiceLocator.ironChestProxy.isIronChest(tileEntity)) {
//@formatter:off
List<WeakReference<ModuleQuickSort>> list = worldCoordinates.getAdjacentTileEntities().filter(adjacent -> adjacent.tileEntity instanceof LogisticsTileGenericPipe).filter(adjacent -> ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe instanceof PipeLogisticsChassi).filter(adjacent -> ((PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).getPointedOrientation() == adjacent.direction.getOpposite()).map(adjacent -> (PipeLogisticsChassi) ((LogisticsTileGenericPipe) adjacent.tileEntity).pipe).flatMap(pipeLogisticsChassi -> Arrays.stream(pipeLogisticsChassi.getModules().getModules())).filter(logisticsModule -> logisticsModule instanceof ModuleQuickSort).map(logisticsModule -> new WeakReference<>((ModuleQuickSort) logisticsModule)).collect(Collectors.toList());
if (!list.isEmpty()) {
LogisticsEventListener.chestQuickSortConnection.put(event.entityPlayer, list);
}
}
}
}
}
Aggregations