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

Astro2202

Members
  • Content Count

    18
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Astro2202

  • Rank
    Tree Puncher
  1. Got it. if(cap.equals(DecayCapability.DECAY_CAPABILITY)){ return decayHandlerOptional.cast(); } else{ return LazyOptional.empty(); } Thank you very much for all your help! It's been incredibly useful.
  2. Like this? @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if(cap.getName() != DecayCapability.DECAY_CAPABILITY.getName()){ return LazyOptional.empty(); } else{ return decayHandlerOptional.cast(); } }
  3. I don't think I made it work yet but I'm on it. I removed both EventHandler and WorldDecayData. It was some unused leftover code from previous attempts. Fixed! I put the worldTickEvent in the EventHandler class and made it call a new method onTick() in DefaultDecay. I think this should fix that issue. I implemented the iterator instead and you are right this is much much better. Can you further elaborate on this? This is the part of the capability which I'm not fully sure of how it works. And both these
  4. https://github.com/Astro2202/DecayMod Edit: I'm not even sure what triggers this behavior. What I do is place blocks and wait for some of them to decay. I remove a block that hasn't decayed and a block that has. Then I sometimes reload the world and break another decayed and non-decayed block.
  5. So as a temporary solution I added a check to see if the dimension is the overworld and will only swap the block on the end phase: @SubscribeEvent public void onWorldTick(final TickEvent.WorldTickEvent event){ if(event.phase.equals(TickEvent.Phase.END)){ if(event.world.dimension().equals(World.OVERWORLD)){ swapBlock(event.world); } } } public void swapBlock(World world){ if(!world.isClientSide){ for(BlockPos blockPos : blockPosList){ if(random.nextInt(decayChance) == 0){
  6. Thank you for your advice! Instead of storing a hard reference I just use the current world object of the event every time to try and replace the block in: @SubscribeEvent public void onWorldTick(final TickEvent.WorldTickEvent event){ swapBlock(event.world); } public void swapBlock(World world){ if(!world.isClientSide){ for(BlockPos blockPos : blockPosList){ if(random.nextInt(decayChance) == 0){ System.out.println(blockPos + " is Decaying"); //System.out.println(world);
  7. So just to make sure that I get this right, the IDecay objects are not unloaded when I unload the world? I just put this "System.out.println("Initialized DefaultDecay");" in the constructor of DefaultDecay to see when it would be initialized and how many times. I don't fully understand why but when I load the world for the first time it's printed three times. When I quit to title and reload the world it's also printed three times. Doesn't this mean it's reinitialized? I'm just not sure if the IDecay object is actually unloaded or not when I reload the world. Edit: I already figured out th
  8. There is a specific scenario where the game breaks but doesn't crash and doesn't give me a crash report. My mod is supposed to replace certain blocks after a certain amount of time in the world. This already works. Quick explanation: It's a decay mod where blocks can break and decay until they are completely gone. Only blocks placed by the player are affected. I implemented it in to a capability in order to save which blocks need to change after the player would quit the world. So the decaying and the saving of which blocks need to decay already work but here's the problem. When
  9. Ok so this might be a lengthy one. (I think) I succeeded in fully implementing the capability and adding the implementation mentioned in my previous comment. I also removed the need of a decayhandler class and all logic that happened in the DecayHandler now takes places in the capability. The problem is that I'm experiencing the same issue that originally made me open this thread. The code stops running without error when I reload the world. I will post all relevant classes and carefully explain what the problem is. To start with: When I load a world, AttachCapabilitiesEvent&l
  10. So I've done some digging in to the capabilities system and I think I'm finally starting to understand it. I've tried to make use of the AttachCapabilitiesEvent<World> to add a capability with my DecayHandler class in it. When I would place a block I would set the decayhandler of that capability with the values of the block I placed. But there are two problems here. 1) I'm unsure of when and how many times the AttachCapabilitiesEvent<World> event is called. It could be that there is only one instance of this capability for what I know. Meaning that there also could be only one
  11. I do, but haven't put much though into it yet. I was trying to make it work in the overworld and worry about other worlds later. Thank you for your response. It seems that I have a lot of homework to do. I will take your feedback in to consideration and implement it accordingly. This might take a while but I'll update the thread if I either fix everything or get stuck again. Thank you for your time!
  12. The class is initialized in the BlockEvent.EntityPlaceEvent. EntityPlaceEvent @SubscribeEvent public static void onBlockPlace(final BlockEvent.EntityPlaceEvent placeEvent){ BlockState blockState = placeEvent.getPlacedBlock(); BlockPos pos = placeEvent.getPos(); System.out.println("placement"); if(blockState.getBlock().equals(Blocks.STONE_BRICKS)){ System.out.println("Stonebrick placed"); DecayHandler decayHandler = new DecayHandler(blockState, pos, world); decayHandlers.add(decayHandler); } } The OnT
  13. I wrote a class that stores the BlockPos and BlockState of a specific block that needs to be changed into another block after a certain amount of time. So far I just coded stone bricks being changed into cracked stone bricks. In every worldtickevent I call a method called onTick in which there is a slight chance (1 in 1000) that this change will occur. The class that does this is called DecayHandler.java DecayHandler.Java : public class DecayHandler { public BlockState blockState; public BlockPos blockPos; public World world; private Random random;
  14. Thank you @ChampionAsh5357 for your replies and useful feedback! I'll follow your advice and see where it takes me.
  15. What I already notice is that it's no longer markDirty() but setDirty(). I'll try to implement it as best as I can using these docs. Thank you very much! This wiki seems incredibly useful and I didn't even know it existed... If I still can't manage to let it work I'll post my current code. Edit: After having a closer look I soon found out that I have the same problems with this documentation. While it does give useful context about some of the uses and such of WorldSavedData, it's no longer up to date. The methods mentioned that you're supposed to use to make it work no longer exist
×
×
  • Create New...

Important Information

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