use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.
the class ClientCommandTest method testCommand.
private int testCommand(CommandContext<CommandSourceStack> context) {
context.getSource().sendSuccess(new TextComponent("Input: " + ResourceLocationArgument.getId(context, "block")), false);
context.getSource().sendSuccess(new TextComponent("Teams: " + context.getSource().getAllTeams()), false);
context.getSource().sendSuccess(new TextComponent("Players: " + context.getSource().getOnlinePlayerNames()), false);
context.getSource().sendSuccess(new TextComponent("First recipe: " + context.getSource().getRecipeNames().findFirst().get()), false);
context.getSource().sendSuccess(new TextComponent("Levels: " + context.getSource().levels()), false);
context.getSource().sendSuccess(new TextComponent("Registry Access: " + context.getSource().registryAccess()), false);
return 0;
}
use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.
the class CommandEventTest method onCommand.
@SubscribeEvent
public static void onCommand(CommandEvent event) {
CommandDispatcher<CommandSourceStack> dispatcher = event.getParseResults().getContext().getDispatcher();
List<ParsedCommandNode<CommandSourceStack>> nodes = event.getParseResults().getContext().getNodes();
CommandSourceStack source = event.getParseResults().getContext().getSource();
// test: when the /time command is used with no arguments, automatically add default arguments (/time set day)
if (nodes.size() == 1 && nodes.get(0).getNode() == dispatcher.getRoot().getChild("time")) {
event.setParseResults(dispatcher.parse("time set day", source));
return;
}
// test: whenever a player uses the /give command, let everyone on the server know
if (nodes.size() > 0 && nodes.get(0).getNode() == dispatcher.getRoot().getChild("give")) {
String msg = source.getTextName() + " used the give command: " + event.getParseResults().getReader().getString();
source.getServer().getPlayerList().getPlayers().forEach(player -> player.sendMessage(new TextComponent(msg), player.getUUID()));
return;
}
// this is annoying so I disabled it
// test: when the /kill command is used with no arguments, throw a custom exception
// if (nodes.size() == 1 && nodes.get(0).getNode() == dispatcher.getRoot().getChild("kill"))
// {
// event.setException(new CommandRuntimeException(new TextComponent("You tried to use the /kill command with no arguments")));
// event.setCanceled(true);
// return;
// }
}
use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.
the class HandshakeHandler method handleRegistryLoading.
private boolean handleRegistryLoading(final Supplier<NetworkEvent.Context> contextSupplier) {
// We use a countdown latch to suspend the impl thread pending the client thread processing the registry data
AtomicBoolean successfulConnection = new AtomicBoolean(false);
CountDownLatch block = new CountDownLatch(1);
contextSupplier.get().enqueueWork(() -> {
LOGGER.debug(FMLHSMARKER, "Injecting registry snapshot from server.");
final Multimap<ResourceLocation, ResourceLocation> missingData = GameData.injectSnapshot(registrySnapshots, false, false);
LOGGER.debug(FMLHSMARKER, "Snapshot injected.");
if (!missingData.isEmpty()) {
LOGGER.error(FMLHSMARKER, "Missing registry data for impl connection:\n{}", LogMessageAdapter.adapt(sb -> missingData.forEach((reg, entry) -> sb.append("\t").append(reg).append(": ").append(entry).append('\n'))));
}
successfulConnection.set(missingData.isEmpty());
block.countDown();
});
LOGGER.debug(FMLHSMARKER, "Waiting for registries to load.");
try {
block.await();
} catch (InterruptedException e) {
Thread.interrupted();
}
if (successfulConnection.get()) {
LOGGER.debug(FMLHSMARKER, "Registry load complete, continuing handshake.");
} else {
LOGGER.error(FMLHSMARKER, "Failed to load registry, closing connection.");
this.manager.disconnect(new TextComponent("Failed to synchronize registry data from server, closing connection"));
}
return successfulConnection.get();
}
use of net.minecraft.network.chat.TextComponent in project MinecraftForge by MinecraftForge.
the class ContainerTypeTest method onRightClick.
private void onRightClick(PlayerInteractEvent.RightClickBlock event) {
if (!event.getWorld().isClientSide && event.getHand() == InteractionHand.MAIN_HAND) {
if (event.getWorld().getBlockState(event.getPos()).getBlock() == Blocks.SPONGE) {
String text = "Hello World!";
NetworkHooks.openGui((ServerPlayer) event.getPlayer(), new MenuProvider() {
@Override
public AbstractContainerMenu createMenu(int p_createMenu_1_, Inventory p_createMenu_2_, Player p_createMenu_3_) {
SimpleContainer inv = new SimpleContainer(9);
for (int i = 0; i < inv.getContainerSize(); i++) {
inv.setItem(i, new ItemStack(Items.DIAMOND));
}
return new TestContainer(p_createMenu_1_, inv, text);
}
@Override
public Component getDisplayName() {
return new TextComponent("Test");
}
}, extraData -> {
extraData.writeUtf(text);
});
}
}
}
Aggregations