Search in sources :

Example 1 with BlockDecorationController

use of com.minecolonies.coremod.blocks.BlockDecorationController in project minecolonies by ldtteam.

the class DecorationBuildRequestMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
    if (colony == null) {
        return;
    }
    final PlayerEntity player = ctxIn.getSender();
    // Verify player has permission to change this huts settings
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
    if (entity instanceof TileEntityDecorationController) {
        final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderBuildDecoration).filter(entry -> ((WorkOrderBuildDecoration) entry.getValue()).getSchematicLocation().equals(pos)).findFirst();
        if (wo.isPresent()) {
            colony.getWorkManager().removeWorkOrder(wo.get().getKey());
            return;
        }
        int difference = 0;
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
        final Blueprint blueprint = structure.getBluePrint();
        if (blueprint != null) {
            final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
            if (structureState != null) {
                if (!(structureState.getBlock() instanceof BlockDecorationController)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
                    return;
                }
                final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    difference = worldRotation - structureRotation;
                } else {
                    difference = 4 + worldRotation - structureRotation;
                }
            }
        }
        final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
        final WorkOrderBuildDecoration order = new WorkOrderBuildDecoration(name + level, name + level, difference, pos, state.getValue(BlockDecorationController.MIRROR));
        if (level != ((TileEntityDecorationController) entity).getTier()) {
            order.setLevelUp();
        }
        colony.getWorkManager().addWorkOrder(order, false);
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Action(com.minecolonies.api.colony.permissions.Action) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) RegistryKey(net.minecraft.util.RegistryKey) Map(java.util.Map) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) LogicalSide(net.minecraftforge.fml.LogicalSide) IMessage(com.minecolonies.api.network.IMessage) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Registry(net.minecraft.util.registry.Registry) Nullable(org.jetbrains.annotations.Nullable) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) IColony(com.minecolonies.api.colony.IColony) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 2 with BlockDecorationController

use of com.minecolonies.coremod.blocks.BlockDecorationController in project minecolonies by Minecolonies.

the class AbstractPathJob method isPassable.

/**
 * Is the space passable.
 *
 * @param block the block we are checking.
 * @return true if the block does not block movement.
 */
protected boolean isPassable(@NotNull final BlockState block, final BlockPos pos, final Node parent) {
    if (block.getMaterial() != Material.AIR) {
        final VoxelShape shape = block.getCollisionShape(world, pos);
        if (block.getMaterial().blocksMotion() && !(shape.isEmpty() || shape.max(Direction.Axis.Y) <= 0.1)) {
            if (block.getBlock() instanceof TrapDoorBlock) {
                final BlockPos parentPos = parent == null ? start : parent.pos;
                final BlockPos dir = pos.subtract(parentPos);
                if (dir.getY() != 0 && dir.getX() == 0 && dir.getZ() == 0) {
                    return true;
                }
                final Direction facing = block.getValue(TrapDoorBlock.FACING);
                if (dir.getX() != 0) {
                    return facing == Direction.NORTH || facing == Direction.SOUTH;
                }
                return facing == Direction.EAST || facing == Direction.WEST;
            } else {
                return pathingOptions.canEnterDoors() && (block.getBlock() instanceof DoorBlock || block.getBlock() instanceof FenceGateBlock) || block.getBlock() instanceof AbstractBlockMinecoloniesConstructionTape || block.getBlock() instanceof PressurePlateBlock || block.getBlock() instanceof BlockDecorationController || block.getBlock() instanceof AbstractSignBlock || block.getBlock() instanceof AbstractBannerBlock;
            }
        } else if (block.getBlock() instanceof FireBlock || block.getBlock() instanceof SweetBerryBushBlock) {
            return false;
        } else {
            if (isLadder(block.getBlock(), pos)) {
                return true;
            }
            if (shape.isEmpty() || shape.max(Direction.Axis.Y) <= 0.1 && !isLiquid((block)) && (block.getBlock() != Blocks.SNOW || block.getValue(SnowBlock.LAYERS) == 1)) {
                final PathNodeType pathType = block.getAiPathNodeType(world, pos);
                if (pathType == null || pathType.getDanger() == null) {
                    return true;
                }
            }
            return false;
        }
    }
    return true;
}
Also used : BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) PathNodeType(net.minecraft.pathfinding.PathNodeType) Direction(net.minecraft.util.Direction) AbstractBlockMinecoloniesConstructionTape(com.minecolonies.api.blocks.decorative.AbstractBlockMinecoloniesConstructionTape) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with BlockDecorationController

use of com.minecolonies.coremod.blocks.BlockDecorationController in project minecolonies by Minecolonies.

the class DecorationBuildRequestMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final IColony colony = IColonyManager.getInstance().getColonyByPosFromDim(dimension, pos);
    if (colony == null) {
        return;
    }
    final PlayerEntity player = ctxIn.getSender();
    // Verify player has permission to change this huts settings
    if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
        return;
    }
    final TileEntity entity = player.getCommandSenderWorld().getBlockEntity(pos);
    if (entity instanceof TileEntityDecorationController) {
        final Optional<Map.Entry<Integer, IWorkOrder>> wo = colony.getWorkManager().getWorkOrders().entrySet().stream().filter(entry -> entry.getValue() instanceof WorkOrderBuildDecoration).filter(entry -> ((WorkOrderBuildDecoration) entry.getValue()).getSchematicLocation().equals(pos)).findFirst();
        if (wo.isPresent()) {
            colony.getWorkManager().removeWorkOrder(wo.get().getKey());
            return;
        }
        int difference = 0;
        final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), this.pos, name + level, new PlacementSettings(), true);
        final Blueprint blueprint = structure.getBluePrint();
        if (blueprint != null) {
            final BlockState structureState = structure.getBluePrint().getBlockInfoAsMap().get(structure.getBluePrint().getPrimaryBlockOffset()).getState();
            if (structureState != null) {
                if (!(structureState.getBlock() instanceof BlockDecorationController)) {
                    Log.getLogger().error(String.format("Schematic %s doesn't have a correct Primary Offset", name + level));
                    return;
                }
                final int structureRotation = structureState.getValue(BlockDecorationController.FACING).get2DDataValue();
                final int worldRotation = colony.getWorld().getBlockState(this.pos).getValue(BlockDecorationController.FACING).get2DDataValue();
                if (structureRotation <= worldRotation) {
                    difference = worldRotation - structureRotation;
                } else {
                    difference = 4 + worldRotation - structureRotation;
                }
            }
        }
        final BlockState state = player.getCommandSenderWorld().getBlockState(pos);
        final WorkOrderBuildDecoration order = new WorkOrderBuildDecoration(name + level, name + level, difference, pos, state.getValue(BlockDecorationController.MIRROR));
        if (level != ((TileEntityDecorationController) entity).getTier()) {
            order.setLevelUp();
        }
        colony.getWorkManager().addWorkOrder(order, false);
    }
}
Also used : IWorkOrder(com.minecolonies.api.colony.workorders.IWorkOrder) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) Action(com.minecolonies.api.colony.permissions.Action) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) RegistryKey(net.minecraft.util.RegistryKey) Map(java.util.Map) Log(com.minecolonies.api.util.Log) BlockState(net.minecraft.block.BlockState) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) LogicalSide(net.minecraftforge.fml.LogicalSide) IMessage(com.minecolonies.api.network.IMessage) PlayerEntity(net.minecraft.entity.player.PlayerEntity) World(net.minecraft.world.World) IColonyManager(com.minecolonies.api.colony.IColonyManager) BlockPos(net.minecraft.util.math.BlockPos) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Registry(net.minecraft.util.registry.Registry) Nullable(org.jetbrains.annotations.Nullable) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration) ResourceLocation(net.minecraft.util.ResourceLocation) IColony(com.minecolonies.api.colony.IColony) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) TileEntityDecorationController(com.minecolonies.coremod.tileentities.TileEntityDecorationController) IColony(com.minecolonies.api.colony.IColony) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) WorkOrderBuildDecoration(com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)

Example 4 with BlockDecorationController

use of com.minecolonies.coremod.blocks.BlockDecorationController in project minecolonies by ldtteam.

the class AbstractPathJob method isPassable.

/**
 * Is the space passable.
 *
 * @param block the block we are checking.
 * @return true if the block does not block movement.
 */
protected boolean isPassable(@NotNull final BlockState block, final BlockPos pos, final Node parent) {
    if (block.getMaterial() != Material.AIR) {
        final VoxelShape shape = block.getCollisionShape(world, pos);
        if (block.getMaterial().blocksMotion() && !(shape.isEmpty() || shape.max(Direction.Axis.Y) <= 0.1)) {
            if (block.getBlock() instanceof TrapDoorBlock) {
                final BlockPos parentPos = parent == null ? start : parent.pos;
                final BlockPos dir = pos.subtract(parentPos);
                if (dir.getY() != 0 && dir.getX() == 0 && dir.getZ() == 0) {
                    return true;
                }
                final Direction facing = block.getValue(TrapDoorBlock.FACING);
                if (dir.getX() != 0) {
                    return facing == Direction.NORTH || facing == Direction.SOUTH;
                }
                return facing == Direction.EAST || facing == Direction.WEST;
            } else {
                return pathingOptions.canEnterDoors() && (block.getBlock() instanceof DoorBlock || block.getBlock() instanceof FenceGateBlock) || block.getBlock() instanceof AbstractBlockMinecoloniesConstructionTape || block.getBlock() instanceof PressurePlateBlock || block.getBlock() instanceof BlockDecorationController || block.getBlock() instanceof AbstractSignBlock || block.getBlock() instanceof AbstractBannerBlock;
            }
        } else if (block.getBlock() instanceof FireBlock || block.getBlock() instanceof SweetBerryBushBlock) {
            return false;
        } else {
            if (isLadder(block.getBlock(), pos)) {
                return true;
            }
            if (shape.isEmpty() || shape.max(Direction.Axis.Y) <= 0.1 && !isLiquid((block)) && (block.getBlock() != Blocks.SNOW || block.getValue(SnowBlock.LAYERS) == 1)) {
                final PathNodeType pathType = block.getAiPathNodeType(world, pos);
                if (pathType == null || pathType.getDanger() == null) {
                    return true;
                }
            }
            return false;
        }
    }
    return true;
}
Also used : BlockDecorationController(com.minecolonies.coremod.blocks.BlockDecorationController) PathNodeType(net.minecraft.pathfinding.PathNodeType) Direction(net.minecraft.util.Direction) AbstractBlockMinecoloniesConstructionTape(com.minecolonies.api.blocks.decorative.AbstractBlockMinecoloniesConstructionTape) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockDecorationController (com.minecolonies.coremod.blocks.BlockDecorationController)4 BlockPos (net.minecraft.util.math.BlockPos)4 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)2 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 AbstractBlockMinecoloniesConstructionTape (com.minecolonies.api.blocks.decorative.AbstractBlockMinecoloniesConstructionTape)2 IColony (com.minecolonies.api.colony.IColony)2 IColonyManager (com.minecolonies.api.colony.IColonyManager)2 Action (com.minecolonies.api.colony.permissions.Action)2 IWorkOrder (com.minecolonies.api.colony.workorders.IWorkOrder)2 IMessage (com.minecolonies.api.network.IMessage)2 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)2 Log (com.minecolonies.api.util.Log)2 WorkOrderBuildDecoration (com.minecolonies.coremod.colony.workorders.WorkOrderBuildDecoration)2 TileEntityDecorationController (com.minecolonies.coremod.tileentities.TileEntityDecorationController)2 Map (java.util.Map)2 Optional (java.util.Optional)2 BlockState (net.minecraft.block.BlockState)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 PacketBuffer (net.minecraft.network.PacketBuffer)2 PathNodeType (net.minecraft.pathfinding.PathNodeType)2