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);
}
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);
}
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);
}
}
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);
});
}
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);
}
Aggregations