TheLimePixel / GregBlock

5 stars 0 forks source link

NPE when invoking FindMe within range of a Steam Pump #79

Open bzy-xyz opened 6 years ago

bzy-xyz commented 6 years ago

When invoking FindMe within search range of a Steam Pump a NullPointerException is thrown. Additionally, no particle effects are produced.

[16:45:41] [Server thread/FATAL] [minecraft/MinecraftServer]: Error executing task
java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_181]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_181]
    at net.minecraft.util.Util.func_181617_a(SourceFile:47) [h.class:?]
    at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:723) [MinecraftServer.class:?]
    at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:668) [MinecraftServer.class:?]
    at net.minecraft.server.integrated.IntegratedServer.func_71217_p(IntegratedServer.java:185) [chd.class:?]
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526) [MinecraftServer.class:?]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
Caused by: java.lang.NullPointerException
    at com.buuz135.findme.network.PositionRequestMessage$Handler.lambda$onMessage$0(PositionRequestMessage.java:74) ~[PositionRequestMessage$Handler.class:?]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_181]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_181]
    at net.minecraft.util.Util.func_181617_a(SourceFile:46) ~[h.class:?]
    ... 5 more
bzy-xyz commented 5 years ago

Ok, so I don't understand why the GregBlockUtils SteamPump implements hasCapability and getCapability in such a way that hasCapability can return true but getCapability returns null.

https://github.com/EmosewaPixel/GregBlockUtilities/blob/1ff712391c580ecf9266f14cc94b1a1eab67eeed/src/main/java/gregblockutils/Machines/SteamPump.java#L136-L144

    @Override
    public boolean hasCapability(Capability<?> capability, EnumFacing side) {
        return (side == null || side.getAxis() != EnumFacing.Axis.Y) && super.hasCapability(capability, side);
    }

    @Override
    public <T> T getCapability(Capability<T> capability, EnumFacing side) {
        return (side == null || side.getAxis() == EnumFacing.Axis.Y) ? null : super.getCapability(capability, side);
    }

Consider what happens when something requests the ITEM_HANDLER_CAPABILITY for side null, as FindMe does. Since the SteamPump has an "inventory" of size 2, GregTechCE's MetaTileEntity happily reports that the SteamPump has the capability, but the SteamPump's getCapability will return null on account of the requested side being null.

This seems like the source of the behaviour I'm observing.