Search in sources :

Example 6 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class BlockAlmostInfiniteCapacitor method sendPlayerStatus.

@Override
protected void sendPlayerStatus(World world, BlockPos pos, PlayerEntity player) {
    LongEnergyStack stack = ((TileAlmostInfiniteCapacitor) world.getBlockEntity(pos)).getStorage().status();
    double percent = 100 * (double) stack.getAmount() / (double) Long.MAX_VALUE;
    player.displayClientMessage(new StringTextComponent(String.format("Energy Amount: %,d  %,.4f%%", stack.getAmount(), percent)), false);
}
Also used : LongEnergyStack(com.cjm721.overloaded.storage.stacks.intint.LongEnergyStack) StringTextComponent(net.minecraft.util.text.StringTextComponent)

Example 7 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class BlockTrueInfiniteCapacitor method sendPlayerStatus.

@Override
protected void sendPlayerStatus(World world, BlockPos pos, PlayerEntity player) {
    BigIntEnergyStack stack = ((TileTrueInfiniteCapacitor) world.getBlockEntity(pos)).getStorage().bigStatus();
    player.displayClientMessage(new StringTextComponent(String.format("Energy Amount: %,d Bits: %,d", stack.getAmount(), stack.getAmount().bitLength())), false);
}
Also used : StringTextComponent(net.minecraft.util.text.StringTextComponent) BigIntEnergyStack(com.cjm721.overloaded.storage.stacks.bigint.BigIntEnergyStack)

Example 8 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class AbstractBlockHyperReceiver method use.

@Override
@Nonnull
public ActionResultType use(@Nonnull BlockState state, @Nonnull World world, @Nonnull BlockPos pos, PlayerEntity player, @Nonnull Hand hand, @Nonnull BlockRayTraceResult rayTraceResult) {
    ItemStack heldItem = player.getItemInHand(hand);
    if (heldItem.getItem().equals(ModItems.linkingCard)) {
        CompoundNBT tag = heldItem.getTag();
        if (tag == null) {
            tag = new CompoundNBT();
        }
        ResourceLocation worldId = world.dimension().location();
        writeNodeData(tag, worldId, pos);
        heldItem.setTag(tag);
        if (world.isClientSide) {
            player.displayClientMessage(new StringTextComponent(String.format("Recorded: World: %s Position: %s", worldId, pos.toShortString())), false);
        }
        return ActionResultType.CONSUME;
    } else {
        return super.use(state, world, pos, player, hand, rayTraceResult);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 9 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project Overloaded by CJ-MC-Mods.

the class NoClipUpdateHandler method clientSide.

@OnlyIn(Dist.CLIENT)
private void clientSide(NoClipStatusMessage message, Supplier<NetworkEvent.Context> ctx) {
    ctx.get().enqueueWork(() -> {
        ArmorEventHandler.setNoClip(Minecraft.getInstance().player, message.isEnabled());
        Minecraft.getInstance().player.displayClientMessage(new StringTextComponent("No Clip: " + message.isEnabled()), true);
    });
}
Also used : StringTextComponent(net.minecraft.util.text.StringTextComponent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 10 with StringTextComponent

use of net.minecraft.util.text.StringTextComponent in project AgriCraft by AgriCraft.

the class DebugModeIGrowable method debugActionBlockClicked.

@Override
public void debugActionBlockClicked(ItemStack stack, ItemUseContext context) {
    if (context.getWorld().isRemote) {
        return;
    }
    BlockPos pos = context.getPos();
    PlayerEntity player = context.getPlayer();
    World world = context.getWorld();
    // Start with the position of the block that was clicked on. '7' is gray. Btw, the chat font is not fixed width. :(
    StringBuilder outputRaw = new StringBuilder(String.format("`7%1$4d,%2$4d,%3$4d`r ", pos.getX(), pos.getY(), pos.getZ()));
    // Check if the clicked on block has the IGrowable interface.
    final IGrowable crop = WorldHelper.getBlock(world, pos, IGrowable.class).orElse(null);
    if (crop == null) {
        // If it does not, add a nicely formatted report, then skip onward.
        outputRaw.append(chatNotIG);
    } else if (world instanceof ServerWorld) {
        // Otherwise run the tests and record the results.
        BlockState state = world.getBlockState(pos);
        // canGrow
        outputRaw.append(crop.canGrow(world, pos, state, false) ? chatTrue : chatFalse);
        // canUseBonemeal
        outputRaw.append(crop.canUseBonemeal(world, world.rand, pos, state) ? chatTrue : chatFalse);
        // grow
        crop.grow((ServerWorld) world, world.rand, pos, state);
        // It's also helpful to also make clear what block was being tested.
        // '3' is dark aqua.
        outputRaw.append("`3");
        outputRaw.append(crop.toString().replaceFirst("Block", ""));
        outputRaw.append("`r");
    }
    // Ellipsis are added as a clue that there's more text.
    // '8' is dark gray.
    outputRaw.append(" `8[...]`r");
    // Create a hover box with explanatory information.
    StringTextComponent hoverComponent = new StringTextComponent(MessageUtil.colorize(chatInfo));
    HoverEvent hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent);
    // Turn the output String into a chat message.
    StringTextComponent outputComponent = new StringTextComponent(MessageUtil.colorize(outputRaw.toString()));
    // Add the hover box to the chat message.
    outputComponent.getStyle().setHoverEvent(hoverEvent);
    // Now send the completed chat message.
    player.sendMessage(outputComponent, Util.DUMMY_UUID);
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) HoverEvent(net.minecraft.util.text.event.HoverEvent) BlockState(net.minecraft.block.BlockState) IGrowable(net.minecraft.block.IGrowable) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

StringTextComponent (net.minecraft.util.text.StringTextComponent)31 ItemStack (net.minecraft.item.ItemStack)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)7 TileEntity (net.minecraft.tileentity.TileEntity)5 Nonnull (javax.annotation.Nonnull)4 BlockPos (net.minecraft.util.math.BlockPos)4 ITextComponent (net.minecraft.util.text.ITextComponent)4 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)4 IGenericDataStorage (com.cjm721.overloaded.storage.IGenericDataStorage)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)3 TileBPMicroblock (com.bluepowermod.tile.TileBPMicroblock)2 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)2 ItemSeedBag (com.infinityraider.agricraft.content.tools.ItemSeedBag)2 BlockState (net.minecraft.block.BlockState)2 Minecraft (net.minecraft.client.Minecraft)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 Vector3d (net.minecraft.util.math.vector.Vector3d)2