Search in sources :

Example 1 with IPlacementHandler

use of com.minecolonies.coremod.placementhandlers.IPlacementHandler in project minecolonies by Minecolonies.

the class AbstractEntityAIStructure method placeBlockAt.

private boolean placeBlockAt(@NotNull final IBlockState blockState, @NotNull final BlockPos coords) {
    final ItemStack item = BlockUtils.getItemStackFromBlockState(blockState);
    worker.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, item == null ? ItemStackUtils.EMPTY : item);
    final IBlockState decrease;
    for (final IPlacementHandler handlers : PlacementHandlers.handlers) {
        final Object result = handlers.handle(world, coords, blockState, this, Configurations.gameplay.builderInfiniteResources, false);
        if (result instanceof IPlacementHandler.ActionProcessingResult) {
            if (result == ACCEPT) {
                return true;
            }
            if (result == DENY) {
                return false;
            }
            continue;
        }
        if (result instanceof IBlockState) {
            decrease = (IBlockState) result;
            decreaseInventory(coords, decrease.getBlock(), decrease);
            connectBlockToBuildingIfNecessary(decrease, coords);
            worker.swingArm(worker.getActiveHand());
            worker.addExperience(XP_EACH_BLOCK);
            return true;
        }
    }
    Log.getLogger().warn("Couldn't handle block: " + blockState.getBlock().getUnlocalizedName());
    return true;
}
Also used : IPlacementHandler(com.minecolonies.coremod.placementhandlers.IPlacementHandler) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IPlacementHandler

use of com.minecolonies.coremod.placementhandlers.IPlacementHandler in project minecolonies by Minecolonies.

the class StructureWrapper method handleBlockPlacement.

private void handleBlockPlacement(final BlockPos pos, final IBlockState localState, final boolean complete) {
    for (final IPlacementHandler handlers : PlacementHandlers.handlers) {
        final Object result = handlers.handle(world, pos, localState, null, true, complete);
        if (result instanceof IBlockState) {
            final IBlockState blockState = (IBlockState) result;
            final Colony colony = ColonyManager.getColony(world, pos);
            if (colony != null) {
                final AbstractBuilding building = colony.getBuildingManager().getBuilding(position);
                if (building != null) {
                    building.registerBlockPosition(blockState, pos, world);
                }
            }
            return;
        } else if (!(result instanceof IPlacementHandler.ActionProcessingResult) || result != IGNORE) {
            return;
        }
    }
}
Also used : IPlacementHandler(com.minecolonies.coremod.placementhandlers.IPlacementHandler) IBlockState(net.minecraft.block.state.IBlockState) Colony(com.minecolonies.coremod.colony.Colony) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Aggregations

IPlacementHandler (com.minecolonies.coremod.placementhandlers.IPlacementHandler)2 IBlockState (net.minecraft.block.state.IBlockState)2 Colony (com.minecolonies.coremod.colony.Colony)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 ItemStack (net.minecraft.item.ItemStack)1