From 61cb4ac8b7f9c474ede191a20eca2e61c9b5f2b2 Mon Sep 17 00:00:00 2001 From: Exa <11907282+Exaxxion@users.noreply.github.com> Date: Fri, 9 Apr 2021 19:25:13 -0700 Subject: [PATCH 1/4] Address JED compatibility issues with late dimension loading - Always register custom cakes even if the dimension doesn't exist during Forge mod initialization phase - Prevent the player from eating a placed custom cake if the target dimension does not exist, and log an error when this occurs --- .../block/BlockCustomCake.java | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java index b588474..f35cc3f 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java @@ -15,12 +15,12 @@ import net.minecraft.util.*; import net.minecraft.util.math.*; import net.minecraft.world.*; -import net.minecraftforge.common.*; import net.minecraftforge.fml.relauncher.*; import javax.annotation.*; import static jackyy.dimensionaledibles.DimensionalEdibles.*; +import static net.minecraftforge.common.DimensionManager.isDimensionRegistered; public class BlockCustomCake extends BlockCakeBase implements ITileEntityProvider { @@ -62,11 +62,9 @@ public boolean onBlockActivated(World world, float hitY, float hitZ) { - - int dim = getDimension(world, pos); - if(!cache.containsKey(dim)) { - logger.error("No such dimension: \"{}\"", dim); + if(!isDimensionRegistered(dim)) { + logger.error("Requested dimension: \"{}\" does not exist. Please verify your configs.", dim); return true; } @@ -156,19 +154,18 @@ public void getSubBlocks(CreativeTabs tab, continue; } int dimension = Integer.parseInt(parts[0].trim()); - if (DimensionManager.isDimensionRegistered(dimension)) { - stack = new ItemStack(this); - NBTTagCompound nbt = stack.getTagCompound(); - if (nbt == null) { - nbt = new NBTTagCompound(); - stack.setTagCompound(nbt); - } - nbt.setInteger("dimID", dimension); - nbt.setString("cakeName", parts[1].trim()); - list.add(stack); - } else { - logger.error("\"{}\" is not a valid dimension ID!", parts[0]); + + // Always register the requested cakes; JED dimensions may not be loaded yet + stack = new ItemStack(this); + NBTTagCompound nbt = stack.getTagCompound(); + if (nbt == null) { + nbt = new NBTTagCompound(); + stack.setTagCompound(nbt); } + nbt.setInteger("dimID", dimension); + nbt.setString("cakeName", parts[1].trim()); + list.add(stack); + } catch(NumberFormatException e) { logger.error("\"{}\" is not a valid line input! The dimension ID needs to be a number!", s, e); } From f21e19a3af8f43c6fe5c09c81e3e2fc9298baf27 Mon Sep 17 00:00:00 2001 From: Exa <11907282+Exaxxion@users.noreply.github.com> Date: Sat, 10 Apr 2021 14:45:56 -0700 Subject: [PATCH 2/4] Send client thread a chat message instead of a log message --- .../dimensionaledibles/block/BlockCustomCake.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java index f35cc3f..a076c51 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java @@ -14,13 +14,15 @@ import net.minecraft.tileentity.*; import net.minecraft.util.*; import net.minecraft.util.math.*; +import net.minecraft.util.text.*; import net.minecraft.world.*; import net.minecraftforge.fml.relauncher.*; +import org.apache.logging.log4j.message.*; import javax.annotation.*; import static jackyy.dimensionaledibles.DimensionalEdibles.*; -import static net.minecraftforge.common.DimensionManager.isDimensionRegistered; +import static net.minecraftforge.common.DimensionManager.*; public class BlockCustomCake extends BlockCakeBase implements ITileEntityProvider { @@ -63,8 +65,14 @@ public boolean onBlockActivated(World world, float hitZ) { int dim = getDimension(world, pos); - if(!isDimensionRegistered(dim)) { - logger.error("Requested dimension: \"{}\" does not exist. Please verify your configs.", dim); + if (!isDimensionRegistered(dim)) { + Message message = new FormattedMessage( + "Requested dimension: \"{}\" does not exist. Please verify your configs.", + dim); + if (!world.isRemote) + logger.error(message); + else + player.sendMessage(new TextComponentString(message.getFormattedMessage())); return true; } From 23d39526a59500f0de826626c42f8c566323dab2 Mon Sep 17 00:00:00 2001 From: Exa <11907282+Exaxxion@users.noreply.github.com> Date: Sat, 10 Apr 2021 14:51:14 -0700 Subject: [PATCH 3/4] Revert inadvertent wildcard static imports --- .../java/jackyy/dimensionaledibles/block/BlockCustomCake.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java index a076c51..1c4fb16 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java @@ -21,8 +21,8 @@ import javax.annotation.*; -import static jackyy.dimensionaledibles.DimensionalEdibles.*; -import static net.minecraftforge.common.DimensionManager.*; +import static jackyy.dimensionaledibles.DimensionalEdibles.logger; +import static net.minecraftforge.common.DimensionManager.isDimensionRegistered; public class BlockCustomCake extends BlockCakeBase implements ITileEntityProvider { From 2c5d56b5706985af8b204739e7aff60fcf3be2d4 Mon Sep 17 00:00:00 2001 From: Exa <11907282+Exaxxion@users.noreply.github.com> Date: Sat, 10 Apr 2021 15:43:52 -0700 Subject: [PATCH 4/4] Remove sidedness from getSubBlocks command to fix NPE --- .../java/jackyy/dimensionaledibles/block/BlockCustomCake.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java index 1c4fb16..3a2f182 100644 --- a/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java +++ b/src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java @@ -16,7 +16,6 @@ import net.minecraft.util.math.*; import net.minecraft.util.text.*; import net.minecraft.world.*; -import net.minecraftforge.fml.relauncher.*; import org.apache.logging.log4j.message.*; import javax.annotation.*; @@ -149,7 +148,6 @@ public static void rebuildCache() { } @Override - @SideOnly(Side.CLIENT) public void getSubBlocks(CreativeTabs tab, NonNullList list) { if (registerItem()) {