Modders cannot get the type of boat from an AbnormalsBoatEntity easily
TelepathicGrunt opened this issue · 9 comments
Edit 2: ignore this comment. Read second comment below. I misunderstood the issue the first time around
To get the type of boat a vanilla boat entity is, the only way to do that is to check if entity is a BoatEntity, cast the entity to a boat, and call getBoatType() like so:
if (entity instanceof BoatEntity) {
BoatEntity boat = (BoatEntity)entity;
BoatEntity.Type type = boat.getBoatType();
However, doing this with an AbnormalsBoatEntity will crash the game as AbnormalsBoatEntity
does not store the boat type into the entity's dataManager (which makes BoatEntity.Type.byId(this.dataManager.get(BOAT_TYPE)); cause the crash).
Instead, it seems AbnormalsBoatEntity stores the type of boat into a string that is private by default.
https://github.com/minecraftabnormals/Abnormals-Core/blob/a2eead4f71c91267909bd69cae7bb0251f62d1a5/src/main/java/com/teamabnormals/abnormals_core/common/items/AbnormalsBoatItem.java#L35
So if any modder is using getBoatType() to get the type of boat with vanilla, they will crash the game if their mod encounters an AbnormalsBoatEntity. If they do add a safety check against AbnormalsBoatEntity and try to do direct support for it, they will need to use reflection to access AbnormalsBoatEntity's type instead.
If possible, can you see about storing the type of boat into the dataManager to help prevent crashes with other mods? If that isn't possible, then perhaps making the type string variable public will help so people won't need to use reflection.
Hope this helps!
Edit: Looks like I got confused. The type string is stored in AbnormalsBoatItem and not AbnormalsBoatEntity. Hmm. I'm not sure I can access the AbnormalsBoatItem from AbnormalsBoatEntity at all. rip
Ok, so I understand why you get that crash.
The AbnormalsBoatEntity
doesn't override getBoatType()
and it also doesn't register the data parameter that the normal boat entity would use to get the type.
Which leads to a null pointer, I'll look into this.
I'm unsure what you need the boat type for. If you can tell me I may be able to think of a way around this temporarily.
I was trying to determine if a Buzzier Bee boat entity is placed on my sugar water block in my Bumblezone dimension and if so, make the boat go faster than normal. The hard part is determining if said entity is Buzzier Bees’ hive boat as there’s no identifying information in the entity itself and other mods could extend AbnormalBoatEntity. What vanilla does is it uses the entity’s dataManager to determine what boat it is for rendering as that’s the only way to distinguish between different boat types with an entity.
It’s not super urgent to do as I’ll wait to do boat compat in a future update of my mod so no rush!
I sorta thought this through a bit when making the boats designed this way.
So, there is a method in AbnormalsBoatEntity
called getBoat()
. This will return a BoatData
from the boat registry. You can then get the boat item for the BoatData
by calling getBoatItem()
Thank you! I’ll test this out tomorrow. You can close this issue if you want
Ok ignore my issue report above. I had a massive brain fart reading the AbnormalsBoatEntity code and it is indeed trying to store the type into the dataManager lol. Sorry about that.
Though when I try to access the type through getBoatType():
if (entity instanceof AbnormalsBoatEntity) {
AbnormalsBoatEntity boat = (AbnormalsBoatEntity)entity;
AbnormalsBoatEntity.Type type = boat.getBoatType();
I get this crash which is odd. Now I'm lost as what the issue could be.
[Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
net.minecraft.crash.ReportedException: Colliding entity with block
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:890) ~[?:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821) ~[?:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662) [?:?] {re:classloading,pl:accesstransformer:B}
at java.lang.Thread.run(Unknown Source) [?:1.8.0_231] {}
Caused by: java.lang.NullPointerException
at net.minecraft.network.datasync.EntityDataManager.get(EntityDataManager.java:118) ~[?:?] {re:classloading}
at net.minecraft.entity.item.BoatEntity.getBoatType(BoatEntity.java:832) ~[?:?] {re:classloading,pl:accesstransformer:B}
at net.telepathicgrunt.bumblezone.blocks.SugarWaterBlock.onEntityCollision(SugarWaterBlock.java:90) ~[?:?] {re:classloading}
at net.minecraft.block.BlockState.onEntityCollision(BlockState.java:282) ~[?:?] {re:classloading}
at net.minecraft.entity.Entity.doBlockCollisions(Entity.java:877) ~[?:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.entity.Entity.move(Entity.java:615) ~[?:?] {re:classloading,pl:accesstransformer:B}
at com.teamabnormals.abnormals_core.common.entity.AbnormalsBoatEntity.tick(AbnormalsBoatEntity.java:208) ~[?:?] {re:classloading}
at net.minecraft.world.server.ServerWorld.updateEntity(ServerWorld.java:615) ~[?:?] {re:classloading}
at net.minecraft.world.World.guardEntityTick(World.java:586) ~[?:?] {re:classloading,pl:accesstransformer:B}
at net.minecraft.world.server.ServerWorld.tick(ServerWorld.java:404) ~[?:?] {re:classloading}
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:886) ~[?:?] {re:classloading,pl:accesstransformer:B}
... 4 more
[Server thread/ERROR] [minecraft/MinecraftServer]: This crash report has been saved to: C:\Users\Admin\Documents\PersonalFun\Minecraft stuff\JavaCodeMods\ModdingWorkspace\Bumblezone\run\.\crash-reports\crash-2020-05-16_22.48.47-server.txt
I think I need to take a break for a while lol.