Search in sources :

Example 26 with Style

use of net.minecraft.util.text.Style in project Charset by CharsetMC.

the class CommandCharset method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length >= 1) {
        String[] args2 = new String[args.length - 1];
        System.arraycopy(args, 1, args2, 0, args.length - 1);
        SubCommand command = SUB_COMMAND_MAP.get(args[0].toLowerCase());
        if (command != null) {
            if (sender.canUseCommand(command.getPermissionLevel(), getName())) {
                command.execute(server, sender, args2);
            } else {
                sender.sendMessage(new TextComponentTranslation("commands.generic.permission").setStyle(new Style().setColor(TextFormatting.RED)));
            }
        } else {
            sender.sendMessage(new TextComponentTranslation("commands.generic.parameter.invalid", args[0]).setStyle(new Style().setColor(TextFormatting.RED)));
        }
    } else {
        sender.sendMessage(new TextComponentString(getUsage(sender)));
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 27 with Style

use of net.minecraft.util.text.Style in project MC-Prefab by Brian-Wuest.

the class Structure method BuildStructure.

/**
 * This is the main building method for this structure.
 *
 * @param configuration The configuration the user updated.
 * @param world The current world.
 * @param originalPos The block the user clicked on.
 * @param assumedNorth This should always be "NORTH" when the file is based on a scan.
 * @param player The player requesting the structure.
 * @return True if the build can occur, otherwise false.
 */
public boolean BuildStructure(StructureConfiguration configuration, World world, BlockPos originalPos, EnumFacing assumedNorth, EntityPlayer player) {
    BlockPos startBlockPos = this.clearSpace.getStartingPosition().getRelativePosition(originalPos, this.clearSpace.getShape().getDirection(), configuration.houseFacing);
    BlockPos endBlockPos = startBlockPos.offset(configuration.houseFacing.rotateYCCW(), this.clearSpace.getShape().getWidth() - 1).offset(configuration.houseFacing.getOpposite(), this.clearSpace.getShape().getWidth() - 1).offset(EnumFacing.UP, this.clearSpace.getShape().getHeight());
    // Make sure this structure can be placed here.
    if (!BuildingMethods.CheckBuildSpaceForAllowedBlockReplacement(configuration, world, startBlockPos, endBlockPos, player)) {
        // Send a message to the player saying that the structure could not
        // be built.
        player.sendMessage(new TextComponentTranslation(GuiLangKeys.GUI_STRUCTURE_NOBUILD).setStyle(new Style().setColor(TextFormatting.GREEN)));
        return false;
    }
    if (!this.BeforeBuilding(configuration, world, originalPos, assumedNorth, player)) {
        // First, clear the area where the structure will be built.
        this.ClearSpace(configuration, world, originalPos, assumedNorth);
        boolean blockPlacedWithCobbleStoneInstead = false;
        // Now place all of the blocks.
        for (BuildBlock block : this.getBlocks()) {
            Block foundBlock = Block.REGISTRY.getObject(block.getResourceLocation());
            if (foundBlock != null) {
                IBlockState blockState = foundBlock.getDefaultState();
                BuildBlock subBlock = null;
                // Check if water should be replaced with cobble.
                if (!this.WaterReplacedWithCobbleStone(configuration, block, world, originalPos, assumedNorth, foundBlock, blockState, player) && !this.CustomBlockProcessingHandled(configuration, block, world, originalPos, assumedNorth, foundBlock, blockState, player)) {
                    block = BuildBlock.SetBlockState(configuration, world, originalPos, assumedNorth, block, foundBlock, blockState, this);
                    if (block.getSubBlock() != null) {
                        foundBlock = Block.REGISTRY.getObject(block.getSubBlock().getResourceLocation());
                        blockState = foundBlock.getDefaultState();
                        subBlock = BuildBlock.SetBlockState(configuration, world, originalPos, assumedNorth, block.getSubBlock(), foundBlock, blockState, this);
                    }
                    if (subBlock != null) {
                        block.setSubBlock(subBlock);
                    }
                    if (!block.getHasFacing()) {
                        if (subBlock != null) {
                            block.setSubBlock(subBlock);
                        }
                        if (foundBlock instanceof BlockFlowerPot || foundBlock instanceof BlockCarpet || foundBlock instanceof BlockBed) {
                            this.priorityThreeBlocks.add(block);
                        } else {
                            this.priorityOneBlocks.add(block);
                        }
                    } else {
                        // These blocks may be attached to other facing blocks and must be done later.
                        if (foundBlock instanceof BlockTorch || foundBlock instanceof BlockSign || foundBlock instanceof BlockLever || foundBlock instanceof BlockButton || foundBlock instanceof BlockBed) {
                            this.priorityThreeBlocks.add(block);
                        } else {
                            this.priorityTwoBlocks.add(block);
                        }
                    }
                }
            } else {
                // Cannot find this block in the registry. This can happen if a structure file has a mod block that no longer exists.
                // In this case, print an informational message and replace it with cobblestone.
                String blockTypeNotFound = block.getResourceLocation().toString();
                block = BuildBlock.SetBlockState(configuration, world, originalPos, assumedNorth, block, Blocks.COBBLESTONE, Blocks.COBBLESTONE.getDefaultState(), this);
                this.priorityOneBlocks.add(block);
                if (!blockPlacedWithCobbleStoneInstead) {
                    blockPlacedWithCobbleStoneInstead = true;
                    FMLLog.log.warn("A Block was in the structure, but it is not registred. This block was replaced with vanilla cobblestone instead. Block type not found: [" + blockTypeNotFound + "]");
                }
            }
        }
        this.configuration = configuration;
        this.world = world;
        this.assumedNorth = assumedNorth;
        this.originalPos = originalPos;
        if (ModEventHandler.structuresToBuild.containsKey(player)) {
            ModEventHandler.structuresToBuild.get(player).add(this);
        } else {
            ArrayList<Structure> structures = new ArrayList<Structure>();
            structures.add(this);
            ModEventHandler.structuresToBuild.put(player, structures);
        }
    }
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos)

Example 28 with Style

use of net.minecraft.util.text.Style in project MC-Prefab by Brian-Wuest.

the class ItemInstantBridge method BuildBridge.

private boolean BuildBridge(World worldIn, EntityPlayer playerIn, BlockPos originalBlockPos) {
    EnumFacing playerFacing = playerIn.getHorizontalFacing();
    BlockPos startingPos = originalBlockPos.offset(playerFacing.rotateYCCW(), 2);
    BlockPos endPos = originalBlockPos.offset(playerFacing, 50).offset(playerFacing.rotateY(), 2).up(2);
    if (!BuildingMethods.CheckBuildSpaceForAllowedBlockReplacement(null, worldIn, startingPos, endPos, playerIn)) {
        playerIn.sendMessage(new TextComponentTranslation(GuiLangKeys.GUI_STRUCTURE_NOBUILD).setStyle(new Style().setColor(TextFormatting.GREEN)));
        return false;
    }
    for (int i = 0; i < 50; i++) {
        BlockPos currentPos = originalBlockPos.offset(playerFacing, i).up();
        // Place the floor
        BuildingMethods.ReplaceBlock(worldIn, currentPos, Blocks.COBBLESTONE);
        BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateYCCW()), Blocks.COBBLESTONE);
        BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateYCCW(), 2), Blocks.COBBLESTONE);
        BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateY()), Blocks.COBBLESTONE);
        BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateY(), 2), Blocks.COBBLESTONE);
        // Build the walls.
        BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateYCCW(), 2).up(), Blocks.COBBLESTONE_WALL);
        BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateY(), 2).up(), Blocks.COBBLESTONE_WALL);
        if (i % 6 == 0) {
            // Place torches.
            BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateYCCW(), 2).up(2), Blocks.TORCH);
            BuildingMethods.ReplaceBlock(worldIn, currentPos.offset(playerFacing.rotateY(), 2).up(2), Blocks.TORCH);
        }
    }
    return true;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) Style(net.minecraft.util.text.Style)

Example 29 with Style

use of net.minecraft.util.text.Style in project MC-Prefab by Brian-Wuest.

the class HouseConfiguration method ConfigurationSpecificBuildStructure.

/**
 * This is used to actually build the structure as it creates the structure instance and calls build structure.
 * @param player The player which requested the build.
 * @param world The world instance where the build will occur.
 * @param hitBlockPos This hit block position.
 */
@Override
protected void ConfigurationSpecificBuildStructure(EntityPlayer player, World world, BlockPos hitBlockPos) {
    boolean houseBuilt = true;
    if (this.houseStyle == HouseConfiguration.HouseStyle.BASIC) {
        // We hit a block, let's start building!!!!!
        BlockPos startingPosition = hitBlockPos.up();
        // Get the new "North" facing. This is the orientation of
        // the house and all building will be based on this.
        EnumFacing northFace = this.houseFacing;
        // Get the "South" facing of the house to make rotating
        // easier.
        EnumFacing southFace = northFace.getOpposite();
        // Set the "North East" corner.
        /*ItemStartHouse.NorthEastCorner = startingPosition.offset(northFace, (int) Math.floor(configuration.houseDepth / 2) + 1)
					.offset(northFace.rotateY(), (int) Math.floor(configuration.houseWidth / 2) + 1);*/
        HouseConfiguration.NorthEastCorner = startingPosition.offset(southFace).offset(northFace.rotateY());
        // Set the "South East" corner.
        HouseConfiguration.SouthEastCorner = HouseConfiguration.NorthEastCorner.offset(southFace, this.houseDepth + 1);
        // Set the "South West" corner.
        HouseConfiguration.SouthWestCorner = HouseConfiguration.SouthEastCorner.offset(northFace.rotateYCCW(), this.houseWidth + 1);
        // Set the "North West" corner.
        HouseConfiguration.NorthWestCorner = HouseConfiguration.NorthEastCorner.offset(northFace.rotateYCCW(), this.houseWidth + 1);
        // Put the starting position in the middle of the house as that's what the rest of the methods expect.
        startingPosition = HouseConfiguration.NorthEastCorner.offset(southFace, (int) Math.floor(this.houseDepth / 2) + 1).offset(northFace.rotateYCCW(), (int) Math.floor(this.houseWidth / 2) + 1);
        BlockPos endBlockPos = startingPosition.offset(northFace.rotateYCCW(), this.houseWidth + 11).offset(southFace, this.houseDepth + 11).offset(EnumFacing.UP, 15);
        // Make sure this structure can be placed here.
        if (!BuildingMethods.CheckBuildSpaceForAllowedBlockReplacement(this, world, startingPosition, endBlockPos, player)) {
            // Send a message to the player saying that the structure could not
            // be built.
            player.sendMessage(new TextComponentTranslation(GuiLangKeys.GUI_STRUCTURE_NOBUILD).setStyle(new Style().setColor(TextFormatting.GREEN)));
            return;
        }
        // Clear the space before the user is teleported. This
        // is in-case they right-click on a space that is only 1
        // block tall.
        BuildingMethods.ClearSpace(world, HouseConfiguration.NorthEastCorner, this.houseWidth, 15, this.houseDepth, northFace);
        // Build the basic structure.
        HouseConfiguration.BuildStructure(world, startingPosition, this, northFace);
        // Build the interior.
        HouseConfiguration.BuildInterior(world, startingPosition, player, this, northFace);
        // Set up the exterior.
        HouseConfiguration.BuildExterior(world, startingPosition, player, this, northFace);
        if (this.addMineShaft && startingPosition.getY() > 15) {
            // Set up the mineshaft.
            HouseConfiguration.PlaceMineShaft(world, startingPosition, this.houseDepth, northFace);
        }
        houseBuilt = true;
    } else {
        // Build the alternate starter house instead.
        StructureAlternateStart structure = StructureAlternateStart.CreateInstance(this.houseStyle.getStructureLocation(), StructureAlternateStart.class);
        houseBuilt = structure.BuildStructure(this, world, hitBlockPos, EnumFacing.NORTH, player);
    }
    // The house was successfully built, remove the item from the inventory.
    if (houseBuilt) {
        EntityPlayerConfiguration playerConfig = EntityPlayerConfiguration.loadFromEntityData((EntityPlayerMP) player);
        playerConfig.builtStarterHouse = true;
        playerConfig.saveToPlayer(player);
        player.inventory.clearMatchingItems(ModRegistry.StartHouse(), -1, 1, null);
        player.inventoryContainer.detectAndSendChanges();
        // Make sure to send a message to the client to sync up the server player information and the client player information.
        Prefab.network.sendTo(new PlayerEntityTagMessage(playerConfig.getModIsPlayerNewTag(player)), (EntityPlayerMP) player);
    }
}
Also used : StructureAlternateStart(com.wuest.prefab.StructureGen.CustomStructures.StructureAlternateStart) PlayerEntityTagMessage(com.wuest.prefab.Proxy.Messages.PlayerEntityTagMessage) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayerConfiguration(com.wuest.prefab.Config.EntityPlayerConfiguration) EnumFacing(net.minecraft.util.EnumFacing) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos)

Example 30 with Style

use of net.minecraft.util.text.Style in project BiomeTweaker by superckl.

the class CommandInfo method execute.

@Override
public void execute(final MinecraftServer server, final ICommandSender sender, final String[] args) throws CommandException {
    final BlockPos coord = sender.getPosition();
    final World world = sender.getEntityWorld();
    if ((coord != null) && (world != null)) {
        final JsonObject obj = BiomeHelper.fillJsonObject(world.getBiome(coord), coord.getX(), coord.getY(), coord.getZ());
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.info.output.text").setStyle(new Style().setColor(TextFormatting.AQUA)));
        final Style gold = new Style().setColor(TextFormatting.GOLD);
        final Gson gson = new GsonBuilder().setPrettyPrinting().create();
        for (final Entry<String, JsonElement> entry : obj.entrySet()) if (entry.getValue().isJsonArray())
            // It looks hideous in MC chat.
            sender.sendMessage(new TextComponentString(entry.getKey() + ": Check the output files.").setStyle(gold));
        else
            sender.sendMessage(new TextComponentString(entry.getKey() + ": " + gson.toJson(entry.getValue())).setStyle(gold));
    } else
        sender.sendMessage(new TextComponentTranslation("biometweaker.msg.info.invalsender.text").setStyle(new Style().setColor(TextFormatting.RED)));
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) GsonBuilder(com.google.gson.GsonBuilder) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Style(net.minecraft.util.text.Style) Gson(com.google.gson.Gson) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString) World(net.minecraft.world.World) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

Style (net.minecraft.util.text.Style)51 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)30 TextComponentString (net.minecraft.util.text.TextComponentString)21 ITextComponent (net.minecraft.util.text.ITextComponent)17 ClickEvent (net.minecraft.util.text.event.ClickEvent)10 BlockPos (net.minecraft.util.math.BlockPos)9 CommandException (net.minecraft.command.CommandException)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 ItemStack (net.minecraft.item.ItemStack)4 World (net.minecraft.world.World)4 Colony (com.minecolonies.coremod.colony.Colony)3 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)3 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 GameProfile (com.mojang.authlib.GameProfile)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 HoverEvent (net.minecraft.util.text.event.HoverEvent)2 Biome (net.minecraft.world.biome.Biome)2 FluidStack (net.minecraftforge.fluids.FluidStack)2