Was thinking about custom fluids via scripts

Discussion in 'Plugin Development' started by mindless728, Feb 11, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    mindless728

    So i was thinking of abandoning my ClassicFluids plugin and was thinking a better way to do this would be designing some way of allowing anyone to create different flow methods.

    To allow allow this i was thinking of implementing a (very) simple scripting language that when the plugin loaded and was enabled would load the script files, generate java files, compile the java files, load the class files, then create instances of the scripts

    The other alternative is to just parse the scripting languages, but i feel this might be too slow when you have say 1,000,000 block flow events

    here is a sample of what i am talking about:
    Code:
    public abstract class CustomFluidsScript {
      Block fluid;
      String wname;
      int xreal;
      int yreal;
      int zreal;
      Server server;
      CustomFluids plugin;
    
      CustomFluidsScript(Block f, String wn, int xr, int yr, int zr, Server s, CustomFluids p) {
        fluid = f;
        wname = wn;
        xreal = xr;
        yreal = yr;
        zreal = zr;
        server = s;
        plugin = p;
      }
    
      boolean isOverWrittable(int i, int j, int k) {
        Block block = getBlock(i,j,k);
        return plugin.isoverWrittable(block.getTypeId());
      }
    
      void overWrite(int i, int j, int k) {
        Block block = getBlock(i,j,k);
        block.setTypeId(fluid.getTypeId);
      }
    
      Block getBlock(int i, int j, int k) {
        return server.getWorld(wname).getBlock(xr+i,yr+j,zr+k);
      }
    
      abstract public void script();
    }
    
    /*
    -------------------------------------------------------------------------
    flow_script.fl: //sample script
    script 2 : water //states that the max distance away from fluid block is 2 and fluid block is only water
      if isOverWrittable(x,y,z+1) //tests if the block can be overwritten
        overWrite(x,y,z+1) //overwrite the block
      fi //end of if
    
    generates::
    
    CF_flow_script.java:
    public class CF_flow_script extends CustomFluidsScript {
      CF_flow_script(Block f, String wn, int xr, int yr, int zr, int s, Server se, CustomFluids p) {
        super(f,wn,xr,yr,zr,s,se,p);
      }
    
      public void script() {
        if(isOverWrittable(0,0,1)) {
          overWrite(0,0,1);
        }
      }
    }
    */
    
    suggestions/comments are very welcome
     
Thread Status:
Not open for further replies.

Share This Page