Jump to content

kykaro

Members
  • Posts

    4
  • Joined

  • Last visited

kykaro's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Thank you very much, I need to fix this and then get some sleep apparently.
  2. I have been trying to implement new capabilities into my mod, and I thought I had it working but I have encountered an error, with Crash report attached. Main Class @Mod(FantasyOres.MOD_ID) @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class FantasyOres { public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "fantasyores"; public FantasyOres() { final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff); EffectInit.EFFECTS.register(modEventBus); EffectInit.POTIONS.register(modEventBus); ItemInit.ITEMS.register(modEventBus); BlockInit.BLOCKS.register(modEventBus); BiomeInit.BIOMES.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public static void onRegisterItems(final RegistryEvent.Register<Item> event) { final IForgeRegistry<Item> registry = event.getRegistry(); BlockInit.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(block -> { final Item.Properties properties = new Item.Properties().group(FantasyOres.TAB); final BlockItem blockItem = new BlockItem(block, properties); blockItem.setRegistryName(block.getRegistryName()); registry.register(blockItem); }); } @SubscribeEvent public static void onRegisterBiomes(final RegistryEvent.Register<Biome> event) { BiomeInit.registerBiomes(); } private void setup(final FMLCommonSetupEvent event) { CapabilityManager.INSTANCE.register(IArmorSet.class, new ArmorSetInstance.Storage(), ArmorSetInstance::new); } private void doClientStuff(final FMLClientSetupEvent event) { } @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { } @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { } @SubscribeEvent public static void LoadCompleteEVent(FMLLoadCompleteEvent event) { ModOreGen.GenerateOre(); } public static final ItemGroup TAB = new ItemGroup("fantasyores_tab") { @Override public ItemStack createIcon() { return new ItemStack(BlockInit.UMBRIUM_ORE.get()); } }; } IArmorSet interface public interface IArmorSet { int getCount(); void setCount(int amt); } ArmorSetInstance public class ArmorSetInstance implements IArmorSet { private int setCount = 0; @Override public int getCount() { FantasyOres.LOGGER.info("GetCountCapability: " + setCount); return setCount; } @Override public void setCount(int amt) { setCount = amt; FantasyOres.LOGGER.info("SetCountCapability: " + setCount);} public static class Storage implements Capability.IStorage<IArmorSet> { @Nullable @Override public INBT writeNBT(Capability<IArmorSet> capability, IArmorSet instance, Direction side) { return IntNBT.valueOf(instance.getCount()); } @Override public void readNBT(Capability<IArmorSet> capability, IArmorSet instance, Direction side, INBT nbt) { instance.setCount(((IntNBT) nbt).getInt()); } } } ArmorSetCapability public class ArmorSetCapability implements ICapabilitySerializable<IntNBT> { @CapabilityInject(IArmorSet.class) public static final Capability<IArmorSet> ARMOR_SET_CAPABILITY = null; private LazyOptional<IArmorSet> instance = LazyOptional.of(ARMOR_SET_CAPABILITY::getDefaultInstance); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return ARMOR_SET_CAPABILITY.orEmpty(cap, instance); } @Override public IntNBT serializeNBT() { return (IntNBT) ARMOR_SET_CAPABILITY.getStorage().writeNBT(ARMOR_SET_CAPABILITY, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null); } @Override public void deserializeNBT(IntNBT nbt) { ARMOR_SET_CAPABILITY.getStorage().readNBT(ARMOR_SET_CAPABILITY, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null, nbt); } } SetArmorItem @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class SetArmorItem extends ArmorItem { private static int setCount = 0; private static int tick = 0; private static String set; public SetArmorItem(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder, String set) { super(materialIn, slot, builder); this.set = set; } public static void onEquipChange(LivingEquipmentChangeEvent e) { LivingEntity actor = e.getEntityLiving(); if(!actor.world.isRemote()) { if ( actor instanceof PlayerEntity ) { setCount = getItemsInSet(); //trimmed out the logic here to save space, //does nothing with capabilities and is known good code. //I just total the number of items equipped that belong to the set and store actor.getCapability(ArmorSetCapability.ARMOR_SET_CAPABILITY).ifPresent(cap -> cap.setCount(setCount)); } } } private void armorCount(int i) { setCount = i; FantasyOres.LOGGER.info(i); } //Just here for debugging, not needed @Override public void onArmorTick(ItemStack stack, World world, PlayerEntity player) { if (tick % 100 == 0) { //player.getCapability(ArmorSetCapability.ARMOR_SET_CAPABILITY).ifPresent(cap -> armorCount(cap.getCount())); } } CapabilitesEvent @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class CapabilitiesEvent { private static int tick = 0; @SubscribeEvent public static void addCapability(AttachCapabilitiesEvent<Entity> e) { if (e.getObject() instanceof PlayerEntity){ FantasyOres.LOGGER.info("addCapability fired for entity: " + e.getObject().getName()); e.addCapability(new ResourceLocation(FantasyOres.MOD_ID, "umbriumsetcount"), new ArmorSetCapability()); } } } I know its an error with the addCapability, but I cant tell what it is or how to correct it. I attempted to look at existing examples of code that implement custom capabilities, and that is partially what my code is based on, so it is possible I just missed a bit of code somewhere that is critical. And pointers would be helpful, thanks. crash-2020-05-19_17.14.16-server.txt
  3. Hi, so I am trying to make a custom regen effect that is enabled when the player wears a certain piece of armor. I thought making a custom potion effect would be the best way to go about that, but perhaps not (if you have a better idea I am all for it, I am new to modding minecraft). I have been able to register a new effect with forge and I figured the best time to check if they have the armor on is during the LivingEquipmentChangeEvent, that way its only firing on a trigger and not all the time. I am able to get the effect to show up, as in when they wear the item, they have the effect with artwork, proper name, proper swirl color, all that fun stuff, but the effect doesnt tick at all. I know I am doing something simple wrong, but I just cant quite figure it out. So //Where I add the effect @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ArmorEffect { @SubscribeEvent public static void onEquip(LivingEquipmentChangeEvent event) { LivingEntity actor = event.getEntityLiving(); if (actor instanceof PlayerEntity) { Iterable<ItemStack> equipment = actor.getEquipmentAndArmor(); //Increment through all equipped items for (ItemStack i : equipment) { //check against tag. since any ruby item should grant the effect //TODO there has to be a better way to do this if (i.getItem().getTags().toString().contains("fantasyores:ruby") { actor.addPotionEffect(new EffectInstance(EffectInit.RUBY_REGEN_EFFECT.get(),100,1)); } } } } //Where I register effect public class EffectInit { public static final DeferredRegister<Effect> EFFECTS = new DeferredRegister<>(ForgeRegistries.POTIONS, FantasyOres.MOD_ID); public static final DeferredRegister<Potion> POTIONS = new DeferredRegister<>(ForgeRegistries.POTION_TYPES, FantasyOres.MOD_ID); public static final RegistryObject<Effect> RUBY_REGEN_EFFECT = EFFECTS.register("ruby_regen",() -> new RegenEffect(EffectType.BENEFICIAL, 15151675)); public static final RegistryObject<Potion> RUBY_REGEN_POTION = POTIONS.register("ruby_regen", () -> new Potion(new EffectInstance(RUBY_REGEN_EFFECT.get()))); } //Regen Effect with debug public class RegenEffect extends Effect { public RegenEffect(EffectType typeIn, int liquidColorIn) { super(typeIn, liquidColorIn); FantasyOres.LOGGER.info("Constructor called"); } @Override public void performEffect(LivingEntity entityLivingBaseIn, int amplifier) { FantasyOres.LOGGER.info("Tick"); if (entityLivingBaseIn.getHealth() < entityLivingBaseIn.getMaxHealth()) { entityLivingBaseIn.heal(1.0F); } else { entityLivingBaseIn.heal((float)Math.max(4 << amplifier, 0)); } } @Override public void affectEntity(@Nullable Entity source, @Nullable Entity indirectSource, LivingEntity entityLivingBaseIn, int amplifier, double health) { FantasyOres.LOGGER.info("entity affected by ruby regen"); this.performEffect(entityLivingBaseIn, amplifier); } } //Main class @Mod(FantasyOres.MOD_ID) @Mod.EventBusSubscriber(modid = FantasyOres.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class FantasyOres { public static final Logger LOGGER = LogManager.getLogger(); public static final String MOD_ID = "fantasyores"; public FantasyOres() { final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); modEventBus.addListener(this::setup); modEventBus.addListener(this::doClientStuff); EffectInit.EFFECTS.register(modEventBus); EffectInit.POTIONS.register(modEventBus); ItemInit.ITEMS.register(modEventBus); BlockInit.BLOCKS.register(modEventBus); BiomeInit.BIOMES.register(modEventBus); //DimensionInit.MOD_DIMENSIONS.register(modEventBus); MinecraftForge.EVENT_BUS.register(this); } @SubscribeEvent public static void onRegisterItems(final RegistryEvent.Register<Item> event) { final IForgeRegistry<Item> registry = event.getRegistry(); BlockInit.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(block -> { final Item.Properties properties = new Item.Properties().group(FantasyOres.TAB); final BlockItem blockItem = new BlockItem(block, properties); blockItem.setRegistryName(block.getRegistryName()); registry.register(blockItem); }); } @SubscribeEvent public static void onRegisterBiomes(final RegistryEvent.Register<Biome> event) { BiomeInit.registerBiomes(); } private void setup(final FMLCommonSetupEvent event) { } private void doClientStuff(final FMLClientSetupEvent event) { } @SubscribeEvent public void onServerStarting(FMLServerStartingEvent event) { } @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD) public static class RegistryEvents { } @SubscribeEvent public static void LoadCompleteEvent(FMLLoadCompleteEvent event) { ModOreGen.GenerateOre(); } public static final ItemGroup TAB = new ItemGroup("fantasyores_tab") { @Override public ItemStack createIcon() { return new ItemStack(ItemInit.RUBY.get()); } }; } Any help is appreciated, sorry if the code is a bit messy, new to this all.
  4. Hey guys, I am working on a mod that adds new sets of ores to the game, I figured that would be a decent introduction to modding. So far I have been successful in adding an ore, its resource and all tools and whatnot. Now that I have a general understanding of it, I would like to see if its possible to spawn that ore only in the presence of a specific block, in this case lets just say within 5 blocks of lava. I know you would have to loop over all blocks around the ore and check for the specific block, but I am not sure where to do this. From a google session I found references to a WorldGenMinable class, but that seems to be from an older version as I cant find that in 1.15.2. Any suggestions on what I would have to override in order to achieve this? Ideally, I would like to make a new Placement Config like CountRangeNearBlockConfig where it would have the same features as CountRangeConfig, but with 2 additional variables for the block to check for and the range to search. That way I can set it individually when I add my feature. Any suggestions or if you know of a mod in 1.15.2 that has an ore block that has similar conditional spawning that I could look at would help. Thanks
×
×
  • Create New...

Important Information

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