Jump to content

[1.7.10]Randomized Enchantment in crafting remote/!remote


OwnAgePau

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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