-
Posts
57 -
Joined
-
Last visited
Everything posted by Pixtar
-
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi Aarilight, Draco18s and loordgek, it working now with the source of Aarilight. Thank you all for your patience with me. ^^ Kind regards, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi Aarilight, after I'm back home from work I'll update Forge to your suggested version 14.22.0.2462 and try it again. Thanks, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi Aarilight, well, that might be, that he posted that code only for a demo - nevertheless the code is doing the same like mine; canceling the event. Yep - I tried that one too. Thank you for your time to create and test your posted snippet. I'm sorry to say that, but for my version of forge (1.12.1-14.22.0.2452) it does nothing else than the other codes - furthermore it doesn't only block Podzol it blocks the entire dirt group. Block gets placed, forge tidies up the block, it disappears and it's gone from the inventory. Have a nice day, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi Draco18s, so I've cleaned my gradle, created a complete clean server, removed all mods at the client side, compiled the BlockPlaceEventTest loordgek posted, inserted it at the server and the client side and tried it again. I encounter still the same problem - the inventory of the client won't be updated, ONLY if the user collects a block of the same denied type the belt receives an update and the blocks are back. Yep - I understand the circumstance that the client thinks the block is/was placed. Main question: At which place do I need to modify what to inform the client that the block wasn't placed successfully if the code of loordgek isn't doing that? Side question: How does the client notice. that the blocks weren't placed after collecting a new block of the same denied type? Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi Draco18s, thanks for the advice of the metadata state. I will keep that in mind. Anyway - the entire thread is heading the wrong track. My initial problem of the sync client / server is still available. Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi, I've tested my last line of code and it's working, but in asking myself how to get a block like "Podzol" or "Coarse Dirt" through that system, because Blocks.PODZOL isn't defined. ^^ Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi loordgek, well that worked for me: public static String blockedBlock = Blocks.DIRT.getRegistryName().toString(); Results in: S:blockedBlock=minecraft:dirt Like I mentioned before about the cast .. how to cast it backwards? Currently I would do the comparison like the following, because I don't know how to cast from String to Block backwards: if ( event.getPlacedBlock().getBlock().getRegistryName().toString().equals( config.blockedBlock ) ) The only way I found myself is this one ?! if ( event.getPlacedBlock().getBlock() == Block.REGISTRY.getObject(new ResourceLocation( ExampleMod.config.blockedBlock ) ) ) Kind regards, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi loordgek, if I'm storing e.g. Dirt via RegistryName it stores nothing in the annotated config except the variable name: public static ResourceLocation blockedBlock = Blocks.DIRT.getRegistryName(); Result blockedBlock { } Let's talk about which versions we are using, currently I'm working with forge-1.12.1-14.22.0.2467-mdk Could it be a sync bug in forge? I'm asking, because I've contact to another mod developer and he's saying he's having the same issue. :-/ Kind regards, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi loordgek, so how to cast from an Integer to an object Block dynamically without using switch case to determine the static Block? I've removed the SideOnly barrier. At the end I'm here to figure out exactly that question: Maybe PlaceEvent is only hooked on the server side and I need to use RightClickBlock? Kind regards, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi loordgek, thanks for your hint. I've rewritten my code and added the config I'm using to define my blocked block: @Config(modid = ExampleMod.MODID, name=ExampleMod.MODID+"/"+ExampleMod.MODID, category="config") public class MyConfig { public static int blockedBlockId = 1; } public class MyConfigWrapper { public static Block blockedBlock = null; MyConfigWrapper() { blockedBlock = Block.getBlockById( ExampleMod.config.blockedBlockId ); } } public static MyConfig config = null; public static MyConfigWrapper configWrapper = null; @Mod.EventHandler public void preinit( FMLPreInitializationEvent event ) { config = new MyConfig( ); configWrapper = new MyConfigWrapper( ); //How to share the blocked block for the client? } @SubscribeEvent public static void onBlockInteract( PlaceEvent event ) { if( FMLCommonHandler.instance().getSide().isServer() ) { Block destBlock = event.getPlacedBlock().getBlock(); if( destBlock == configWrapper.blockedBlock ) { event.setCanceled( true ); } } else { //What to do here? } } At the end these changes are cosmetic I will still have the same problems: The client doesn't know about block which block should be blocked, right? Kind regards, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi Aarilight, ah okay, no problem, thanks for your help anyway. I think I've detected another problem I need to solve. The canceled event is based on a server side config, which contains a list of blocks which aren't allowed to be place. So I need to follow the hints of this forge documentation and provide the blocks which needs to be blocked via an NetworkInterface to the client. Right? Kind regards, Pixtar -
[1.12.1] Canceled PlaceEvent removes block from inventory
Pixtar replied to Pixtar's topic in Modder Support
Hi Aarilight, until now I haven't annotated any class or method with @SideOnly. That sounds like both sides are in need of the mod, client and server? So I need to divide the code into two sections, server and client, like this? @SubscribeEvent public static void onBlockInteract( PlaceEvent event ) { if( FMLCommonHandler.instance().getSide().isServer() ) { int blockId = Block.getIdFromBlock( event.getPlacedBlock().getBlock() ); if( blockId == 0 ) { event.setCanceled( true ); } } else { //What to do here? } } Currently I haven't much knowledge about Sides coding. Kind regards, Pixtar -
Hi all, I'm using the following code to cancel the PlaceEvent: @SubscribeEvent public static void onBlockInteract( PlaceEvent event ) { int blockId = Block.getIdFromBlock( event.getPlacedBlock().getBlock() ); if( blockId == 0 ) { event.setCanceled( true ); } } The following happens: The block gets placed, it appears for a short time, then disappears and isn't placed at all BUT the placed block is gone from the inventory of the player AND is back after a relog of the player. I want to give the player black the block during his current session, not after a relog. If read the following thread/post maybe I'm encountering the same problem - but I don't know how to solve it. How can I gave the player the not placed item/block back? Kind regards, Pixtar
-
[Solved] [1.12.1] Configuration save at server without GUI?!
Pixtar replied to Pixtar's topic in Modder Support
Hi jabelar, FINALLY with annotations MyConfig.java @Config(modid = ShowPlugins.MODID) public class MyConfig { @Config.Comment("This is an example boolean property.") public static boolean testBool = true; public void save( ) { ConfigManager.sync( Examplemod.MODID, Config.Type.INSTANCE ); } public void setTestBool( boolean test ) { testBool = test; save(); } } Examplemod.java public static MyConfig config = null; @Mod.EventHandler public void preinit( FMLPreInitializationEvent event ) { config = new MyConfig( ); } Command.java @Override public void execute( MinecraftServer server, ICommandSender sender, String[] args ) throws CommandException { Examplemod.config.setTestBool( true ); } It creates, loads, modifies and stores the configs. .. what a hell ride to get here .. Pixtar -
[Solved] [1.12.1] Configuration save at server without GUI?!
Pixtar replied to Pixtar's topic in Modder Support
Hi jabelar, no, I don't need any events at all. Here an example what and how I want to do it: I've went to the source of Configuration: I'm creating a new Configuration, which calls runConfiguration() and if everything is ok, it's calling load() .. within load() we have: if (start.matches()) { fileName = start.group(1); categories = new TreeMap<String, ConfigCategory>(); continue; } else if (end.matches()) { fileName = end.group(1); Configuration child = new Configuration(); child.categories = categories; this.children.put(fileName, child); continue; } So Configuration is storing its data into children or categories. Then we have the normal getter methods of Configuration to get the values from children or categories. Now we are looking at Configuration.save(), which is doing: for (Map.Entry<String, Configuration> entry : children.entrySet()) { buffer.write("START: \"" + entry.getKey() + "\"" + NEW_LINE); entry.getValue().save(buffer); buffer.write("END: \"" + entry.getKey() + "\"" + NEW_LINE + NEW_LINE); } So the question is: How to modify children or categories? There is no way to do it! I thought I'm calling getCategory to get ConfigCategory, modify it and put it back into Configuration: Property testBool = new Property( "testBool", "true", Property.Type.BOOLEAN ); ConfigCategory configCat = cfg.getCategory("config"); configCat.put( "testBool", testBool ); //cfg.setCategory( configCat ); cfg.save(); .. but there is no method to set the ConfigCategory back into the Configuration. Next I was thinking of using: copyCategoryProps ... which leads me to the same problem, how to put ConfigCategory back into it? So, finally it seems for me impossible to use Configuration to save settings back into the file from where I've read them -------___------- Totally weird, Pixtar -
[Solved] [1.12.1] Configuration save at server without GUI?!
Pixtar replied to Pixtar's topic in Modder Support
I've looked some things up and tried some things out. ConfigChangedEvent.OnConfigChangedEvent So this event needs a GUI, which I don't have at the server. I tried the annotation based system, which leads me to the same problem. It creates the config, it loads the config, I can access the variable and modify it, but It doesn't saves the modifications back into the file. Pixtar EDIT: At the end it seems for me, that there is only an automatism for saving a config from the GUI, not through commands and internal changes. That means for me, that I need to entirely write my own config system based on JSON objects. -.- then I'm wishing me the "old" system back with properties could be saved :-/ -
[Solved] [1.12.1] Configuration save at server without GUI?!
Pixtar replied to Pixtar's topic in Modder Support
Hi jabelar, okay it seems like we talked past each other. You're looking from the client side, but I try to handle a server - client model. ^^ The server provides the config file, its configs and the command structure. The client is executing the command to adjust the configs. At the end the configs should be stored back into the config file. Pixtar -
[Solved] [1.12.1] Configuration save at server without GUI?!
Pixtar replied to Pixtar's topic in Modder Support
Hi jabelar, 1. You mean this function within Config? @SubscribeEvent public void onConfigurationChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event) { if (event.getModID().equalsIgnoreCase(MAIN.MODID)) { cfg.save(); } } 2. I don't know to if it matters. 3. The file will be created for me with everything setup and loaded as well. I don't know what you mean with GUI config .. I'm changing the value of Config via CommandBase. Yeah I saw the annotation based system and currently trying it out, because I want to save the config with its changes through the game. Pixtar -
[Solved] [1.12.1] Configuration save at server without GUI?!
Pixtar posted a topic in Modder Support
Hi all, I wanted to load, modify and save a Configuration. Loading and modifying works but call me dumb, I don't understand the mechanism behind the method Configuration::save What I have until now: Main public static Config config = null; @Mod.EventHandler public void preinit( FMLPreInitializationEvent event ) { config = new Config( event.getSuggestedConfigurationFile().getParentFile().getAbsolutePath() ); config.preinit(); } @Mod.EventHandler public void init( FMLInitializationEvent event ) { config.init(); } @Mod.EventHandler public void postinit( FMLPostInitializationEvent event ) { config.postinit(); } Config: public class Config { private Configuration cfg; public static boolean testBool = true; public Config( String cfgPath ) { cfg = new Configuration( new File( cfgPath+"/test", "test.cfg" ), "v1", false ); } public void preinit() { testBool = this.cfg.getBoolean( "testBool", "config", testBool, "TestComment" ); } public void init() { } public void postinit() { if( cfg.hasChanged() ) cfg.save(); } public Configuration getConfig() { return cfg; } public boolean setTest( boolean test ) { testBool = test; cfg.save(); } } cfg.save() does nothing. I've read many thread about Configs, but they seem to base on older versions of Forge, where getBoolean returned a Property instead of a boolean. Nevertheless I've read something about registering a method watching configChanges, but we are not in C++, where Configuration knows about my testBool as a reference to store the data back into the file. So what do I need to add or modify to save the testBool back into the file? Kind regards, Pixtar EDIT: I was talking about this thread and Property. -
[Solved] [1.12.1] Register one command for two mods?
Pixtar replied to Pixtar's topic in Modder Support
Hi diesieben07, below the modified version, which now gets the base command before the registration: //Register your command class e.g. "MyCommand": @Mod.EventHandler public void onServerStarting( FMLServerStartingEvent event ) { MyCommand cmd = new MyCommand(); //Get the command you want to overwrite/extend from e.g. command "examplemod": ICommand base = FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager().getCommands().get( "examplemod" ); cmd.registerBase( base ); event.registerServerCommand( cmd ); } //Within the "MyCommand" have a variable to store the base command private static ICommand base = NULL; //Within the "MyCommand" have a function to register the base command public registerBase( ICommand base ) { base = _base; } //Within the "MyCommand" class extended from CommandBase overwrite "execute" @Override public void execute( MinecraftServer server, ICommandSender sender, String[] args ) throws CommandException { if( sender instanceof EntityPlayerMP ) { //Handle arguments if( args.length > 0 ) { //Handle the "newcommand" you have added if( args[0].equalsIgnoreCase("newcommand") ) { doSomething( ); } //Redirect all other command from the mod to the mod ifself else { base.execute( server, sender, args ); } } //If no arguments where given print the usage else { EntityPlayerMP player = (EntityPlayerMP) sender; //Extend the usage text with the "newcommand" String usageText = base.getUsage( sender ) + "\n/examplemod <newcommand>"; //Print the text to the player player.sendMessage( new TextComponentString(usageText).setStyle( new Style().setColor(TextFormatting.YELLOW) ) ); } } } -
[Solved] [1.12.1] Register one command for two mods?
Pixtar replied to Pixtar's topic in Modder Support
Hi Choonster, after I tried it out, I've read your answer again and then I understood it. So in general a mod developer should use CommandTreeBase to give other developers the chance to extend the mod commands if they like to? Hi diesieben07, I tried your method and it's working flawlessly; thanks. Just for completeness and other people reading this thread - I did the following: //Register your command class e.g. "MyCommand": @Mod.EventHandler public void onServerStarting( FMLServerStartingEvent event ) { event.registerServerCommand( new MyCommand() ); } //Within the "MyCommand" class extended from CommandBase overwrite "execute" @Override public void execute( MinecraftServer server, ICommandSender sender, String[] args ) throws CommandException { if( sender instanceof EntityPlayerMP ) { //Get the command you want to overwrite/extend from e.g. command "examplemod": ICommand base = FMLCommonHandler.instance().getMinecraftServerInstance().getCommandManager().getCommands().get( "examplemod" ); //Handle arguments if( args.length > 0 ) { //Handle the "newcommand" you have added if( args[0].equalsIgnoreCase("newcommand") ) { doSomething( ); } //Redirect all other command from the mod to the mod ifself else { base.execute( server, sender, args ); } } //If no arguments where given print the usage else { EntityPlayerMP player = (EntityPlayerMP) sender; //Extend the usage text with the "newcommand" String usageText = base.getUsage( sender ) + "\n/examplemod <newcommand>"; //Print the text to the player player.sendMessage( new TextComponentString(text).setStyle( new Style().setColor(TextFormatting.YELLOW) ) ); } } } -
[Solved] [1.12.1] Register one command for two mods?
Pixtar replied to Pixtar's topic in Modder Support
Hi diesieben07, so it's like I assumed, otherwise it had shown me both commands. ^^ Nevertheless I was waiting for such the work-a-round answer of yours. I will give your method of delegation a try. Thanks you very much for the hint. Pixtar -
[Solved] [1.12.1] Register one command for two mods?
Pixtar replied to Pixtar's topic in Modder Support
Right, that was my expectation. That if I type /<command> that both registered commands will be executed. Currenlty it only executes the command of my mod, maybe because of a non exisitng queue behind it and LIFO?! -
[Solved] [1.12.1] Register one command for two mods?
Pixtar replied to Pixtar's topic in Modder Support
The commands are getting registered, so it could be that there is a queue where the commands get registered. I don't know about the mechanism behind it, therefore I'm asking. ^^ -
Hi all, I've written an extension for another mod and I wanted to use the same command as the mod itself. It seems that it isn't possible with my current knowledge. So my question is: Is it possible to share/use the same command as another mod without overwriting it? If it's not possible, is there a known work-a-round? Kind regards, Pixtar