Jump to content

FireController1847

Members
  • Posts

    290
  • Joined

  • Last visited

Everything posted by FireController1847

  1. Apologies if I'm misunderstanding, I'm having a hard time wrapping my head around this. So the "instance" is the object that is attached to each entity, correct? Say, if I have a capability called MoreHealth, the "instance" is an instance of MoreHealth, right? Also, to create a capability on a per-entity basis, does Forge do that for me when I attach it? If the instance is a static on the provider class, wouldn't the same instance be used if you call getCapability on different entities? On a similar note, I have no idea what to do in the if statement for the getCapability function. I've seen examples of calling a "cast" function, but none of them appear to work on the latest forge. This is my class currently: package com.firecontroller1847.levelhearts.capabilities; import net.minecraft.nbt.INBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; public class MoreHealthProvider implements ICapabilitySerializable<INBT> { @CapabilityInject(IMoreHealth.class) public static Capability<IMoreHealth> MORE_HEALTH_CAPABILITY; private LazyOptional<IMoreHealth> instance = LazyOptional.of(MORE_HEALTH_CAPABILITY::getDefaultInstance); @Override public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return cap == MORE_HEALTH_CAPABILITY ? ???????? : LazyOptional.empty(); // I have no idea what to return here } @Override public INBT serializeNBT() { // TODO return null; } @Override public void deserializeNBT(INBT nbt) { // TODO } }
  2. So sorry for my very late response. Gotta love the beginning of the week, have no freetime haha. This is interesting... If I extend the ICapabilitySerializable or something like that, and my instance is a lazy optional, what do I do for the writeNBT and the readNBT functions? I need to be able to have the instance to write and read the NBT data to it, no? Also, I don't quite think one of my questions was answered.... Does the instance exist for every entity it is attached to, or is there one global instance that is used between all of them? Similarly, if my mod only applies to players, wouldn't that be a huge waste of space adding it to every entity? The way my mod works now (by caching PlayerData and manually updating their NBT data) would be much more efficient in this case, and I don't see any reason why I would want to or need to switch to capabilities.
  3. Thank you, these helped a lot. One thing I couldn't figure out when I was implementing the ICapabilityProvider was what a LazyOption or something was, and how to properly return the capability. I do not understand how that works; does it create a new instance of my capability every time the getCapability is called or is the one instance I make in my provider uses for everything?
  4. I cannot for the life of me understand how capabilities work. It may just be the way I'm needing to implement them, so I'll be talking about that specifically. I'm currently making a mod that adds a modifier to the player's health to allow for more than just the generic 20 max health. Previously I used a class that contained a player cache and had functions to store and modify the NBT data of said player. Well, I was recently told to use capabilities now, but I have absolutely no idea how to do that. From what I understand, capabilities are supposed to be an easy way to store data alongside Minecraft classes. For example, an easy way to store data for a furnace or something. What I don't understand is how the hell this is supposed to work; what is a capability? Is it a modification to the way things work? Or is it supposed to be an easy interface between NBT data and Minecraft objects? How the hell do you attach a capability to an Entity? Do I need to provide my own Capability Provider, or use one of Forge's? If I need to use one of Forge's, which one do i use? How do I provide my own, in the case I need to do that (the forge documentation is useless and outdated). What does it mean to "expose" a capability? What is a capability type? What does it mean to "attach" a capability? Capabilities do not make sense at all! I will attempt to break this down so you can understand what I don't: "In general terms, each capability provides a feature in the form of an interface, alongside with a default implementation which can be requested, and a storage handler for at least this default implementation. " "each capability provides a feature in the form of an interface," what does this even mean? I've completed my college course on Java and still have no idea what this implies. A Java interface is used to easily describe classes and provides a layer of abstraction, it is not supposed to provide features. You cannot "implement" a feature using an interface. "alongside with a default implementation which can be requested," what? A default implementation versus... what, a custom one? Someone else's? Why not just implement what you need instead of attempting to provide an interface? "a storage handler for at least this default implementation," again, what is this 'default implementation', and what other types of implementations are there? Also, what in the world is this implementation? I, alongside many others, learn best by example, but the examples on the Forge docs don't provide any context whatsoever. The text refers to things that haven't been talked about, and implies that you have already created things that you didn't even know existed. How am I supposed to have made an "instance of the underlying capability type" if I didn't even know I needed to make one? Maybe I'm just having a hard time understanding Forge's documentation, but I have no idea what capabilities are supposed to be, what they provide in functionality, and how they're supposed to be "easier" than just directly interfacing with a player's NBT data. And yes, I have looked in the source, and no, it doesn't help whatsoever because if I don't even know what they do in the first place how am I supposed to understand an implementation? Note: Once I truly understand the purpose of a capability and how to implement one, I would love to make a PR to help improve the wording of the docs.
  5. Unfortunately, no, it is not called when KeepInventory is off. And it makes sense this didn't fix it, as when you look at the code that calls this event (found in LivingEntity#onDeathUpdate), it loops and does NOT check any gamerules. Actually, what happens is it calls getExperiencePoints from the entity, which is overridden for PlayerEntity to be 0 when KeepInventory is enabled (found in PlayerEntity#getExperiencePoints). I can't see any reason why it is not being called for the player. I know it's begin called for other mobs as it does log to console that it's been called when I add a sysout. I'm curious if this is a Forge bug, should I report it?
  6. Hello! I have a mod that currently forces a player to drop their experience even if the keepInventory gameRule is enabled. To do so, I used the LivingExperienceDropEvent and detected whether or not the event.getEntity was an instanceof a PlayerEvent. This worked fine up until I updated from 1.14.3 to 1.14.4. For some reason, it does not appear to be called at all for the PlayerEntity when they die, however it is called for other mobs. Any ideas? @SubscribeEvent public static void onLivingExperienceDrop(LivingExperienceDropEvent event) { if (!LevelHeartsConfig.XP.loseOnDeath.get() || !(event.getEntity() instanceof PlayerEntity)) return; PlayerEntity player = (PlayerEntity) event.getEntity(); int i = player.experienceLevel * 7; event.setDroppedExperience(i > 100 ? 100 : i); } I am currently using Minecraft Forge 28.0.45, as I just updated to fix various other issues with the mod.
  7. Well I'm just as dumb as can be, aren't I? I found the LivingExperienceDropEvent (through slowly going back and forth and missing a line of code). I'm assuming I can use this to set the player's experience drop based on EntityPlayer#getExperiencePoints.
  8. Hello! I'm curious how to make the player lose their experience even if keepInventory is on. I originally attempted to just set their experience level to zero, right until I realized that the game also DROPS experience when you die! So Now it's confusing the crap out of me. My attempt 1.12 code: @SubscribeEvent public void onPlayerRespawn(PlayerRespawnEvent event) { event.player.experienceLevel = 0; event.player.experience = 0.0f; } @SubscribeEvent public void onPlayerPickupXp(PlayerPickupXpEvent event) { event.getOrb().xpValue *= LevelHeartsConfig.xp.multiplier; } I've looked at EntityLivingBase#onDeathUpdate, and it uses EntityLivingBase#getExperiencePoints to determine how many to drop. EntityPlayer#getExperiencePoints overrides this to return 0 if the world has "keepInventory" enabled. How would I be able to override/change this method so that it always returns the experience, even if keepInventory is enabled?
  9. My apologies, I was looking within the code but somehow happened to miss this entirely. So sorry, thanks!
  10. In previous versions of Minecraft (1.13-), I was able to create an NBTTagCompound and then run .setTag on the EntityData to set my compound to the entity. However, in 1.14, it appears this is different. How do I set a compound tag to the entity data via NBT? Old code: public void saveToPlayer(EntityPlayer player) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("minHealth", this.defHealth); tag.setDouble("modifier", this.modifier); tag.setByte("heartContainers", this.heartContainers); tag.setShort("levelRampPosition", this.levelRampPosition); player.getEntityData().setTag(LevelHearts.NBT_ID, tag); } New (attempt) code: public void saveToPlayer(PlayerEntity player) { CompoundNBT tag = new CompoundNBT(); tag.putByte("minHealth", this.defHealth); tag.putDouble("modifier", this.modifier); tag.putByte("heartContainers", this.heartContainers); tag.putShort("levelRampPosition", this.levelRampPosition); player.getEntityData().setTag(LevelHearts.NBT_ID, tag); // There is no "setTag" option here, what do I do? }
  11. Thanks, this will work for me. I don't mind it resetting the whole array; if I go through with this, the comment can specify that it MUST be in the range otherwise it resets.
  12. First of all, can I just say I really, really miss the annotation config system. It was simple and easy to use and made making configurations so much better. However, I'm not here to rant. I have figured out how to use the builder and make an array using the builder, however what I can't figure out is how I set the range for said array. I can set a range for a regular ConfigValue<Integer>, but I cannot a ConfigValue<Integer[]>. What the previous annotation did is that if you defined a range with an array, it would disallow values smaller than and bigger than that to be in the array. I can't do that at all now, from what I can tell. Here's my current code: levelRamp = builder.define("Level Ramp", new ArrayList<Integer>( Arrays.asList(1, 5, 10, 15, 20, 25, 30, 34, 38, 42, 46, 50, 53, 56, 59, 62, 64, 66, 68, 70, 75, 80, 85, 90, 95, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200))); As you can see, I can define the array, but I cannot define a range. What do I do?
  13. Okay, after some experimentation, I have determined that I am an idiot and that I have been doing events entirely wrong and I even knew it from the beginning. Disregard my last statement, I was able to get the block model to override. Back to experimentation...
  14. Okay, I think I understand the states & modeldata, but what I don't quite understand is how to override the block's IBakedModel with my own model. In the example that, admittedly, @desht said wouldn't work, they get the quads and such from the state (which is depreciated, what do I replace that with??), and then use those quads in their custom model. However, I don't understand how to make my custom IBakedModel override my block's model. Is there a specific registry that I'd need to replace/register it under? Also, if someone could help me out by telling me how to disable this crap that'd be awesome: [21:22:39.771] [Server thread/DEBUG] [ne.mi.re.ForgeRegistry/REGISTRYDUMP]: Registry Name: minecraft:enchantments Entry: 0, minecraft:protection, net.minecraft.enchantment.EnchantmentProtection@783b3aa0 Entry: 1, minecraft:fire_protection, net.minecraft.enchantment.EnchantmentProtection@2ec85a25 Entry: 2, minecraft:feather_falling, net.minecraft.enchantment.EnchantmentProtection@4c176ff1 Entry: 3, minecraft:blast_protection, net.minecraft.enchantment.EnchantmentProtection@27c53c32 Entry: 4, minecraft:projectile_protection, net.minecraft.enchantment.EnchantmentProtection@68aec50 Entry: 5, minecraft:respiration, net.minecraft.enchantment.EnchantmentOxygen@1d60059f Entry: 6, minecraft:aqua_affinity, net.minecraft.enchantment.EnchantmentWaterWorker@427308f8
  15. @desht @Cadiboo Thanks for the resources, I'll check them out and see what I can hack up. I'll report back here and if it worked I'll mark this as solved and let you guys know
  16. So I am currently developing mod that contains a block that needs to display/use the same texture as the block the player right clicks with. So in this situation, this block will "mimic" the look of another block. Here's where it might get even more complicated, though, is that I also need to modify the texture to be slightly transparent and have a blue hue. I don't expect support with those, but any help would be appreciated. I was reading this post about how to do it with a TileEntity, and I used the ironchest mod for examples on how to do that. However, it uses a method "getBlockTexture" and "getIcon" which, as far as I know, haven't existed for a long time. I've read some more up-to-date articles using the same method. I don't believe this method works in 1.13. Can someone describe to me how blocks render/display their texture, and if it's even possible to do what I want to do? Edit: I also read this post, but the same issue persists.
  17. I am not entirely sure if this is a bug, but I am currently using PlaceActivated to replace a block with the block the player right clicked with. I am trying to play the place sound, however when using playSound on the player and/or the world, the sound plays much higher pitched than placing the same block on the ground.Am I doing something wrong? Here's my code for the PlaceActivated event: @Override public boolean onBlockActivated(IBlockState state, World worldIn, BlockPos pos, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack itemstack = player.getHeldItemMainhand(); Item item = itemstack.getItem(); if (item == Items.AIR || item == Registry.iblk_blueprint) return false; Block block = Block.getBlockFromItem(item); if (block == Blocks.AIR || block == Registry.blk_blueprint) return false; worldIn.setBlockState(pos, block.getDefaultState()); if (!player.isCreative()) itemstack.setCount(itemstack.getCount() - 1); SoundType sound = block.getDefaultState().getSoundType(worldIn, pos, player); worldIn.playSound(null, pos, sound.getPlaceSound(), SoundCategory.BLOCKS, sound.getVolume(), sound.getPitch()); return true; }
  18. Nevermind, I can't believed I missed the text "registry events are fired right after preinitialization".
  19. Maybe I'm doing this wrong, but this is what I have right now... Can I register SoundEvents on CommonProxy or do they need to be in the main file? I don't see why a dedicated server would need to register sound events so this made sense to me. RegisterSoundEvent.java public class RegisterSoundEvent { @SubscribeEvent public void registerSoundEvents(RegistryEvent.Register<SoundEvent> event) { System.out.println("SOUND EVENT REGISTER :) ----------------~~~~~~~~~"); // THIS IS NOT FIRING } } CommonProxy.java public class CommonProxy implements IProxy { @Override public void preInit() { // TODO Auto-generated method stub } @Override public void init() { MinecraftForge.EVENT_BUS.register(new RegisterSoundEvent()); // ... } @Override public void postInit() { // TODO Auto-generated method stub } } MainModFile.java (No, it's not actually called that) public class AdvancedMusic { @EventHandler public void preInit(FMLPreInitializationEvent event) { // ... proxy.preInit(); } @EventHandler public void init(FMLInitializationEvent event) { proxy.init(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { proxy.postInit(); } }
  20. I don't know, just the fact that there's another listener constantly checking for songs every client tick in the background. It's like having two full music systems running. But I have no problem doing it this way, I was just wondering if there was a better way I didn't know about
  21. So I've been working on a mod that completely overhauls the music system in Minecraft, but I have one issue that I don't want to let my little "hack" 'fix'. Basically, I have my own MusicTicker that handles its own randoms, but while mine runs the Minecraft music ticker runs in the background as well. Is there a way to disable it outright, or somehow override it, or is the code below the only way of "handling" it? The code below is how I am handling this right now... @SubscribeEvent public void onSoundPlayed(PlaySoundEvent event) { if (AdvancedMusic.musicTicker == null) return; if (event.getSound().getCategory() == SoundCategory.MUSIC) { System.out.println("SONG MUSIC"); if (!(event.getSound() instanceof Song)) { event.setResultSound(null); return; } if (AdvancedMusic.musicTicker.getCurrentMusic() == null) return; System.out.println("CUSTOM SONG MUSIC"); System.out.println("CURRENT SONG: " + AdvancedMusic.musicTicker.getCurrentMusic().getName()); } }
  22. Okok, before you get mad at me for posting this in Modder Support in my defense this has to do with modding and helping me figure out how forge works overall. But seriously, I've searched for hours and I cannot find any way to get an Eclipse workspace to go within an Eclipse project like Forge has done. How did you guys do that!?
  23. Ah, I see. What is the highest version I should go to that is still compatible with ForgeGradle?
×
×
  • Create New...

Important Information

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