Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

OberonPuck

Members
  • Posts

    9
  • Joined

  • Last visited

OberonPuck's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. I'm trying to prevent damage done by tipped arrows with beneficial effects. To do this I have a LivingHurtEvent that checks if the entity was an arrow. I just don't know how to access the effects of the arrow from the entity. Is there a way to access this information?
  2. I made a custom potion item that extends PotionItem and it works perfectly. I provided it with a multi-layer model with two layers, one for the "glass bottle" and one for the "potion liquid". However, when I loaded in, all of the custom potions used the same, default texture. So I went into ItemColors and tried to replicate the code that registers the colors of other potion variants using PotionUtils.getColor. Even though the game didn't crash, the colors of the potions didn't change. I've checked multiple threads on this forum about similar issues, but they are either outdated and some of the methods don't work or they are only tangentially related. TLDR: How do I change the color of my custom potions' texture to match the effect? Here is my code for my potion item: //Commented out imports public class GelledPotionItem extends PotionItem { public GelledPotionItem(Item.Properties builder) { super(builder); } public ItemStack onItemUseFinish(ItemStack stack, World worldIn, LivingEntity entityLiving) { return null; } public int getUseDuration(ItemStack stack) { return 0; } public UseAction getUseAction(ItemStack stack) { return null; } public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { return null; } } Here is my main class: // Commented out imports // The value here should match an entry in the META-INF/mods.toml file @Mod("minormagicks") public class MinorMagicks { public static MinorMagicks instance; private static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "minormagicks"; public MinorMagicks() { instance = this; final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(this::setup); modEventBus.addListener(this::doClientStuff); ItemRegistryHandler.ITEMS.register(modEventBus); PotionRegistryHandler.POTIONS.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(new MinorMagicksForgeEventHandler()); } private void setup(final FMLCommonSetupEvent event) { MagicksItemColors.registerColors(); PotionRegistryHandler.replaceRecipes(); MagicksPotionBrewing.init(); } private void doClientStuff(final FMLClientSetupEvent event) { } } My model json for my item: { "parent": "item/generated", "textures": { "layer0": "minormagicks:items/gelled_potion_liquid", "layer1": "minormagicks:items/gelled_potion" } }
  3. So it has come to my attention that I have no idea what I am doing when it comes to events. I have one event, injectPotion, that is supposed to: Use the LivingHurtEvent to check if the true damage source is a player. Get the item in their hand. Check to see if that item is my custom potion item, which extends PotionItem. Then search that item for its effects And then apply those effects to the victim of the damage. However, this does not happen and I don't think the current issue is with how I am applying the effects, because I tried to replace the potion effect code with code that clears the player entity's inventory, and it still didn't work. So in short, how to I fix this event and is there a way to improve the quality of the code in my main class? Main Class: package com.oberonpuck.minormagicks; //All of imports are here but I commented them out for ease of reading // The value here should match an entry in the META-INF/mods.toml file @Mod("minormagicks") public class MinorMagicks { public static MinorMagicks instance; private static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "minormagicks"; public MinorMagicks() { instance = this; final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(this::setup); modEventBus.addListener(this::doClientStuff); modEventBus.addListener(this::injectPotion); ItemRegistryHandler.ITEMS.register(modEventBus); PotionRegistryHandler.POTIONS.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event) { PotionRegistryHandler.removeRecipes(); MagicksPotionBrewing.init(); } private void doClientStuff(final FMLClientSetupEvent event) { } private void injectPotion (LivingHurtEvent event) { if(event.getSource().getTrueSource() instanceof PlayerEntity) { PlayerEntity playerentity = (PlayerEntity) event.getSource().getTrueSource(); LivingEntity entityLiving = event.getEntityLiving(); ItemStack stack = playerentity.getHeldItemMainhand(); World world = playerentity.getEntityWorld(); if(stack.getItem() instanceof GelledPotionItem) { if (playerentity instanceof ServerPlayerEntity) { CriteriaTriggers.CONSUME_ITEM.trigger((ServerPlayerEntity)playerentity, stack); } if (!world.isRemote) { for(EffectInstance effectinstance : PotionUtils.getEffectsFromStack(stack)) { if (effectinstance.getPotion().isInstant()) { effectinstance.getPotion().affectEntity(playerentity, playerentity, entityLiving, effectinstance.getAmplifier(), 1.0D); } else { entityLiving.addPotionEffect(new EffectInstance(effectinstance)); } } } if (playerentity != null) { playerentity.addStat(Stats.ITEM_USED.get(ItemRegistryHandler.GELLED_POTION.get())); if (!playerentity.abilities.isCreativeMode) { stack.shrink(1); } } if (playerentity == null || !playerentity.abilities.isCreativeMode) { if (stack.isEmpty()) { playerentity.inventory.storeItemStack(new ItemStack(Items.GLASS_BOTTLE)); } if (playerentity != null) { playerentity.inventory.storeItemStack(new ItemStack(Items.GLASS_BOTTLE)); } } } } } }
  4. So, I don't know how to do that, but removing the .setAccessible worked like a charm. Thank you so much @ChampionAsh5357, and @Draco18s as well. Though, I have another issue that is tangentially related to potion brewing. Should I just ask it here or create a new thread?
  5. Okay, so I attempted to do as you said, but I think I went about it incorrectly. The crash log says that I cannot cast an ArrayList to an AccessibleObject. However, I do not know how to make the ArrayList accessible in another way. Here is my code. If you know a way to correct it, I would appreciate the help: private static List<IBrewingRecipe> recipeRegistryArray; @SuppressWarnings("unchecked") private static List<IBrewingRecipe> recipes() { if(recipeRegistryArray == null) { try { recipeRegistryArray = (List<IBrewingRecipe>)((ObfuscationReflectionHelper.findField(BrewingRecipeRegistry.class, "recipes").get(null))); } catch (IllegalArgumentException | IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } ((AccessibleObject) recipeRegistryArray).setAccessible(true); } return recipeRegistryArray; }
  6. Thanks, I will attempt to do so and let you know what ends up happening.
  7. Well, it turns out that problem was not that at all. I just needed to use the RegistryObjects of my new potions and then add ".get()" and use those for the recipes, instead of the ResourceLocations: public static void addBrewingRecipes() { addMix(Potions.AWKWARD, Items.ROTTEN_FLESH, PotionRegistryHandler.NASUEA.get()); addMix(PotionRegistryHandler.NASUEA.get(), Items.REDSTONE, PotionRegistryHandler.LONG_NASUEA.get()); addMix(PotionRegistryHandler.NASUEA.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.HUNGER.get()); addMix(PotionRegistryHandler.LONG_NASUEA.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_HUNGER.get()); addMix(Potions.AWKWARD, Items.EMERALD, Potions.LUCK); addMix(Potions.LUCK, Items.REDSTONE, PotionRegistryHandler.LONG_LUCK.get()); addMix(Potions.LUCK, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.UNLUCK.get()); addMix(PotionRegistryHandler.LONG_LUCK.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_UNLUCK.get()); addMix(Potions.WATER_BREATHING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.DOLPHINS_GRACE.get()); addMix(Potions.LONG_WATER_BREATHING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_DOLPHINS_GRACE.get()); addMix(Potions.AWKWARD, Items.SHULKER_SHELL, PotionRegistryHandler.RESISTANCE.get()); addMix(PotionRegistryHandler.RESISTANCE.get(), Items.REDSTONE, PotionRegistryHandler.LONG_RESISTANCE.get()); addMix(PotionRegistryHandler.RESISTANCE.get(), Items.GLOWSTONE, PotionRegistryHandler.STRONG_RESISTANCE.get()); addMix(PotionRegistryHandler.RESISTANCE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.HEALTH_BOOST.get()); addMix(PotionRegistryHandler.LONG_RESISTANCE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_HEALTH_BOOST.get()); addMix(PotionRegistryHandler.STRONG_RESISTANCE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.STRONG_HEALTH_BOOST.get()); addMix(Potions.AWKWARD, Items.PRISMARINE_CRYSTALS, PotionRegistryHandler.HASTE.get()); addMix(PotionRegistryHandler.HASTE.get(), Items.REDSTONE, PotionRegistryHandler.LONG_HASTE.get()); addMix(PotionRegistryHandler.HASTE.get(), Items.GLOWSTONE, PotionRegistryHandler.STRONG_HASTE.get()); addMix(PotionRegistryHandler.HASTE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.MINING_FATIGUE.get()); addMix(PotionRegistryHandler.LONG_HASTE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_MINING_FATIGUE.get()); addMix(PotionRegistryHandler.STRONG_HASTE.get(), Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.STRONG_MINING_FATIGUE.get()); addMix(Potions.FIRE_RESISTANCE, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.ABSORPTION.get()); addMix(Potions.LONG_FIRE_RESISTANCE, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_ABSORPTION.get()); addMix(Potions.SLOW_FALLING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LEVITATION.get()); addMix(Potions.LONG_SLOW_FALLING, Items.FERMENTED_SPIDER_EYE, PotionRegistryHandler.LONG_LEVITATION.get()); addMix(Potions.AWKWARD, Items.ENDER_EYE, PotionRegistryHandler.GLOWING.get()); addMix(PotionRegistryHandler.GLOWING.get(), Items.REDSTONE, PotionRegistryHandler.LONG_GLOWING.get()); addMix(PotionRegistryHandler.GLOWING.get(), Items.FERMENTED_SPIDER_EYE, Potions.INVISIBILITY); addMix(PotionRegistryHandler.LONG_GLOWING.get(), Items.FERMENTED_SPIDER_EYE, Potions.LONG_INVISIBILITY); }
  8. I have been doing some research to figure out how to remove recipes from the BrewingRecipeRegistry. Most of the results I have found pertain to crafting recipes and are all from 1.12.2. I have tried to use the information for my mod, which is in 1.16, but it doesn't work. I am assuming this is because I am either missing some key concept or I botched the code. Regardless, one of the solutions I found was using IForgeRegistryModifiable#remove, but I am having trouble casting BrewingRecipeRegistry to make it modifiable and am not even sure if that is the correct way to go about this. But essentially what I want to do is this: BrewingRecipeRegistry.getEntries().remove(1); I know that is not the actual syntax and that it doesn't work because getEntries() returns an immutable list, but I hope you catch my gist. I have found ways to add brewing recipes, and this is the next logical step in my mod.
  9. I followed a tutorial on how to make custom potions for a minecraft mod, however, this was before deferred registries were used frequently. So I pieced together things from regular registries and deferred registries, however, I am having trouble. All but one of my custom recipes that use the Awkward Potion as a base results in an uncraftable potion, even though I can see, obtain, and use my custom potions from the creative tabs. The recipes that use my custom potions don't work at all. I think this is all because of the way I inputted my custom potions into the recipes, because the one recipe that uses all vanilla items works fine (an awkward potion and an emerald, creating a Potion of Luck). Am I missing something? Am I way off as to where the problem lies? My main class: package com.oberonpuck.minormagicks; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.oberonpuck.minormagicks.util.ItemRegistryHandler; import com.oberonpuck.minormagicks.util.PotionRegistryHandler; // The value here should match an entry in the META-INF/mods.toml file @Mod("minormagicks") public class MinorMagicks { private static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "minormagicks"; public MinorMagicks() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); ItemRegistryHandler.init(); PotionRegistryHandler.init(); MinecraftForge.EVENT_BUS.register(this); } private void setup(final FMLCommonSetupEvent event){} private void doClientStuff(final FMLClientSetupEvent event){} } My potion class for registering potions and recipes: package com.oberonpuck.minormagicks.util; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.function.Supplier; import com.oberonpuck.minormagicks.MinorMagicks; import com.oberonpuck.minormagicks.items.ItemBase; import net.minecraft.entity.ai.attributes.Attributes; import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.potion.Effect; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.EffectType; import net.minecraft.potion.Effects; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionBrewing; import net.minecraft.potion.Potions; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ObjectHolder; public class PotionRegistryHandler { public static final DeferredRegister<Potion> POTIONS = DeferredRegister.create(ForgeRegistries.POTION_TYPES, MinorMagicks.MOD_ID); public static final DeferredRegister<Effect> EFFECTS = DeferredRegister.create(ForgeRegistries.POTIONS, MinorMagicks.MOD_ID); public static void init () { POTIONS.register(FMLJavaModLoadingContext.get().getModEventBus()); PotionRegistryHandler.addBrewingRecipes(); } //Potions public static final RegistryObject<Potion> HUNGER = POTIONS.register("hunger", () -> new Potion(new EffectInstance(Effects.HUNGER, 3600))); public static final RegistryObject<Potion> RESISTANCE = POTIONS.register("resistance", () -> new Potion(new EffectInstance(Effects.RESISTANCE, 3600))); public static final RegistryObject<Potion> ABSORPTION = POTIONS.register("absorption", () -> new Potion(new EffectInstance(Effects.ABSORPTION, 3600))); public static final RegistryObject<Potion> HEALTH_BOOST = POTIONS.register("health_boost", () -> new Potion(new EffectInstance(Effects.HEALTH_BOOST, 3600))); public static final RegistryObject<Potion> HASTE = POTIONS.register("haste", () -> new Potion(new EffectInstance(Effects.HASTE, 3600))); public static final RegistryObject<Potion> MINING_FATIGUE = POTIONS.register("mining_fatigue", () -> new Potion(new EffectInstance(Effects.MINING_FATIGUE, 3600))); public static final RegistryObject<Potion> NASUEA = POTIONS.register("nausea", () -> new Potion(new EffectInstance(Effects.NAUSEA, 3600))); public static final RegistryObject<Potion> BLINDNESS = POTIONS.register("blindness", () -> new Potion(new EffectInstance(Effects.BLINDNESS, 3600))); public static final RegistryObject<Potion> GLOWING = POTIONS.register("glowing", () -> new Potion(new EffectInstance(Effects.GLOWING, 3600))); public static final RegistryObject<Potion> LEVITATION = POTIONS.register("levitation", () -> new Potion(new EffectInstance(Effects.LEVITATION, 3600))); public static final RegistryObject<Potion> DOLPHINS_GRACE = POTIONS.register("dolphins_grace", () -> new Potion(new EffectInstance(Effects.DOLPHINS_GRACE, 3600))); public static final RegistryObject<Potion> UNLUCK = POTIONS.register("unluck", () -> new Potion(new EffectInstance(Effects.UNLUCK, 3600))); private static Method brewing_mixes; private static void addMix(Potion start, Item ingredient, Potion result) { if(brewing_mixes == null) { brewing_mixes = ObfuscationReflectionHelper.findMethod(PotionBrewing.class, "addMix", Potion.class, Item.class, Potion.class); brewing_mixes.setAccessible(true); } try { brewing_mixes.invoke(null, start, ingredient, result); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } } static ResourceLocation nausea = new ResourceLocation("minormagicks:nausea"); static ResourceLocation hunger = new ResourceLocation("minormagicks:hunger"); static ResourceLocation unluck = new ResourceLocation("minormagicks:unluck"); static ResourceLocation dolphins_grace = new ResourceLocation("minormagicks:dolphins_grace"); static ResourceLocation resistance = new ResourceLocation("minormagicks:resistance"); static ResourceLocation health_boost = new ResourceLocation("minormagicks:health_boost"); static ResourceLocation haste = new ResourceLocation("minormagicks:haste"); static ResourceLocation mining_fatigue = new ResourceLocation("minormagicks:mining_fatigue"); static ResourceLocation absorption = new ResourceLocation("minormagicks:absorption"); static ResourceLocation levitation = new ResourceLocation("minormagicks:levitation"); public static void addBrewingRecipes() { addMix(Potions.AWKWARD, Items.ROTTEN_FLESH, ForgeRegistries.POTION_TYPES.getValue(nausea)); addMix(ForgeRegistries.POTION_TYPES.getValue(nausea), Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(hunger)); addMix(Potions.AWKWARD, Items.EMERALD, Potions.LUCK); addMix(Potions.LUCK, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(unluck)); addMix(Potions.WATER_BREATHING, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(dolphins_grace)); addMix(Potions.AWKWARD, Items.SHULKER_SHELL, ForgeRegistries.POTION_TYPES.getValue(resistance)); addMix(ForgeRegistries.POTION_TYPES.getValue(resistance), Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(health_boost)); addMix(Potions.AWKWARD, Items.PRISMARINE_CRYSTALS, ForgeRegistries.POTION_TYPES.getValue(haste)); addMix(ForgeRegistries.POTION_TYPES.getValue(haste), Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(mining_fatigue)); addMix(Potions.FIRE_RESISTANCE, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(absorption)); addMix(Potions.SLOW_FALLING, Items.FERMENTED_SPIDER_EYE, ForgeRegistries.POTION_TYPES.getValue(levitation)); } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.