Jump to content

JimiIT92

Members
  • Posts

    866
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JimiIT92

  1. I was trying to add a mana bar following this tutorial https://github.com/coolAlias/Forge_Tutorials/blob/master/IExtendedEntityPropertiesTutorial.java#L102 The bar actually works, is decreased as well. However if the player logout and then relogin the bar reset. This is the ExtendedProperties class i'm using package com.rpg.player; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class ExtendedPlayer implements IExtendedEntityProperties{ public final static String EXT_PROP_NAME = "ExtendedPlayer"; private final EntityPlayer player; private int currentMana; private int maxMana; public ExtendedPlayer(EntityPlayer player) { this.player = player; this.currentMana = this.maxMana = 50; } public static final void register(EntityPlayer player) { player.registerExtendedProperties(EXT_PROP_NAME, new ExtendedPlayer(player)); } public static final ExtendedPlayer get(EntityPlayer player) { return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setInteger("CurrentMana", this.currentMana); properties.setInteger("MaxMana", this.maxMana); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME); this.currentMana = properties.getInteger("CurrentMana"); this.maxMana = properties.getInteger("MaxMana"); System.out.println("[Mana from NBT] " + this.currentMana + "/" + this.maxMana); } @Override public void init(Entity entity, World world) {} public boolean consumeMana(int amount) { boolean sufficient = amount <= this.currentMana; this.currentMana -= (amount < this.currentMana ? amount : this.currentMana); return sufficient; } public int getCurrentMana() { return this.currentMana; } public int getMaxMana() { return this.maxMana; } public void replenishMana() { this.currentMana = this.maxMana; } } And this is the EventHandler package com.rpg.events; import com.rpg.player.ExtendedPlayer; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.entity.EntityEvent.EntityConstructing; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class EventHandler { @SubscribeEvent public void onEntityConstructing(EntityConstructing event) { if(event.entity instanceof EntityPlayer && ExtendedPlayer.get((EntityPlayer)event.entity) == null) { ExtendedPlayer.register((EntityPlayer)event.entity); } } } Every time a player relogs in the world, the readFromNBT prints out that the current mana is 50 (the max mana value). How can i solve this?
  2. The 2nd ingredient check was used because i was able to brew a longer levitation potion with the same item, but i guess there's a better way to avoid this. So basically i should return a copy of the output stack? EDIT: returning the copy of the stack has solved that problem. Thank you for the help
  3. Ok, so i've added a custom implementation for the brewing recipe package com.mineworld.crafting; import com.mineworld.core.MWItems; import net.minecraft.init.Items; import net.minecraft.init.PotionTypes; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionEffect; import net.minecraft.potion.PotionHelper; import net.minecraft.potion.PotionUtils; import net.minecraftforge.common.brewing.BrewingRecipeRegistry; import net.minecraftforge.common.brewing.IBrewingRecipe; public class PotionRecipes implements IBrewingRecipe{ private ItemStack input; private ItemStack ingredient; private ItemStack output; public PotionRecipes(ItemStack input, ItemStack ingredient, ItemStack output) { this.input = input; this.ingredient = ingredient; this.output = output; } @Override public boolean isInput(ItemStack input2) { if(!input2.hasTagCompound()) return false; return input2.getTagCompound().getString("Potion").equals(this.input.getTagCompound().getString("Potion")); } @Override public boolean isIngredient(ItemStack ingredient2) { return ingredient2.getItem().equals(Items.REDSTONE) || ingredient2.getItem().equals(Items.GLOWSTONE_DUST) || ingredient2.getItem().equals(Items.COAL) || ingredient2.getItem().equals(MWItems.shulker_bullet); } @Override public ItemStack getOutput(ItemStack input2, ItemStack ingredient2) { if(ingredient2 != null && input2 != null && isInput(input2) && isIngredient(ingredient2) && ingredient2.getItem().equals(this.ingredient.getItem())) { return this.output; } else return null; } } And this is how i add potion recipes now package com.mineworld.crafting; import com.mineworld.core.MWBlocks; import com.mineworld.core.MWItems; import com.mineworld.core.MWPotions; import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.init.PotionTypes; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.Item; import net.minecraft.item.ItemDye; import net.minecraft.item.ItemStack; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionUtils; import net.minecraftforge.common.brewing.BrewingRecipeRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; public class CraftingPotions { public CraftingPotions() { BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), PotionTypes.POISON), new ItemStack(Items.COAL, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither), new ItemStack(Items.REDSTONE, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_wither))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither), new ItemStack(Items.GLOWSTONE_DUST, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither2))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither), new ItemStack(Items.REDSTONE, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_wither))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither), new ItemStack(Items.GLOWSTONE_DUST, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither2))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither), new ItemStack(Items.REDSTONE, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.long_wither))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither), new ItemStack(Items.GLOWSTONE_DUST, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither2))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), PotionTypes.AWKWARD), new ItemStack(MWItems.shulker_bullet, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.levitation))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.levitation), new ItemStack(Items.REDSTONE, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_levitation))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.levitation), new ItemStack(Items.REDSTONE, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_levitation))); BrewingRecipeRegistry.addRecipe(new PotionRecipes(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.levitation), new ItemStack(Items.REDSTONE, 1), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.long_levitation))); } } But in result of the brewing, if i use 2 or 3 base potions, only 1 of them is "valid". Sometimes i get the 0-stack item, sometimes the stack looks like a potion but when i click on it it disappear What could be the cause of this?
  4. Ok i will try it, i've never write a custom recipe implementation, i hope is not so hard to do it
  5. Wich is what i've done. The fact is that the crafting recipe doesn't work. Here is a video explaining what happens now And these are all the brewing recipes i add package com.mineworld.crafting; import com.mineworld.core.MWBlocks; import com.mineworld.core.MWItems; import com.mineworld.core.MWPotions; import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.init.PotionTypes; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.Item; import net.minecraft.item.ItemDye; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionUtils; import net.minecraftforge.common.brewing.BrewingRecipeRegistry; import net.minecraftforge.fml.common.registry.GameRegistry; public class CraftingPotions { public CraftingPotions() { BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), PotionTypes.POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), PotionTypes.LONG_POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), PotionTypes.STRONG_POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), PotionTypes.POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), PotionTypes.LONG_POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), PotionTypes.STRONG_POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), PotionTypes.POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), PotionTypes.LONG_POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), PotionTypes.STRONG_POISON), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither), new ItemStack(Items.REDSTONE, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither), new ItemStack(Items.REDSTONE, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither), new ItemStack(Items.REDSTONE, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither), new ItemStack(Items.GLOWSTONE_DUST, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_wither), new ItemStack(Items.GLOWSTONE_DUST, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither), new ItemStack(Items.GLOWSTONE_DUST, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_wither), new ItemStack(Items.GLOWSTONE_DUST, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither), new ItemStack(Items.GLOWSTONE_DUST, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.long_wither), new ItemStack(Items.GLOWSTONE_DUST, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_wither), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither2), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_wither), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.long_wither)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.wither2), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.wither2)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), PotionTypes.WATER), new ItemStack(Items.FEATHER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.levitation)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.levitation), new ItemStack(Items.REDSTONE, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_levitation)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.levitation), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.levitation)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.long_levitation), new ItemStack(Items.GUNPOWDER, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_levitation)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.levitation), new ItemStack(Items.DRAGON_BREATH, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.levitation)); BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.SPLASH_POTION, 1), MWPotions.long_levitation), new ItemStack(Items.DRAGON_BREATH, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.LINGERING_POTION, 1), MWPotions.long_levitation)); } } Also these are the PotionTypes declared public static PotionType wither; public static PotionType long_wither; public static PotionType wither2; public static PotionType levitation; public static PotionType long_levitation; wither = new PotionType(new PotionEffect(MobEffects.WITHER, 900)).setRegistryName("wither"); long_wither = new PotionType(new PotionEffect(MobEffects.WITHER, 1800)).setRegistryName("long_wither"); wither2 = new PotionType(new PotionEffect(MobEffects.WITHER, 420, 1)).setRegistryName("wither2"); levitation = new PotionType(new PotionEffect(MobEffects.LEVITATION, 900)).setRegistryName("levitation"); long_levitation = new PotionType(new PotionEffect(MobEffects.LEVITATION, 1800)).setRegistryName("long_levitation"); GameRegistry.register(wither); GameRegistry.register(long_wither); GameRegistry.register(wither2); GameRegistry.register(levitation); GameRegistry.register(long_levitation);
  6. Creating a new PotionType adds a new potion to the game (wich i used to add the wither and levitation potion). But in crafting i want that only if the poison potion with 45 seconds duration is in the brewing stand the process can start. If there is a poison 2 potion the brewing must give a different result. I've tried doing this public static PotionType poison; poison = new PotionType(new PotionEffect(MobEffects.POISON, 900)).setRegistryName("poison"); GameRegistry.register(poison); but instead it adds a new poison 1 potion to the game with 45 second duration. So i've tried doing this BrewingRecipeRegistry.addRecipe(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), new PotionType(new PotionEffect(MobEffects.POISON, 900))), new ItemStack(Items.COAL, 1, 0), PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM, 1), MWPotions.wither)); But i can still brew the wither potion using the poison 2 potion as base
  7. Thanks, now is working But if i want that only the poison 1 with 45 seconds duration can be turned into the new potion how can i do?
  8. I was trying adding a new brewing recipe for a potion i made. The idea is that adding coal in the brewing stand to a potion of poison will give the new potion. However the brewing process doesn't start (but it start if i remove the metadata value, so with a generic potion it works). The code i'm using is this BrewingRecipeRegistry.addRecipe(new ItemStack(Items.POTIONITEM, 1, PotionType.getID(PotionTypes.POISON)), new ItemStack(Items.COAL, 1, 0), new ItemStack(MWItems.wither_potion, 1)); But as i said it doesn't work So how can i use the potion of poison in this recipe?
  9. Oh, that was easier than i thought
  10. Mmm, so i could check the BlockBreakingEvent and there check if the tool i'm using is enchanted with this enchant right?
  11. As i said i'm new to enchantments, so which will be a good approach to add one? I've deleted that base class, so now i have only the enchantment class package com.mineworld.enchantments; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnumEnchantmentType; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Enchantments; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; public class EnchantmentSmelting extends Enchantment { public EnchantmentSmelting() { super(Rarity.UNCOMMON, EnumEnchantmentType.DIGGER,new EntityEquipmentSlot[]{EntityEquipmentSlot.MAINHAND, EntityEquipmentSlot.OFFHAND}); this.setRegistryName("smelting"); } @Override public int getMaxLevel() { return 1; } @Override public String getName() { return "enchantment.smelting.name"; } @Override public boolean canApplyAtEnchantingTable(ItemStack stack) { return true; } @Override public boolean isAllowedOnBooks() { return true; } @Override public boolean canApplyTogether(Enchantment ench) { return super.canApplyTogether(ench) && ench != Enchantments.SILK_TOUCH; } @Override public int getMinEnchantability(int enchantmentLevel) { return 1 + 10 * (enchantmentLevel - 1); } @Override public int getMaxEnchantability(int enchantmentLevel) { return super.getMinEnchantability(enchantmentLevel) + 50; } } But looking at the function i can override in this class i don't find anything that could lead me to define what the performAction function do
  12. Yes, i've changed to this sourceCompatibility = 1.8 targetCompatibility = 1.8 and it worked
  13. So i was trying adding the smelting enchant on the pickaxe, using the CraftPlusPlus code, but is not working. This is the first time i try adding an enchant, so i don't know nothing about them. I've also tried looking into other enchantments classes, like silk touch, but there is no code of the tool behavior on that enchant. At the moment i'm using this as a base class for all the custom enchantments package com.mineworld.core; import java.util.List; import java.util.OptionalInt; import java.util.stream.IntStream; import com.google.common.collect.Lists; import com.mineworld.MW; import net.minecraft.client.resources.I18n; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnumEnchantmentType; import net.minecraft.entity.Entity; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.eventhandler.Event; import net.minecraftforge.fml.common.registry.GameRegistry; public abstract class MWEnchantment extends Enchantment { /** * A list of all of Craft++'s enchantments */ public static List<MWEnchantment> Enchantments = Lists.newArrayList(); protected MWEnchantment(String name, Enchantment.Rarity rarityIn, EnumEnchantmentType typeIn, EntityEquipmentSlot... slots) { super(rarityIn, typeIn, slots); this.setName(name); Enchantment.REGISTRY.register(findFreeEnchantmentID(name), new ResourceLocation(MW.MODID + ":" + name), this); Enchantments.add(this); } /** * Finds the first free enchantment ID to register this enchantment * * @param enchantmentName the name of the enchantment * @return The enchantment ID for this enchantment to use */ private static int findFreeEnchantmentID(String enchantmentName) { OptionalInt freeEnchantmentID = IntStream.range(0, 256).filter(i -> Enchantment.getEnchantmentByID(i) == null).findFirst(); if (!freeEnchantmentID.isPresent()) throw new NoFreeEnchantmentIDException(enchantmentName); return freeEnchantmentID.getAsInt(); } @Override public boolean isAllowedOnBooks() { return true; } /** * Gets the enchantment level of this enchantment on the specified ItemStack * * @param itemstack The ItemStack to check * @return The enchantment level of this enchantment on the ItemStack */ protected int getEnchantmentLevel(ItemStack itemstack) { return EnchantmentHelper.getEnchantmentLevel(this, itemstack); } @Override public int getMinEnchantability(int enchantmentLevel) { return getMinimumEnchantability(enchantmentLevel); } @Override public int getMaxEnchantability(int enchantmentLevel) { return getMaximumEnchantability(enchantmentLevel); } /** * Performs the action this enchantment does * * @param entity The entity to go along with the enchantment * @param baseEvent The event to go along with the enchantment */ public abstract void performAction(Entity entity, Event baseEvent); public abstract int getMinimumEnchantability(int enchantmentLevel); public abstract int getMaximumEnchantability(int enchantmentLevel); private static class NoFreeEnchantmentIDException extends RuntimeException { private NoFreeEnchantmentIDException(String enchantmentName) { super("Could not find a free enchantment ID for " + I18n.format("enchantment." + enchantmentName)); } } } And this as the class of the smelting enchant package com.mineworld.enchantments; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Random; import com.mineworld.core.MWEnchantment; import net.minecraft.enchantment.EnumEnchantmentType; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraftforge.event.world.BlockEvent.HarvestDropsEvent; import net.minecraftforge.fml.common.eventhandler.Event; public class EnchantmentSmelting extends MWEnchantment { public EnchantmentSmelting() { super("smelting", Rarity.UNCOMMON, EnumEnchantmentType.DIGGER,new EntityEquipmentSlot[]{EntityEquipmentSlot.MAINHAND, EntityEquipmentSlot.OFFHAND}); } @Override public int getMaxLevel() { return 1; } @Override public String getName() { return "enchantment.smelting.name"; } @Override public boolean canApplyAtEnchantingTable(ItemStack stack) { return true; } @Override public boolean isAllowedOnBooks() { return true; } @Override public void performAction(Entity entity, Event baseEvent) { if (entity != null && this.getEnchantmentLevel(((EntityLivingBase) entity).getHeldItemMainhand()) > 0) { HarvestDropsEvent event = (HarvestDropsEvent) baseEvent; List<ItemStack> drops = event.getDrops(); List<ItemStack> dropsCopy = this.copyList(drops); drops.clear(); for (ItemStack drop : dropsCopy) if (drop != null) { ItemStack smeltingResult = FurnaceRecipes.instance().getSmeltingResult(drop); if (smeltingResult != null) { smeltingResult = smeltingResult.copy(); smeltingResult.stackSize *= drop.stackSize; int fortuneLevel = event.getFortuneLevel(); if (!(smeltingResult.getItem() instanceof ItemBlock)) smeltingResult.stackSize *= new Random().nextInt(fortuneLevel + 1) + 1; drops.add(smeltingResult); } else drops.add(drop); } } } public static <T> List<T> copyList(List<T> list) { try { Constructor constructor = list.getClass().getConstructor(Collection.class); return (List<T>) constructor.newInstance(list); } catch (Exception exception) { return new ArrayList<>(list); } } @Override public int getMinimumEnchantability(int enchantmentLevel) { return 1 + 10 * (enchantmentLevel - 1); } @Override public int getMaximumEnchantability(int enchantmentLevel) { return super.getMinEnchantability(enchantmentLevel) + 50; } } I'm also registring the enchant in the preInit method by simply calling the EnchantmentSmelting class new EnchantmentSmelting(); As i said the performAction function is never called, so wich function i had to write to make this enchant actually work? Thanks in advance for your help
  14. So how can i compile in Java 8? In Eclipse the project is using Java 8, infact it gives me no error on there EIDT: turns out i had to add these lines to the build.gradle file sourceCompatibility = 1.7 targetCompatibility = 1.7
  15. The source of the mod is compiled in Java 8 (to allow lambda expressions in the GrassColourHandler), but when exporting it says that the mod cannot be exported in Java 8. This is the console error How can i solve it?
  16. Thanks for the explanation, i'll group all items into one array and add that, and also lowering the randomChance value to something valid (like 0.5)
  17. Thank you That works, but i want to know if i can improve my code. Right now i have this @SubscribeEvent public void onLootTableLoad(LootTableLoadEvent event) { ResourceLocation name = event.getName(); LootTable table = event.getTable(); LootCondition[] chance = {new RandomChance(50.0F)}; LootFunction[] count = {new SetCount(chance, new RandomValueRange(1.0F, 4.0F))}; LootFunction[] meta = {new SetMetadata(chance, new RandomValueRange(0.0F, 1.0F))}; LootEntryItem[] item = {new LootEntryItem(MWItems.ruby, 50, 1, count, chance, "ruby")}; LootEntryItem[] log = {new LootEntryItem(Item.getItemFromBlock(MWMetadataBlocks.log), 50, 1, meta, chance, "log")}; if(name.equals(LootTableList.CHESTS_SPAWN_BONUS_CHEST)) { table.addPool(new LootPool(item, chance, new RandomValueRange(1.0F), new RandomValueRange(0.0F), "ruby")); table.addPool(new LootPool(log, chance, new RandomValueRange(1.0F), new RandomValueRange(0.0F), "log")); } } wich i think is not the best code (expecially the randomChanceValue)
  18. So i'm trying to add items and blocks to vanilla dungeon chests using the LootTableLoadEvent. But i don't understand much of how to add them. I know i have to do this event.getTable().addPool(new LootPool(new LootEntryItem(itemIn, weightIn, qualityIn, functionsIn, conditionsIn, entryName), poolConditionsIn, rollsIn, bonusRollsIn, name)); but i didn't understand what to place instead of parameters. Also how can i add a sub block to the loot, because from the Item.getItemFromBlock i get only the default value of the block
  19. So i have to move to 1.9.4? Because that is the latest version i see on the site for MC-1.9
  20. As i said, for some reason, i have no LootTableLoadEvent class I'm using the Forge version 1.9-12.16.1.1887
  21. In Forge 1.9 ChestGenHooks has been removed due to loot tables. I've found an onld post saying that i have to hook the LootTableLoadEvent, but i can't find it. So how can i add some items to dungeon chests?
  22. If the fog isn't necessarly you can try removing all the fog related methods in the World Provider Also could you tell me how you registered the dimension?
×
×
  • Create New...

Important Information

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