Jump to content

nates1984

Members
  • Posts

    10
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

nates1984's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. EDIT: Please disregard. Looks like I overlooked the getPosition() method, which works as expected. Thanks everyone for your replies. It appears the root problem is with playerLocation, however. Can anyone explain why: System.out.println(playerIn.playerLocation.getX()); Throws a NullPointerException on both the client and server sides within the onItemRightClick() method?
  2. I want the value of pos to be shared across all items, so no reason to use PropertyInteger, NBT, etc. What is it about BlockPos that makes this not work?
  3. Suspect it's a server vs client thing. Any ideas on why this isn't working? I've tried both static and non-static variables. The code is below. When I try to use pos in the hitEntity() method I get a NullPointerException. EDIT: Also worth pointing out that the code in hitEntity() only executes if posSet is true, and it's set to false in the constructor. So I know posSet is working as intended. public class CustomItem extends Item { public static BlockPos pos; public Random rand; public static boolean posSet; ....... @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { CustomItem.pos = playerIn.playerLocation; CustomItem.posSet = true; return new ActionResult(EnumActionResult.PASS, itemStackIn); }
  4. That worked. Thanks a bunch! itemRedstoneAnvilBlock = new ItemBlock(blockRedstoneAnvil); GameRegistry.register(itemRedstoneAnvilBlock.setRegistryName(blockRedstoneAnvil.getRegistryName()));
  5. Still seeing the same error after putting getItemFromBlock after register. Edit: Maybe this line from the console output is helpful: [23:57:37] [Client thread/ERROR] [FML]: Fatal errors were detected during the transition from PREINITIALIZATION to INITIALIZATION. Loading cannot continue Edit2: Note that the following code from the working 1.8 version of this appears to work without issue: blockRedstoneAnvil = new BlockRedstoneAnvil().setUnlocalizedName("redstone_anvil"); GameRegistry.registerBlock(blockRedstoneAnvil, ItemRedstoneAnvilBlock.class, "redstone_anvil"); itemRedstoneAnvilBlock = GameRegistry.findItem("nates1984redstoneanvil", "redstone_anvil");
  6. More context: Main.class @Mod(modid = Main.MOD_ID, name = Main.MOD_NAME, version = Main.VERSION) public class Main { public static final String MOD_ID = "nates1984redstoneanvil"; public static final String MOD_NAME = "Redstone Anvil"; public static final String VERSION = "1.1"; public static SimpleNetworkWrapper network; public static Block blockRedstoneAnvil; public static Item itemRedstoneAnvilBlock; @Instance(MOD_ID) public static Main instance; @SidedProxy(clientSide = "nates1984.redstoneanvil.proxy.ClientProxy", serverSide = "nates1984.redstoneanvil.proxy.CommonProxy") public static CommonProxy proxy; @EventHandler public void preInit(FMLPreInitializationEvent e) { network = NetworkRegistry.INSTANCE.newSimpleChannel("nates1984redstoneanvil"); network.registerMessage(RenameMessage.Handler.class, RenameMessage.class, 0, Side.SERVER); network.registerMessage(RenameMessage.Handler.class, RenameMessage.class, 0, Side.CLIENT); blockRedstoneAnvil = new BlockRedstoneAnvil(); GameRegistry.register(blockRedstoneAnvil.setRegistryName("redstone_anvil")); itemRedstoneAnvilBlock = Item.getItemFromBlock(blockRedstoneAnvil); GameRegistry.register(itemRedstoneAnvilBlock.setRegistryName(blockRedstoneAnvil.getRegistryName())); proxy.preInit(); } @EventHandler public void init(FMLInitializationEvent e) { GameRegistry.addRecipe(new ItemStack(blockRedstoneAnvil), "AAA", "BCB", "CCC", 'A', Blocks.iron_block, 'B', Blocks.redstone_block, 'C', Items.iron_ingot); NetworkRegistry.INSTANCE.registerGuiHandler(Main.instance, new GuiHandler()); proxy.init(); } @EventHandler public void postInit(FMLPostInitializationEvent e) { proxy.postInit(); } } Stacktrace [23:21:10] [Client thread/ERROR] [FML]: The following problems were captured during this phase [23:21:10] [Client thread/ERROR] [FML]: Caught exception from nates1984redstoneanvil java.lang.NullPointerException at nates1984.redstoneanvil.Main.preInit(Main.java:56) ~[bin/:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92] at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560) ~[forgeSrc-1.9-12.16.0.1865-1.9.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?] at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228) ~[forgeSrc-1.9-12.16.0.1865-1.9.jar:?] at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206) ~[forgeSrc-1.9-12.16.0.1865-1.9.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92] at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ~[guava-17.0.jar:?] at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ~[guava-17.0.jar:?] at com.google.common.eventbus.EventBus.post(EventBus.java:275) ~[guava-17.0.jar:?] at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135) [LoadController.class:?] at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556) [Loader.class:?] at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:240) [FMLClientHandler.class:?] at net.minecraft.client.Minecraft.startGame(Minecraft.java:472) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:381) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_92] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_92] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_92] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] [23:21:10] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:646]: ---- Minecraft Crash Report ---- // There are four lights! Time: 4/22/16 11:21 PM Description: Initializing game java.lang.NullPointerException: Initializing game at nates1984.redstoneanvil.Main.preInit(Main.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:240) at net.minecraft.client.Minecraft.startGame(Minecraft.java:472) at net.minecraft.client.Minecraft.run(Minecraft.java:381) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at nates1984.redstoneanvil.Main.preInit(Main.java:56) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:560) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:228) at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:206) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) at com.google.common.eventbus.EventBus.post(EventBus.java:275) at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:135) at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:556) at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:240) at net.minecraft.client.Minecraft.startGame(Minecraft.java:472) -- Initialization -- Details: Stacktrace: at net.minecraft.client.Minecraft.run(Minecraft.java:381) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26)
  7. Going to hijack this thread: The following throws a NullPointerException, and it is basically equivalent to winnetrie's working code. It's contained in Main's preInit, and I'm on forge-1.9.12.16.0.1865-1.9 Any ideas? What silly thing am I overlooking? The last line below is what the stacktrace points to. blockRedstoneAnvil = new BlockRedstoneAnvil(); GameRegistry.register(blockRedstoneAnvil.setRegistryName("redstone_anvil")); itemRedstoneAnvilBlock = Item.getItemFromBlock((Block) blockRedstoneAnvil); GameRegistry.register(itemRedstoneAnvilBlock.setRegistryName(blockRedstoneAnvil.getRegistryName())); Interestingly enough, everything seemed to be working fine without registering the item, and using the deprecated registerBlock method.
  8. Probably silly questions, but asking none-the-less. It has been awhile since I touched Minecraft, and I admit I never became all that familiar with the code base... 1) In preInit(), the old way of registering variant names was ModelBakery.addVariantName(Item, String...) and doesn't seem to work anymore. If I'm following the classes right, it looks like I need to use ModelBakery.registerItemVariants(Item, ResourceLocation...) instead. Is the ResourceLocation equivalent to the ModelResourceLocation() used in init()? That's probably vague... I've included code at end of post... Just some general pointers on how to modify to update from 1.8 to 1.9 would be useful. This is the last error I'm fighting with. 2) GameRegistry.findItem() has deprecated. The popup says: "Use Item.REGISTRY.getValue(ResourceLocation) instead! Look up a mod item in the global "named item list"" Maybe I'm just being dense, but Item.REGISTRY doesn't exist. Item.itemRegistry.getValue() does though. Admittedly, I'm not sure what the global named item list is. Is that the items in ModelBakery.registerVariantNames()? Assuming once I get this sorted out, I the use setRegistryName() as described here in some way: http://www.minecraftforge.net/forum/index.php?topic=38187.0 public class ClientProxy extends CommonProxy { public static Block blockRedstoneAnvil; public void preInit() { blockRedstoneAnvil = new BlockRedstoneAnvil().setUnlocalizedName("redstone_anvil"); //GameRegistry.registerBlock(blockRedstoneAnvil, ItemRedstoneAnvilBlock.class, "redstone_anvil"); GameRegistry.register(blockRedstoneAnvil); Item itemRedstoneAnvilBlock = GameRegistry.findItem("nates1984redstoneanvil", "redstone_anvil"); ModelBakery.addVariantName(itemRedstoneAnvilBlock, "nates1984redstoneanvil:redstone_anvil_intact", "nates1984redstoneanvil:redstone_anvil_slightly_damaged", "nates1984redstoneanvil:redstone_anvil_very_damaged"); } public void init() { Item item = GameRegistry.findItem(Main.MOD_ID, "redstone_anvil"); ModelResourceLocation model = new ModelResourceLocation("nates1984redstoneanvil:redstone_anvil_intact", "inventory"); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, model); model = new ModelResourceLocation("nates1984redstoneanvil:redstone_anvil_slightly_damaged", "inventory"); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 1, model); model = new ModelResourceLocation("nates1984redstoneanvil:redstone_anvil_very_damaged", "inventory"); Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 2, model); GameRegistry.addRecipe(new ItemStack(blockRedstoneAnvil), "AAA", "BCB", "CCC", 'A', Blocks.iron_block, 'B', Blocks.redstone_block, 'C', Items.iron_ingot); NetworkRegistry.INSTANCE.registerGuiHandler(Main.instance, new GuiHandler()); } public void postInit() { } }
  9. Wow, that was surprisingly easy with SimpleNetworkWrapper. Kind of feel like a noob for even asking. Regardless, thanks for your comment.
  10. So, as my first adventure into Minecraft modding I decided to create an anvil block that will allow me to specify custom repair mechanics. Everything works except for one aspect: renaming an item. The behavior I'm seeing is that the new name is reflected in the output slot, but when I try to pick the item up the game bugs out for a split second and then the gui resets to the state that existed just prior to me trying to pick up the renamed item. When I try to rename an item and do other things, i.e. repair using material or combine with a second item, the renaming aspect is ignored but the other changes occur. I asked on the minecraftforge IRC channel and was given the lead that I'm doing something client side that I should be doing server side. My understanding is that client side and server side are relevant even for the combined client, i.e. that the combined client has both a client sandbox and a server sandbox. The server in the combined client is the world. If this is the issue I'm seeing, I'm a bit confused. Why is it the case that I can spawn new items with my current code, but not spawn one with a new name? Is it the case that Forge is handling things under the hood that I'm not aware of, and renaming is an edge case that isn't handled? Or perhaps I have a fundamental misunderstanding of what's going on here? Regardless, not really sure where to go from here. My code below if that helps, as a concrete example I can apply things to. https://github.com/NatePillow/MinecraftMods/tree/master/Redstone%20Anvil/src/main/java/nates1984/redstoneanvil A side question: I'd like to refactor and extend BlockAnvil and ContainerRepair... Any issue with doing this? It's how I was initially doing things, but backed off as a way to avoid any potential bugs this may cause. Another side question: I've noticed that if I extend ItemMultiTexture, and create an overriden method for getUnlocalizaedName that just calls the super method, things don't work (this was the issue preventing different textures/names from metadata from working properly). Is that me misunderstanding Java, or misunderstanding Forge?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.