TeamGalacticraft / Galacticraft

The classic space mod, rewritten for modern versions of Minecraft.
MIT License
398 stars 85 forks source link

Rocket does not break when launchpad is broken #323

Closed LeMayday closed 1 month ago

LeMayday commented 1 month ago

Mod Loader

Fabric

Version Information

688f2b2

Log or Crash Report

N/A

Reproduction steps

  1. Build 3x3 launch pad
  2. Place rocket on launch pad
  3. destroy launch pad
  4. observe rocket does not break
LeMayday commented 1 month ago

this is a tricky one. I can observe a problem in RocketLaunchPadBlockEntity.java. When you put a rocket on the pad, it links just fine via setLinkedRocket, but then when you destroy the pad, it calls hasRocket which doesn't seem to acknowledge that UUID and rocket should no longer be null. Thus the if statement if (pad.hasRocket()) in onRemove() in RocketLaunchPadBlock.java is never entered.

LeMayday commented 1 month ago

I'm not familiar with this syntax for instanceof, but my guess is the problem is here in RocketLaunchPadBlock.java: if (level.getBlockEntity(center.offset(x, 0, z)) instanceof RocketLaunchPadBlockEntity pad)

My guess is this constructs a new instance of RocketLaunchPadBlockEntity that does not have the data from before. I will continue looking into this

LeMayday commented 1 month ago

nvm just found out this is a thing called pattern matching

LeMayday commented 1 month ago

ok actually I wonder if it has anything to do with the fact that it seems to create like 2 new launchpadblock entities every time you place down a launch pad block (so there are 18 in total when you make the multiblock)

LeMayday commented 1 month ago

turns out I think the issue was that the call to super() in onRemove destroyed the launchpadblockentity before the rest of the function could figure out whether there was a rocket on it