Jump to content

Pixtar

Members
  • Posts

    57
  • Joined

  • Last visited

Posts posted by Pixtar

  1. Hi Aarilight,

    7 hours ago, Aarilight said:

    You put the code from a test into your code? He posted that test to demonstrate how BlockPlaceEvent works. This code won't do anything for you as is.

    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.

     

    7 hours ago, Aarilight said:

    In the handler which started this entire problem, did you try using RightClickBlock instead of PlaceEvent?

    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

  2. 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

  3. 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.

    5 hours ago, Pixtar said:

    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.

    Pixtar

  4. 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

  5. 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

  6. 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:

    Quote

    why is the hook only called from the server side and not both ??

     

    Maybe PlaceEvent is only hooked on the server side and I need to use RightClickBlock?

     

    Kind regards,

    Pixtar

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. Hi jabelar,

     

    no, I don't need any events at all. Here an example what and how I want to do it:
     

    Quote

     

    /examplemod set test true

    calls cfg.setTest( true ); from the Command class

     

    /examplemod store

    calls cfg.save(); from the Command class

     

     

    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

  13. I've looked some things up and tried some things out.

     

    ConfigChangedEvent.OnConfigChangedEvent

    Quote

    It fires when the Done button has been clicked on a GuiConfig screen

    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 :-/

  14. 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

  15. 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

  16. 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.

  17. 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) ) );
            }
        }
    }

     

  18. 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) ) );
            }
        }
    }

     

  19. 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

×
×
  • Create New...

Important Information

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