Posted June 27, 201510 yr Hi there, I have succesfully created a block that allows me to combine a tool or armor with a magical stone to give the tool or armor a random enchantment. However I want to see the actual output on the right side. What happens right now is that it randomly selects an enchantment both on remote and !remote. So the enchantment you see in the output is not the enchantment that is being added to the tool/armor. I tried placing the randomization only on !remote side or on remote but this either results in the output not showing an enchantment and recieving an enchantment upon creation or showing an enchantment in the ouput and not recieving an enchantment upon creation. How could I make it so it selects a randomized enchantment and gives that enchantment to the weapon. I am the creator of the Soul Forest Mod : http://www.planetminecraft.com/mod/151-soul-forest-10-ores-vines-dimension-mobs-and-more/
June 27, 201510 yr Author It is a bit messy though and I currently removed the split between remote or not. public void onCraftMatrixChanged(IInventory par1IInventory){ ItemStack result = GemmingCraftingRecipes.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj); if(!this.worldObj.isRemote){ if(result != null){ ItemStack input = null; if(this.getSlot(0).getStack() != null){ input = this.getSlot(0).getStack(); } if(this.getSlot(1).getStack() != null){ input = this.getSlot(1).getStack(); } if(input != null){ if(input.getItem() != SoulItems.ScarletiteAmuletStone.get()){ ArrayList<Enchantment> enchants = new ArrayList(); for(Enchantment e : Enchantment.enchantmentsList){ if(e != null){ if(e.canApply(input)){ enchants.add(e); } } } System.out.println("--------------------------"); int random = new Random().nextInt(enchants.size()); Enchantment newEnchantment = enchants.get(random); System.out.println("New Enchantment : " + newEnchantment.getName()); Map map = EnchantmentHelper.getEnchantments(input); Iterator iterator = map.keySet().iterator(); int newEnchLevel = 0; boolean flag = false; while (iterator.hasNext()){ int i = ((Integer)iterator.next()).intValue(); Enchantment ench = Enchantment.enchantmentsList[i]; int enchLevel = map.containsKey(Integer.valueOf(i)) ? ((Integer)map.get(Integer.valueOf(i))).intValue() : 0; System.out.println(ench.effectId + ", " + newEnchantment.effectId); if(ench.effectId == newEnchantment.effectId){ flag = true; enchLevel += 1; } boolean flag1 = ench.canApply(result); if("enchantment.lootBonusDigger".equals(newEnchantment.getName())){ if("enchantment.untouching".equals(ench.getName())){ flag1 = false; } } if("enchantment.untouching".equals(newEnchantment.getName())){ if("enchantment.lootBonusDigger".equals(ench.getName())){ flag1 = false; } } if(!(newEnchantment.canApplyTogether(ench) && ench.canApplyTogether(newEnchantment))){ flag1 = false; } if(flag1){ if (enchLevel > ench.getMaxLevel()){ enchLevel = ench.getMaxLevel(); } System.out.println("ID : " + ench.getName() + ", lvl : " + enchLevel); map.put(Integer.valueOf(ench.effectId), Integer.valueOf(enchLevel)); } else{ if (enchLevel > ench.getMaxLevel()){ enchLevel = ench.getMaxLevel(); } System.out.println("ID : " + ench.getName() + ", lvl : " + enchLevel); map.put(Integer.valueOf(ench.effectId), Integer.valueOf(enchLevel)); } } if(!flag){ if (newEnchLevel > newEnchantment.getMaxLevel()){ newEnchLevel = newEnchantment.getMaxLevel(); } if(newEnchLevel == 0){ newEnchLevel += 1; } boolean canApply = newEnchantment.canApply(result); if(canApply){ System.out.println("NEW -> ID : " + newEnchantment.getName() + ", lvl : " + newEnchLevel); map.put(Integer.valueOf(newEnchantment.effectId), Integer.valueOf(newEnchLevel)); } } EnchantmentHelper.setEnchantments(map, result); } } } } this.craftResult.setInventorySlotContents(0, result); } I am the creator of the Soul Forest Mod : http://www.planetminecraft.com/mod/151-soul-forest-10-ores-vines-dimension-mobs-and-more/
June 27, 201510 yr Author Well when I do that it won't let me grab the result out of the slot. I am the creator of the Soul Forest Mod : http://www.planetminecraft.com/mod/151-soul-forest-10-ores-vines-dimension-mobs-and-more/
June 28, 201510 yr Author But isn't it so in this case that on remote it sets the output and thus the enchantment on that output, but then on local it doesn't put anything in the output at all. And therefor I am not able to take anything out? Because If I turn this around, visually it doesn't set the output but locally and "underwater" there is something in the output and when I click the output slot I get the output with an enchantment. It seems that on remote it sets what the output looks like but what you actually get from the output happens on the !remote side.... I am the creator of the Soul Forest Mod : http://www.planetminecraft.com/mod/151-soul-forest-10-ores-vines-dimension-mobs-and-more/
June 28, 201510 yr If you store an enchantment seed per player, you can set the random seed on the client and server to be the same. See the 1.8 source code for the enchantment gui, I'm sure there's some way to put that into a crafting table in 1.7.10 catch(Exception e) { } Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.