From 9b79acaad6d364599a0a5c6160d3f83c7bbf042a Mon Sep 17 00:00:00 2001 From: WayofTime Date: Sat, 21 Nov 2020 10:24:35 -0500 Subject: [PATCH] Fixed the Lava Crystal crash Maybe not the most elegant method? But it works. --- .../java/wayoftime/bloodmagic/BloodMagic.java | 6 +--- .../bloodmagic/client/ClientEvents.java | 5 ++++ .../common/item/ItemLavaCrystal.java | 28 +++++++++++-------- .../bloodmagic/util/helper/NetworkHelper.java | 5 +++- .../bloodmagic/util/helper/PlayerHelper.java | 15 ++++------ 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/main/java/wayoftime/bloodmagic/BloodMagic.java b/src/main/java/wayoftime/bloodmagic/BloodMagic.java index fc5e0dad..42eab61d 100644 --- a/src/main/java/wayoftime/bloodmagic/BloodMagic.java +++ b/src/main/java/wayoftime/bloodmagic/BloodMagic.java @@ -6,8 +6,6 @@ import org.apache.logging.log4j.Logger; import com.google.gson.Gson; import net.minecraft.block.Block; -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.data.DataGenerator; import net.minecraft.fluid.Fluid; import net.minecraft.item.ItemGroup; @@ -37,7 +35,6 @@ import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import wayoftime.bloodmagic.client.ClientEvents; import wayoftime.bloodmagic.client.hud.Elements; -import wayoftime.bloodmagic.client.model.MimicColor; import wayoftime.bloodmagic.client.model.MimicModelLoader; import wayoftime.bloodmagic.common.block.BloodMagicBlocks; import wayoftime.bloodmagic.common.data.GeneratorBaseRecipes; @@ -225,6 +222,7 @@ public class BloodMagic packetHandler.initialize(); } +// @OnlyIn(Dist.CLIENT) private void doClientStuff(final FMLClientSetupEvent event) { // do something that can only be done on the client @@ -232,8 +230,6 @@ public class BloodMagic ClientEvents.initClientEvents(event); Elements.registerElements(); - Minecraft.getInstance().getBlockColors().register(new MimicColor(), BloodMagicBlocks.MIMIC.get()); - RenderTypeLookup.setRenderLayer(BloodMagicBlocks.MIMIC.get(), (RenderType) -> true); } private void enqueueIMC(final InterModEnqueueEvent event) diff --git a/src/main/java/wayoftime/bloodmagic/client/ClientEvents.java b/src/main/java/wayoftime/bloodmagic/client/ClientEvents.java index 8e6e8fd4..6795ceed 100644 --- a/src/main/java/wayoftime/bloodmagic/client/ClientEvents.java +++ b/src/main/java/wayoftime/bloodmagic/client/ClientEvents.java @@ -1,5 +1,6 @@ package wayoftime.bloodmagic.client; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScreenManager; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.RenderTypeLookup; @@ -19,6 +20,7 @@ import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import wayoftime.bloodmagic.BloodMagic; import wayoftime.bloodmagic.api.item.IMultiWillTool; +import wayoftime.bloodmagic.client.model.MimicColor; import wayoftime.bloodmagic.client.render.block.RenderAlchemyArray; import wayoftime.bloodmagic.client.render.block.RenderAltar; import wayoftime.bloodmagic.client.render.block.RenderDemonCrucible; @@ -91,6 +93,9 @@ public class ClientEvents return ((ItemSentientSword) stack.getItem()).getActivated(stack) ? 1 : 0; } }); + + Minecraft.getInstance().getBlockColors().register(new MimicColor(), BloodMagicBlocks.MIMIC.get()); + RenderTypeLookup.setRenderLayer(BloodMagicBlocks.MIMIC.get(), (RenderType) -> true); }); } diff --git a/src/main/java/wayoftime/bloodmagic/common/item/ItemLavaCrystal.java b/src/main/java/wayoftime/bloodmagic/common/item/ItemLavaCrystal.java index 8f1ce086..97ca5a4f 100644 --- a/src/main/java/wayoftime/bloodmagic/common/item/ItemLavaCrystal.java +++ b/src/main/java/wayoftime/bloodmagic/common/item/ItemLavaCrystal.java @@ -14,6 +14,7 @@ import net.minecraft.util.Hand; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvents; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.common.thread.EffectiveSide; import wayoftime.bloodmagic.core.data.Binding; import wayoftime.bloodmagic.core.data.SoulTicket; import wayoftime.bloodmagic.util.helper.NetworkHelper; @@ -52,14 +53,21 @@ public class ItemLavaCrystal extends ItemBindableBase if (binding == null) return -1; -// if (NetworkHelper.syphonFromContainer(stack, SoulTicket.item(stack, 25))) - if (NetworkHelper.canSyphonFromContainer(stack, 50)) - return 200; - else + if (EffectiveSide.get().isServer()) { - PlayerEntity player = PlayerHelper.getPlayerFromUUID(binding.getOwnerId()); - if (player != null) - player.addPotionEffect(new EffectInstance(Effects.NAUSEA, 99)); + if (NetworkHelper.canSyphonFromContainer(stack, 50)) + return 200; + else + { + PlayerEntity player = PlayerHelper.getPlayerFromUUID(binding.getOwnerId()); + if (player != null) + { + player.addPotionEffect(new EffectInstance(Effects.NAUSEA, 99)); + } + } + } else + { + return 200; } return -1; @@ -100,11 +108,9 @@ public class ItemLavaCrystal extends ItemBindableBase if (!player.canPlayerEdit(pos, facing, itemstack)) return ActionResultType.FAIL; - if (context.getWorld().isAirBlock(pos) - && NetworkHelper.getSoulNetwork(binding).syphonAndDamage(player, SoulTicket.item(player.getHeldItem(hand), 100)).isSuccess()) + if (context.getWorld().isAirBlock(pos) && NetworkHelper.getSoulNetwork(binding).syphonAndDamage(player, SoulTicket.item(player.getHeldItem(hand), 100)).isSuccess()) { - context.getWorld().playSound(player, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, random.nextFloat() - * 0.4F + 0.8F); + context.getWorld().playSound(player, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, random.nextFloat() * 0.4F + 0.8F); context.getWorld().setBlockState(pos, Blocks.FIRE.getDefaultState(), 11); } else return ActionResultType.FAIL; diff --git a/src/main/java/wayoftime/bloodmagic/util/helper/NetworkHelper.java b/src/main/java/wayoftime/bloodmagic/util/helper/NetworkHelper.java index cde1398f..debf1d4f 100644 --- a/src/main/java/wayoftime/bloodmagic/util/helper/NetworkHelper.java +++ b/src/main/java/wayoftime/bloodmagic/util/helper/NetworkHelper.java @@ -9,13 +9,13 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.storage.DimensionSavedDataManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.server.ServerLifecycleHooks; +import wayoftime.bloodmagic.api.item.IBindable; import wayoftime.bloodmagic.core.data.BMWorldSavedData; import wayoftime.bloodmagic.core.data.Binding; import wayoftime.bloodmagic.core.data.SoulNetwork; import wayoftime.bloodmagic.core.data.SoulTicket; import wayoftime.bloodmagic.core.registry.OrbRegistry; import wayoftime.bloodmagic.event.SoulNetworkEvent; -import wayoftime.bloodmagic.api.item.IBindable; import wayoftime.bloodmagic.orb.BloodOrb; import wayoftime.bloodmagic.orb.IBloodOrb; @@ -161,6 +161,9 @@ public class NetworkHelper return false; SoulNetwork network = getSoulNetwork(binding); + if (network == null) + return false; + return network.getCurrentEssence() >= toSyphon; } diff --git a/src/main/java/wayoftime/bloodmagic/util/helper/PlayerHelper.java b/src/main/java/wayoftime/bloodmagic/util/helper/PlayerHelper.java index 715b0f3a..7150adc2 100644 --- a/src/main/java/wayoftime/bloodmagic/util/helper/PlayerHelper.java +++ b/src/main/java/wayoftime/bloodmagic/util/helper/PlayerHelper.java @@ -22,13 +22,11 @@ public class PlayerHelper public static PlayerEntity getPlayerFromId(UUID uuid) { // TODO: Need to find a reliable way to get whether the side is Client or Server -// if (FMLCommonHandler.instance().) -// return null; -// -// World w; -// Dist d; -// -// if(ServerLifecycleHooks.getCurrentServer().get) + + if (ServerLifecycleHooks.getCurrentServer() == null) + { + return null; + } return ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayerByUUID(uuid); @@ -58,7 +56,6 @@ public class PlayerHelper */ public static boolean isFakePlayer(PlayerEntity player) { - return player instanceof FakePlayer - || (player != null && knownFakePlayers.contains(player.getClass().getCanonicalName())); + return player instanceof FakePlayer || (player != null && knownFakePlayers.contains(player.getClass().getCanonicalName())); } } \ No newline at end of file