diff --git a/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityEMCLink.java b/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityEMCLink.java index 736d5311..c4622c63 100644 --- a/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityEMCLink.java +++ b/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityEMCLink.java @@ -101,7 +101,12 @@ public void tickServer(Level level, BlockPos pos, BlockState state, BlockEntityE resetLimits(); if (emc.equals(BigInteger.ZERO)) return; ServerPlayer player = Util.getPlayer(level, owner); - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return; + } provider.setEmc(provider.getEmc().add(emc)); if (player != null) provider.syncEmc(player); @@ -183,7 +188,12 @@ public int getSlots() { @Override public ItemStack getStackInSlot(int slot) { if (slot != 0 || itemStack.isEmpty()) return ItemStack.EMPTY; - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return ItemStack.EMPTY; + } BigInteger maxCount = provider.getEmc().divide(BigInteger.valueOf(ProjectEAPI.getEMCProxy().getValue(itemStack))).min(BigInteger.valueOf(Integer.MAX_VALUE)); int count = maxCount.intValueExact(); if (count <= 0) return ItemStack.EMPTY; @@ -207,7 +217,12 @@ public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate int insertCount = Math.min(count, remainingImport); if (!simulate) { long itemValue = ProjectEAPI.getEMCProxy().getSellValue(stack); - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return stack; + } BigInteger totalValue = BigInteger.valueOf(itemValue).multiply(BigInteger.valueOf(insertCount)); provider.setEmc(provider.getEmc().add(totalValue)); ServerPlayer player = Util.getPlayer(owner); @@ -236,7 +251,12 @@ public ItemStack extractItemInternal(int slot, int amount, boolean simulate, boo if (slot != 0 || remainingExport <= 0 || owner == null || itemStack.isEmpty() || Util.getPlayer(owner) == null) return ItemStack.EMPTY; BigInteger itemValue = BigInteger.valueOf(ProjectEAPI.getEMCProxy().getValue(itemStack)); - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return ItemStack.EMPTY; + } BigInteger maxCount = provider.getEmc().divide(itemValue).min(BigInteger.valueOf(Integer.MAX_VALUE)); int extractCount = Math.min(amount, limit ? Math.min(maxCount.intValueExact(), remainingExport) : maxCount.intValueExact()); if (extractCount <= 0) return ItemStack.EMPTY; @@ -334,7 +354,12 @@ public FluidStack drain(int maxDrain, FluidAction action) { if(fluid == null || Util.getPlayer(owner) == null) return FluidStack.EMPTY; if(maxDrain > remainingFluid) maxDrain = remainingFluid; long cost = getFluidCost(maxDrain); - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return FluidStack.EMPTY; + } BigInteger emc = provider.getEmc(); BigDecimal dEMC = new BigDecimal(emc); if(dEMC.compareTo(BigDecimal.valueOf(getFluidCostPer())) < 0) return FluidStack.EMPTY; diff --git a/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityTransmutationInterface.java b/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityTransmutationInterface.java index ea4f7855..658ef0b2 100644 --- a/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityTransmutationInterface.java +++ b/src/main/java/cool/furry/mc/forge/projectexpansion/block/entity/BlockEntityTransmutationInterface.java @@ -63,7 +63,12 @@ private ItemInfo[] fetchKnowledge() { } private int getMaxCount(int slot) { - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return 0; + } BigInteger playerEmc = provider.getEmc(); if (playerEmc.compareTo(BigInteger.ZERO) < 1) return 0; BigInteger targetItemEmc = BigInteger.valueOf(ProjectEAPI.getEMCProxy().getValue(fetchKnowledge()[slot])); @@ -115,7 +120,12 @@ public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate if (simulate) return ItemStack.EMPTY; long emcValue = ProjectEAPI.getEMCProxy().getSellValue(stack); - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return ItemStack.EMPTY; + } BigInteger totalEmcValue = BigInteger.valueOf(emcValue).multiply(BigInteger.valueOf(count)); provider.setEmc(provider.getEmc().add(totalEmcValue)); @@ -143,7 +153,12 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) { if (simulate) return item; long emcValue = ProjectEAPI.getEMCProxy().getValue(info[slot - 1]); BigInteger totalEmcCost = BigInteger.valueOf(emcValue).multiply(BigInteger.valueOf(amount)); - IKnowledgeProvider provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + IKnowledgeProvider provider; + try { + provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(owner); + } catch (NullPointerException ignore) { + return ItemStack.EMPTY; + } provider.setEmc(provider.getEmc().subtract(totalEmcCost)); ServerPlayer player = Util.getPlayer(level, owner); if (player != null) provider.syncEmc(player); diff --git a/src/main/java/cool/furry/mc/forge/projectexpansion/util/PowerFlowerCollector.java b/src/main/java/cool/furry/mc/forge/projectexpansion/util/PowerFlowerCollector.java index f206be89..45ad9cbc 100644 --- a/src/main/java/cool/furry/mc/forge/projectexpansion/util/PowerFlowerCollector.java +++ b/src/main/java/cool/furry/mc/forge/projectexpansion/util/PowerFlowerCollector.java @@ -32,7 +32,9 @@ public static void onTick(TickEvent.ServerTickEvent event) { IKnowledgeProvider provider; try { provider = ProjectEAPI.getTransmutationProxy().getKnowledgeProviderFor(uuid); - } catch(NullPointerException ignore) { continue; } + } catch(NullPointerException ignore) { + continue; + } provider.setEmc(provider.getEmc().add(amount)); provider.syncEmc(player); toRemove.add(uuid);