use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class AddPackFinderEventTest method addPackFinders.
@SubscribeEvent
public static void addPackFinders(AddPackFindersEvent event) {
try {
if (event.getPackType() == PackType.CLIENT_RESOURCES) {
var resourcePath = ModList.get().getModFileById(MODID).getFile().findResource("test_nested_resource_pack");
var pack = new PathResourcePack(ModList.get().getModFileById(MODID).getFile().getFileName() + ":" + resourcePath, resourcePath);
var metadataSection = pack.getMetadataSection(PackMetadataSection.SERIALIZER);
if (metadataSection != null) {
event.addRepositorySource((packConsumer, packConstructor) -> packConsumer.accept(packConstructor.create("builtin/add_pack_finders_test", new TextComponent("display name"), false, () -> pack, metadataSection, Pack.Position.BOTTOM, PackSource.BUILT_IN, false)));
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class DataGeneratorTest method gatherData.
@SubscribeEvent
public static void gatherData(GatherDataEvent event) {
GSON = new GsonBuilder().registerTypeAdapter(Variant.class, new Variant.Deserializer()).registerTypeAdapter(ItemTransforms.class, new ItemTransforms.Deserializer()).registerTypeAdapter(ItemTransform.class, new ItemTransform.Deserializer()).create();
DataGenerator gen = event.getGenerator();
if (event.includeClient()) {
gen.addProvider(new Lang(gen));
// Let blockstate provider see generated item models by passing its existing file helper
ItemModelProvider itemModels = new ItemModels(gen, event.getExistingFileHelper());
gen.addProvider(itemModels);
gen.addProvider(new BlockStates(gen, itemModels.existingFileHelper));
gen.addProvider(new SoundDefinitions(gen, event.getExistingFileHelper()));
}
if (event.includeServer()) {
gen.addProvider(new Recipes(gen));
gen.addProvider(new Tags(gen, event.getExistingFileHelper()));
gen.addProvider(new Advancements(gen, event.getExistingFileHelper()));
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class RenderLocalPlayerTest method onItemRightClick.
@SubscribeEvent
public static void onItemRightClick(final PlayerInteractEvent.RightClickItem event) {
if (ENABLED && event.getItemStack().getItem() == Items.STICK) {
Minecraft mc = Minecraft.getInstance();
if (mc.getCameraEntity() != mc.player) {
mc.setCameraEntity(mc.player);
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCanceled(true);
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class RenderLocalPlayerTest method onItemRightClickEntity.
@SubscribeEvent
public static void onItemRightClickEntity(final PlayerInteractEvent.EntityInteract event) {
if (ENABLED && event.getItemStack().getItem() == Items.STICK) {
Minecraft mc = Minecraft.getInstance();
if (mc.getCameraEntity() == mc.player) {
mc.setCameraEntity(event.getTarget());
event.setCancellationResult(InteractionResult.SUCCESS);
event.setCanceled(true);
}
}
}
use of net.minecraftforge.eventbus.api.SubscribeEvent 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;
// }
}
Aggregations