Search in sources :

Example 1 with ChangeFreeToInteractBlockMessage

use of com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage in project minecolonies by ldtteam.

the class ItemScepterPermission method handleAddBlockType.

@NotNull
private static ActionResultType handleAddBlockType(final PlayerEntity playerIn, final World worldIn, final BlockPos pos, final IColonyView iColonyView) {
    final BlockState blockState = iColonyView.getWorld().getBlockState(pos);
    final Block block = blockState.getBlock();
    final ChangeFreeToInteractBlockMessage message = new ChangeFreeToInteractBlockMessage(iColonyView, block, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK);
    Network.getNetwork().sendToServer(message);
    return ActionResultType.SUCCESS;
}
Also used : BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) ChangeFreeToInteractBlockMessage(com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ChangeFreeToInteractBlockMessage

use of com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage in project minecolonies by Minecolonies.

the class WindowPermissionsPage method addBlock.

/**
 * Called when the "addBlock" button has been triggered. Tries to add the content of the input field as block or position to the colony.
 */
private void addBlock() {
    final TextField input = findPaneOfTypeByID(INPUT_BLOCK_NAME, TextField.class);
    final String inputText = input.getText();
    try {
        final Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(inputText));
        if (block != null) {
            building.getColony().addFreeBlock(block);
            Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), block, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK));
        }
    } catch (final ResourceLocationException e) {
    // Do nothing.
    }
    final BlockPos pos = BlockPosUtil.getBlockPosOfString(inputText);
    if (pos != null) {
        Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), pos, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK));
        building.getColony().addFreePosition(pos);
    }
    fillFreeBlockList();
    input.setText("");
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ResourceLocationException(net.minecraft.util.ResourceLocationException) TextField(com.ldtteam.blockout.controls.TextField) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ChangeFreeToInteractBlockMessage(com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage)

Example 3 with ChangeFreeToInteractBlockMessage

use of com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage in project minecolonies by Minecolonies.

the class ItemScepterPermission method handleAddLocation.

@NotNull
private static ActionResultType handleAddLocation(final PlayerEntity playerIn, final World worldIn, final BlockPos pos, final IColonyView iColonyView) {
    final ChangeFreeToInteractBlockMessage message = new ChangeFreeToInteractBlockMessage(iColonyView, pos, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK);
    Network.getNetwork().sendToServer(message);
    return ActionResultType.SUCCESS;
}
Also used : ChangeFreeToInteractBlockMessage(com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ChangeFreeToInteractBlockMessage

use of com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage in project minecolonies by Minecolonies.

the class ItemScepterPermission method handleAddBlockType.

@NotNull
private static ActionResultType handleAddBlockType(final PlayerEntity playerIn, final World worldIn, final BlockPos pos, final IColonyView iColonyView) {
    final BlockState blockState = iColonyView.getWorld().getBlockState(pos);
    final Block block = blockState.getBlock();
    final ChangeFreeToInteractBlockMessage message = new ChangeFreeToInteractBlockMessage(iColonyView, block, ChangeFreeToInteractBlockMessage.MessageType.ADD_BLOCK);
    Network.getNetwork().sendToServer(message);
    return ActionResultType.SUCCESS;
}
Also used : BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) ChangeFreeToInteractBlockMessage(com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with ChangeFreeToInteractBlockMessage

use of com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage in project minecolonies by Minecolonies.

the class WindowPermissionsPage method removeBlock.

private void removeBlock(final Button button) {
    final int row = freeBlocksList.getListElementIndexByPane(button);
    if (row >= 0) {
        @NotNull final List<Block> freeBlocks = building.getColony().getFreeBlocks();
        @NotNull final List<BlockPos> freePositions = building.getColony().getFreePositions();
        if (row < freeBlocks.size()) {
            Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), freeBlocks.get(row), ChangeFreeToInteractBlockMessage.MessageType.REMOVE_BLOCK));
            building.getColony().removeFreeBlock(freeBlocks.get(row));
        } else if (row < freeBlocks.size() + freePositions.size()) {
            final BlockPos freePos = freePositions.get(row - freeBlocks.size());
            Network.getNetwork().sendToServer(new ChangeFreeToInteractBlockMessage(building.getColony(), freePos, ChangeFreeToInteractBlockMessage.MessageType.REMOVE_BLOCK));
            building.getColony().removeFreePosition(freePos);
        }
        fillFreeBlockList();
    }
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) ChangeFreeToInteractBlockMessage(com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage)

Aggregations

ChangeFreeToInteractBlockMessage (com.minecolonies.coremod.network.messages.server.colony.ChangeFreeToInteractBlockMessage)6 NotNull (org.jetbrains.annotations.NotNull)5 Block (net.minecraft.block.Block)4 BlockState (net.minecraft.block.BlockState)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextField (com.ldtteam.blockout.controls.TextField)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 ResourceLocationException (net.minecraft.util.ResourceLocationException)1