use of net.minecraft.block.AirBlock in project Structurize by ldtteam.
the class Blueprint method getItem.
/**
* Calculate the item needed to place the current block in the structure.
*
* @param pos the pos its at.
* @return an item or null if not initialized.
*/
@Nullable
public Item getItem(final BlockPos pos) {
@Nullable final BlockInfo info = this.getBlockInfoAsMap().getOrDefault(pos, null);
if (info == null || info.getState() == null || info.getState().getBlock() instanceof AirBlock || info.getState().getMaterial().isLiquid()) {
return null;
}
final ItemStack stack = BlockUtils.getItemStackFromBlockState(info.getState());
if (!ItemStackUtils.isEmpty(stack)) {
return stack.getItem();
}
return null;
}
use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.
the class EntityAIWorkPlanter method decide.
@Override
protected IAIState decide() {
final IAIState nextState = super.decide();
if (nextState != START_WORKING && nextState != IDLE) {
return nextState;
}
final BuildingPlantation plantation = getOwnBuilding();
final List<BlockPos> list = plantation.getPosForPhase();
for (final BlockPos pos : list) {
if (isAtLeastThreeHigh(pos)) {
this.workPos = pos;
return PLANTATION_FARM;
}
}
final Item current = plantation.nextPlantPhase();
final int plantInBuilding = InventoryUtils.getCountFromBuilding(getOwnBuilding(), itemStack -> itemStack.sameItem(new ItemStack(current)));
final int plantInInv = InventoryUtils.getItemCountInItemHandler((worker.getInventoryCitizen()), itemStack -> itemStack.sameItem(new ItemStack(current)));
if (plantInBuilding + plantInInv <= 0) {
requestPlantable(current);
return START_WORKING;
}
if (plantInInv == 0 && plantInBuilding > 0) {
needsCurrently = new Tuple<>(itemStack -> itemStack.sameItem(new ItemStack(current)), Math.min(plantInBuilding, PLANT_TO_REQUEST));
return GATHERING_REQUIRED_MATERIALS;
}
for (final BlockPos pos : list) {
if (world.getBlockState(pos.above()).getBlock() instanceof AirBlock) {
this.workPos = pos;
return PLANTATION_PLANT;
}
}
return START_WORKING;
}
use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.
the class ColonyPermissionEventHandler method on.
/**
* PlayerInteractEvent handler.
* <p>
* Check, if a player right clicked a block. Deny if: - If the block is in colony - block is AbstractBlockHut - player has not permission
*
* @param event PlayerInteractEvent
*/
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
// Huts
if (event instanceof PlayerInteractEvent.RightClickBlock && block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getPlayer(), colony, Action.ACCESS_HUTS, event.getPos());
return;
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(block, event.getPos()) && perms.hasPermission(event.getPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (MineColonies.getConfig().getServer().enableColonyProtection.get()) {
if (!perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_BLOCK) && !(block instanceof AirBlock)) {
checkEventCancelation(Action.RIGHTCLICK_BLOCK, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (block instanceof ContainerBlock && !perms.hasPermission(event.getPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getPlayer(), colony, Action.OPEN_CONTAINER, event.getPos());
return;
}
if (event.getWorld().getBlockEntity(event.getPos()) != null && !perms.hasPermission(event.getPlayer(), Action.RIGHTCLICK_ENTITY)) {
checkEventCancelation(Action.RIGHTCLICK_ENTITY, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
final ItemStack stack = event.getItemStack();
if (ItemStackUtils.isEmpty(stack) || stack.getItem().isEdible()) {
return;
}
if (stack.getItem() instanceof PotionItem) {
checkEventCancelation(Action.THROW_POTION, event.getPlayer(), event.getWorld(), event, event.getPos());
return;
}
if (stack.getItem() instanceof ItemScanTool && !perms.hasPermission(event.getPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getPlayer(), colony, Action.USE_SCAN_TOOL, event.getPos());
}
}
}
}
use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.
the class BlockPosUtil method findLand.
/**
* this checks that you are not in the air or underground. If so it will look up and down for a good landing spot before TP.
*
* @param blockPos for the current block LOC.
* @param world the world to search in.
* @return blockPos to be used for the TP.
*/
public static BlockPos findLand(final BlockPos blockPos, final World world) {
int top = blockPos.getY();
int bot = 0;
int mid = blockPos.getY();
BlockPos foundland = null;
BlockPos tempPos = blockPos;
// We are doing a binary search to limit the amount of checks (usually at most 9 this way)
while (top >= bot) {
tempPos = new BlockPos(tempPos.getX(), mid, tempPos.getZ());
final Block block = world.getBlockState(tempPos).getBlock();
if (block instanceof AirBlock && world.canSeeSkyFromBelowWater(tempPos)) {
top = mid - 1;
foundland = tempPos;
} else {
bot = mid + 1;
foundland = tempPos;
}
mid = (bot + top) / 2;
}
if (world.getBlockState(tempPos).getMaterial().isSolid()) {
return foundland.above();
}
return foundland;
}
use of net.minecraft.block.AirBlock in project minecolonies by ldtteam.
the class AbstractEntityAIStructure method structureStep.
/**
* The Structure step to execute the actual placement actions etc.
*
* @return the next step to go to.
*/
protected IAIState structureStep() {
if (structurePlacer.getB().getStage() == null) {
return PICK_UP_RESIDUALS;
}
if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
return INVENTORY_FULL;
}
worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent("com.minecolonies.coremod.status.building"));
checkForExtraBuildingActions();
// some things to do first! then we go to the actual phase!
// Fill workFrom with the position from where the builder should build.
// also ensure we are at that position.
final BlockPos progress = getProgressPos() == null ? NULL_POS : getProgressPos().getA();
final BlockPos worldPos = structurePlacer.getB().getProgressPosInWorld(progress);
if (getProgressPos() != null) {
structurePlacer.getB().setStage(getProgressPos().getB());
}
if (!progress.equals(NULL_POS) && !limitReached && (blockToMine == null ? !walkToConstructionSite(worldPos) : !walkToConstructionSite(blockToMine))) {
return getState();
}
limitReached = false;
final StructurePhasePlacementResult result;
final StructurePlacer placer = structurePlacer.getA();
switch(structurePlacer.getB().getStage()) {
case BUILD_SOLID:
// structure
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !info.getBlockInfo().getState().getMaterial().isSolid() || isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
break;
case CLEAR_WATER:
// water
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.WATER_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getFluidState().isEmpty()), false);
break;
case CLEAR_NON_SOLIDS:
// clear air
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().decrement(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> !(info.getBlockInfo().getState().getBlock() instanceof AirBlock) || (handler.getWorld().isEmptyBlock(pos)))), false);
break;
case DECORATE:
// not solid
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getBlockInfo().getState().getMaterial().isSolid() && !isDecoItem(info.getBlockInfo().getState().getBlock()))), false);
break;
case SPAWN:
// entities
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_PLACEMENT, () -> placer.getIterator().increment(DONT_TOUCH_PREDICATE.or((info, pos, handler) -> info.getEntities().length == 0)), true);
break;
case REMOVE_WATER:
// water
placer.getIterator().setRemoving();
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.WATER_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> info.getBlockInfo().getState().getFluidState().isEmpty()), false);
break;
case REMOVE:
placer.getIterator().setRemoving();
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock || info.getBlockInfo().getState().getBlock() instanceof AirBlock || !handler.getWorld().getBlockState(pos).getFluidState().isEmpty() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSolidSubstitution.get() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSubstitution.get() || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockSubstitution.get() || handler.getWorld().getBlockState(pos).getBlock() instanceof IBuilderUndestroyable), true);
break;
case CLEAR:
default:
result = placer.executeStructureStep(world, null, progress, StructurePlacer.Operation.BLOCK_REMOVAL, () -> placer.getIterator().decrement((info, pos, handler) -> handler.getWorld().getBlockState(pos).getBlock() instanceof IBuilderUndestroyable || handler.getWorld().getBlockState(pos).getBlock() == Blocks.BEDROCK || handler.getWorld().getBlockState(pos).getBlock() instanceof AirBlock || info.getBlockInfo().getState().getBlock() == com.ldtteam.structurize.blocks.ModBlocks.blockFluidSubstitution.get() || !handler.getWorld().getBlockState(pos).getFluidState().isEmpty()), false);
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
getOwnBuilding().checkOrRequestBucket(getOwnBuilding().getRequiredResources(), worker.getCitizenData(), true);
}
break;
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FAIL) {
Log.getLogger().error("Failed placement at: " + result.getBlockResult().getWorldPos().toShortString());
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.FINISHED) {
getOwnBuilding().nextStage();
if (!structurePlacer.getB().nextStage()) {
getOwnBuilding().setProgressPos(null, null);
return COMPLETE_BUILD;
}
} else if (result.getBlockResult().getResult() == BlockPlacementResult.Result.LIMIT_REACHED) {
this.limitReached = true;
}
this.storeProgressPos(result.getIteratorPos(), structurePlacer.getB().getStage());
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.MISSING_ITEMS) {
if (hasListOfResInInvOrRequest(this, result.getBlockResult().getRequiredItems(), result.getBlockResult().getRequiredItems().size() > 1) == RECALC) {
job.getWorkOrder().setRequested(false);
return LOAD_STRUCTURE;
}
return NEEDS_ITEM;
}
if (result.getBlockResult().getResult() == BlockPlacementResult.Result.BREAK_BLOCK) {
blockToMine = result.getBlockResult().getWorldPos();
return MINE_BLOCK;
} else {
blockToMine = null;
}
if (MineColonies.getConfig().getServer().builderBuildBlockDelay.get() > 0) {
final double decrease = 1 - worker.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(BLOCK_PLACE_SPEED);
setDelay((int) ((MineColonies.getConfig().getServer().builderBuildBlockDelay.get() * PROGRESS_MULTIPLIER / (getPlaceSpeedLevel() / 2 + PROGRESS_MULTIPLIER)) * decrease));
}
return getState();
}
Aggregations