Editing various Minecraft mechanics

Discussion in 'Plugin Development' started by Limeth, May 12, 2013.

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

    Limeth

    Hello, coders.
    I'm currently being fascinated by Terra Firma Craft and I'd love to create a plugin with similar mechanics. If you know the answer, tell me how to do that:
    1. Create a dummy inventory for a 5x5 crafting table Not answered
    2. Remove Minecraft recipes Answered
    3. Lengthen the time of fire being lit Answered
    I'm sure I will have to use CraftBukkit. Thanks for your help and sorry for my bad english.
    - Limeth
     
  2. Offline

    caseif

    1. Build an instance of the recipe you want to remove, then remove it from the List returned by getServer().getRecipes().
    2. To double the time: Listen to the BlockDecayEvent, check if it's fire, then cancel the event and add the coords and world to a List, preferably in the form of a custom class. Then, when you do listen for the BlockDecayEvent again, only cancel it if the location isn't on the List. If it is, allow the event and remove the coords from the List. You can easily use a HashMap instead to triple the time or more, by mapping the location to an integer representing the number of times the block has decayed, and deleting it once it gets to a certain point.
     
  3. Offline

    Limeth

    AngryNerd
    Neat name, haha.
    Okay so, few questions: Is there a better way than saving the fire in a list? Because I have a feeling that would lag the server a little, if it has to go through all the fires until it hits the correct one.
    Also, I'm wondering, is there a way to remove all vanilla recipes? I'm very new to Iterators, I tried:
    Code:java
    1.  
    2. Iterator<Recipe> recipes = getServer().recipeIterator();
    3.  
    4. while(recipes.hasNext()) {
    5.  
    6. recipes.remove();
    7. recipes.next();
    8. }
    9.  

    But that didn't work.
     
  4. Offline

    1SmallVille1

    Limeth
    There will be very little lag coming from code that's just iterating through a list. It's a simple task and will not lag your server.
     
  5. Offline

    TheTinySpider

    Limeth
    PHP:
    public void removeRecipies () {
            
    Iterator<ReciperecipeIterator Bukkit.recipeIterator();
     
            while(
    recipeIterator.hasNext())
            {
                
    recipeIterator.remove();
            }
        }
    But there is also something like:
    PHP:
    Bukkit.resetRecipes();
     
    Limeth likes this.
  6. Offline

    caseif

    Fire blocks would only be added to the list when they're scheduled to go out, so even a massive fire wouldn't result in more than 1,000 entries, which is fairly small and should have a minimal impact on the memory usage.
     
    Limeth likes this.
  7. Offline

    Limeth

    AngryNerd TheTinySpider 1SmallVille1
    Okay, so, that helped. Now I'm creating a new type of Crafting Tables. It is going to use a 5x5 grid for recipes and should replace the default one. I think I'm about 50% done, but I need help with InventoryHolders. The new Crafting Table should also work similarly to Project Tables in FTB - their contents stay when closing the inventory.
    Code:java
    1.  
    2. public void open(Player player) {
    3.  
    4. Inventory inv = Bukkit.createInventory(InventoryHolder?, 45, "Crafting Table"); //This is the part I don't know what to do with
    5.  
    6. showBorder(inv); //Shows unavailable slots
    7. update(inv); //Shows contents
    8.  
    9. player.openInventory(inv);
    10.  
    11. }
    12.  
     
  8. Offline

    caseif

    Leave the first parameter null if you're creating a virtual inventory, but set it as the block you're storing it in if applicable.
     
  9. Offline

    Limeth

    Do you mean like: Bukkit.createInventory(loc.getBlock(), 45, "Crafting Table");? Because that doesn't work for me. Another problem: I tried creating it with null, but in this example, the boolean is null:
    Code:java
    1. public Inventory inv;
    2.  
    3. public void init() {
    4. Player player = Bukkit.getPlayer("Random online player");
    5. inv = Bukkit.createInventory(null, 45, "Crafting Table");
    6. player.openInventory(inv);
    7. }
    8.  
    9. @EventHandler
    10. public void invClick(InventoryClickEvent event) { //A click in the "Crafting Table" inventory...
    11.  
    12. if(!event.getPlayer().getName().equals("Random online player")) return;
    13.  
    14. boolean result = event.getInventory().equals(inv); //The result is getting set to false. No idea why.
    15.  
    16. }
     
Thread Status:
Not open for further replies.

Share This Page