Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address compatibility issues with JED dimensions #24

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions src/main/java/jackyy/dimensionaledibles/block/BlockCustomCake.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
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.common.*;
import net.minecraftforge.fml.relauncher.*;
import org.apache.logging.log4j.message.*;

import javax.annotation.*;

import static jackyy.dimensionaledibles.DimensionalEdibles.*;
import static jackyy.dimensionaledibles.DimensionalEdibles.logger;
import static net.minecraftforge.common.DimensionManager.isDimensionRegistered;

public class BlockCustomCake extends BlockCakeBase implements ITileEntityProvider {

Expand Down Expand Up @@ -62,11 +63,15 @@ 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)) {
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;
}

Expand Down Expand Up @@ -143,7 +148,6 @@ public static void rebuildCache() {
}

@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(CreativeTabs tab,
NonNullList<ItemStack> list) {
if (registerItem()) {
Expand All @@ -156,19 +160,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);
}
Expand Down