JACOB event registration - java

I'm trying to use JACOB to obtain a callback whenever a slide show starts or ends using the following:
public class Test {
public static void main(String[] args) {
ActiveXComponent oApp = new ActiveXComponent("PowerPoint.Application");
Dispatch presentations = oApp.getProperty("Presentations").toDispatch();
Dispatch presentation = Dispatch.call(presentations, "Open", "C:\\Users\\Bob\\Documents\\test.ppt").toDispatch();
new DispatchEvents(oApp, new Handler());
}
}
public class Handler {
public void SlideShowBegin(Variant[] args) {
System.out.println("here");
}
}
However, I'm coming a bit unstuck, the result of the above is:
GetEventIID: couldn't get IProvideClassInfo
Exception in thread "main" com.jacob.com.ComFailException: Can't find event iid
at com.jacob.com.DispatchEvents.init3(Native Method)
at com.jacob.com.DispatchEvents.<init>(DispatchEvents.java:138)
at com.jacob.com.DispatchEvents.<init>(DispatchEvents.java:99)
at com.jacob.com.DispatchEvents.<init>(DispatchEvents.java:72)
at tester.Test.main(Test.java:28)
Does anyone have any ideas? Searching has come up pretty short. I've tried using the 4 argument constructor of DispatchEvents, supplying "Powerpoint.Application" and the full path to the powerpoint exe as the last two arguments, but no difference.

Related

Why do I get "Unidentified mapping from registry minecraft:block"?

I am learning how to write Minecraft mods (version 1.14.4) and was able to make an item. Now I am trying to make a block. I am following this tutorial video which actually covers 1.14.3, but I thought it would be close enough.
I am currently getting this error:
[20Mar2020 14:09:10.522] [Server thread/INFO] [net.minecraftforge.registries.ForgeRegistry/REGISTRIES]: Registry Block: Found a missing id from the world examplemod:examplemod
[20Mar2020 14:09:10.613] [Server thread/ERROR] [net.minecraftforge.registries.GameData/REGISTRIES]: Unidentified mapping from registry minecraft:block
examplemod:examplemod: 676
I also get presented with this at runtime:
I have tried messing around with how i'm naming the registries but I just can't seem to pin down what the issue is. Maybe i'm not formatting my json files correctly?
Note that ItemList and BlockList are just classes that contain static instances of each Block/Item I have created.
ExampleMod.java:
// The value here should match an entry in the META-INF/mods.toml file
#Mod(ExampleMod.MOD_ID)
public class ExampleMod
{
// Directly reference a log4j logger.
private static final Logger LOGGER = LogManager.getLogger();
public static final String MOD_ID = "examplemod";
public ExampleMod() {
// Register the setup method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
// Register the enqueueIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
// Register the processIMC method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
// Register the doClientStuff method for modloading
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event)
{
// some preinit code
LOGGER.info("HELLO FROM PREINIT");
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
}
private void doClientStuff(final FMLClientSetupEvent event) {
// do something that can only be done on the client
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
}
private void enqueueIMC(final InterModEnqueueEvent event)
{
// some example code to dispatch IMC to another mod
InterModComms.sendTo(ExampleMod.MOD_ID, "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
}
private void processIMC(final InterModProcessEvent event)
{
// some example code to receive and process InterModComms from other mods
LOGGER.info("Got IMC {}", event.getIMCStream().
map(m->m.getMessageSupplier().get()).
collect(Collectors.toList()));
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
#SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
// do something when the server starts
LOGGER.info("HELLO from server starting");
}
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
#Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
#SubscribeEvent
public static void onItemsRegistry(final RegistryEvent.Register<Item> blockItemEvent)
{
ItemList.bomb_item = new Item(new Item.Properties().group(ItemGroup.COMBAT));
ItemList.bomb_item.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "bomb_item"));
ItemList.mystery_block = new BlockItem(BlockList.mystery_block, new Item.Properties().group(ItemGroup.MISC));
ItemList.mystery_block.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "mystery_block"));
blockItemEvent.getRegistry().registerAll(ItemList.bomb_item, ItemList.mystery_block);
LOGGER.info("Items registered.");
}
#SubscribeEvent
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
BlockList.mystery_block = new Block(Block.Properties.create(Material.CAKE)
.hardnessAndResistance(2.0f, 2.0f)
.sound(SoundType.GLASS));
BlockList.mystery_block.setRegistryName(new ResourceLocation(MOD_ID, "mystery_block"));
blockRegistryEvent.getRegistry().registerAll(BlockList.mystery_block);
LOGGER.info("Blocks registered.");
}
}
}
blockstates/mystery_block.json:
{
"variants": {
"": {
"model": "examplemod:block/mystery_block"
}
}
}
models/block/mystery_block.json:
{
"parent": "block/cube_all",
"textures": {
"all": "examplemod:block/mystery_block"
}
}
models/item/mystery_block.json:
{
"parent": "examplemod:block/mystery_block"
}
All that means is that at some point you had a block registered as "examplemod:examplemod", and now you don't. You can safely ignore the message. If you start a new world instead of opening an old one, you won't get that message.
As an aside, HarryTalks is not a recommended way to learn to mod (on the Minecraft Forge forums ). Apparently he uses several bad practices (I have not actually used them).
Alternative suggestions are Cadiboo's example mod, or McJty's tutorials.

I/O using windowbuilder in eclipse for a java application

I've never used java windowbuilder before, however I'm trying to test it with my program which performs operations on sets. It's a Gradle project. I wrote all classes in the default package (I knew that it's discouraged just when I was finished). The program reads a line of operations on sets, parses it and prints the result and keeps doing that while there is a new line input from the user.
I'm trying to make a simple GUI for this program using windowbuilder but I can't figure out how to run the main class in the windowbuilder class and make it take input from a jtextfield and prints output.
My main looks like this:
public static void main(String[] argv) {
new Main().start();
}
private void start() {
hmap = new HashMap<IdentifierInterface, SetInterface<BigInteger>>();
Scanner in = new Scanner(System.in);
// While there is input, read line and parse it.
while (in.hasNextLine()) {
try {
String statement = in.nextLine();
if (statement.trim().isEmpty()) {
System.out.println("error, no statement");
} else {
Scanner statementScanner = new Scanner(statement);
readStatement(statementScanner);
}
} catch (APException e) {
System.out.printf("%s\n", e.getMessage());
}
}
}
I made a new windowbuilder class, with the buttons and text fields, but I got stuck on how to run my main inside the windowbuilder. Your help is appreciated. Thanks in advance.
Eclipse RCP applications are OSGi plug-ins; they do not have a main() method.
Instead your Main class should look like this:
package com.myplugin;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Main implements BundleActivator {
#Override
public void start(BundleContext bundleContext) throws Exception {
// Copy your start logic here
}
}
Then edit META-INF/MANIFEST.MF file and set for example
Bundle-Activator: com.myplugin.Main
This makes your Main class the activator of the plug-in: start() will be invoked at load.

Java Variables in Threads

I've read a few question/answers here but am still a hair confused on how java threading and variables work.
My software opens a continuous URL listener for some events connecting some jacked up version of the REST API, but I'll digress. So here's a summarized block of code.
public static void main(String[] args) {
//open the long-running URL
conn = (HttpURLConnection) url.openConnection();
// Start to receive the event notification.
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
// Read a complete event. Process the event.
String str = sb.toString();
sb.delete(0, sb.length());
// Parse the alarm and send to the sub-processor if necessary
log4j.debug("Start Event Parsing");
ParseAlarm.parseXML(str);
Thread newAlarm = new Thread(new CreateAlarm());
newAlarm.start();
}
Mind you this is all to fix a bug where if a 2nd event is received before the parsing completes, one of them gets lost.
If I move ParseAlarm.parseXML(str) into the newAlarm thread (which fires additional threads to maintain order) do all of the sub-threads have access to the public variables (some are arrays, some are ints/strings) declared in parseXML or do I need to pass the variables to each sub-thread?
If the public variables declared in parseXML are available to all of the sub-threads of newAlarm, what happens if newAlarm is triggered again by the main script? Do the public parseXML variables clash with the ones in the other thread?
ParseAlarm is as such. Sparing the irreverent portions of code. Mind you it's not setup for threading yet.
public class ParseAlarm {
public static int intAlarmID;
public static String strAlarmDesc;
public static Map<String, String> mXML = new HashMap<String, String>();
public static void ParseXML(String strXML) throws Exception {
for (int i = 0; i < arElementList.length; i++) {
//parse the elements in the XML
}
// Create the alarm ID as an integer for the alarm acknowledgement and the alarm description for the filter
intAlarmID = Integer.parseInt(mXML.get("id"));
strAlarmDesc = mXML.get("alarmDesc");
}
}
I have been able to access the variables declared public from other threads by referencing the them as such:
public static Map mAlarm = ParseAlarm.mXML;
private int intID = ParseAlarm.intAlarmID;
Is this not supposed to happen or am I completely doing this wrong?

How to shutdown akka from java

I have an akka (akka-actor_2.11) application that we use for stress testing one of our systems. The top level actor called RunCoordinatorActor is able to know based on responses coming from its subordinates when the work is finished.
When the work is finished the RunCoordinatorActor makes a call to getContext().system().shutdown() and then in the main method there is a loop checking for the system.isTerminated() call to return true. All works fine and I am happy with the way it works. However both system.sutdown() and system.isTerminated() methods are marked as deprecated and I am trying to figure out the right way to implement a graceful shutdown without using them.
Here is my main class:
public static void main(String[] args) throws Exception {
if (new ArgumentsValidator().validate(args)) {
// If the arguments are valid then we can load spring application
// context on here.
final ApplicationContext context = new AnnotationConfigApplicationContext(
M6ApplicationContext.class);
// Use an akka system to be able to send messages in parallel
// without doing the low level thread manipulation ourselves.
final ActorSystem system = context.getBean(ActorSystem.class);
final ActorRef runCoordinator = system.actorOf(SPRING_EXT_PROVIDER.get(system)
.props("RunCoordinatorActor"), "runCoordinator");
Thread.sleep(1000);
runCoordinator.tell(new StartTesting(), ActorRef.noSender());
do {
LOGGER.info("Waiting for the process to finish");
Thread.sleep(60000L);
// What would be the alternative for isTerminated() code below
} while (!system.isTerminated());
}
}
and here is my call to shutdown inside the RunCoordinator class:
#Named("RunCoordinatorActor")
#Scope("prototype")
public class RunCoordinator extends UntypedActor {
#Override
public void onReceive(Object message) throws Exception {
....
if (message instanceof WorkDone) {
getContext().system().shutdown();
}
}
}
I can see there is another method called terminate() that returns a Future and if I replace the shutdown call with that it all works OK too.
if (message instanceof WorkDone) {
Future<Terminated> work = getContext().system().terminate();
// But where should I put the call work.isCompleted()
// and how would I make the main aware of it
}
I could find some scala examples on here shutdown-patterns-in-akka-2 but they still use system.shutdown in the end so not sure how up to date that post still is.
Thank you in advance for your inputs.
The solution was not that hard to find once I looked closer into the ActorSystem API.
All I had to do was to add this to my RunCoordinator class:
if (message instanceof WorkDone) {
getContext().system().terminate();
}
And had a Future<Terminated> workDone = system.whenTerminated(); defined in my main class which after the change became:
public static void main(String[] args) throws Exception {
if (new ArgumentsValidator().validate(args)) {
// If the arguments are valid then we can load spring application
// context on here.
final ApplicationContext context = new AnnotationConfigApplicationContext(
M6ApplicationContext.class);
// Use an akka system to be able to send messages in parallel
// without doing the low level thread manipulation ourselves.
final ActorSystem system = context.getBean(ActorSystem.class);
final Future<Terminated> workDone = system.whenTerminated();
final ActorRef runCoordinator = system.actorOf(SPRING_EXT_PROVIDER.get(system)
.props("RunCoordinatorActor"), "runCoordinator");
runCoordinator.tell(new StartTesting(), ActorRef.noSender());
do {
LOGGER.info("Waiting for the process to finish");
Thread.sleep(60000L);
} while (!workDone.isCompleted());
}
}
All worked very well after this. I am still surprised google cold not take me to any existing example showing how to do it.

Minecraft 1.9 modding block rendering error

I'm trying to render a block with a custom model in my 1.9 mod but it gives me a error at .getItemModelMesher
Code:
public class ModBlocks extends Blocks {
public static Block wooden_table;
public static void init() {
// Create Block
wooden_table = new Block(Material.wood).setUnlocalizedName("wooden_table").setCreativeTab(CreativeTabs.tabMisc);
// Register
GameRegistry.registerBlock(wooden_table, wooden_table.getUnlocalizedName().substring(5));
}
public static void registerRenders() {
registerRender(wooden_table);
}
public static void registerRender(Block block) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0,
new ModelResourceLocation(
Main.MODID + ":" + Item.getItemFromBlock(block).getUnlocalizedName().substring(5),
"inventory"));
}
}
Crash report:
---- Minecraft Crash Report ----
Description: Initializing game
java.lang.NullPointerException: Initializing game
at mcrafterzzfurnituremod.blocks.ModBlocks.registerRender(ModBlocks.java:29)
at mcrafterzzfurnituremod.blocks.ModBlocks.registerRenders(ModBlocks.java:25)
Please help I can't find any solution for this problem. If you need more code then just ask.
Minecraft.getMinecraft().getRenderItem()
that part only exists in the INIT phase, and not the PreInit phase. there it's still null.
Register variants in preinit,
then register meshes in init
besure to call this via your clientproxy and not the commonproxy
ps, read the tutorial on http://bedrockminer.jimdo.com/modding-tutorials/basic-modding-1-8/blockstates-and-metadata/ and download the example zip to understand where goes where normally

Categories

Resources