Skip to content

Commit

Permalink
* Warning in log and GUI if Storage Drawers version differs from the …
Browse files Browse the repository at this point in the history
…one targeted

* Compatibility with Storage Drawers 3.4.4 (fixes #6)
  • Loading branch information
Belgabor committed Nov 14, 2016
1 parent d5fcbb7 commit 86f7fa0
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.33
* [NEW] Warning in log and GUI if Storage Drawers version differs from the one targeted
* [FIXED] Compatibility with Storage Drawers 3.4.4 (Belgabor/DrawersBits#6)

## Version 0.32
* [FIXED] Compatibility with Storage Drawers 3.3.0 (Belgabor/DrawersBits#5)

Expand Down
4 changes: 2 additions & 2 deletions build.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
minecraft_version = 1.10.2
forge_version = 12.18.1.2065
mod_version = 0.32
forge_version = 12.18.2.2122
mod_version = 0.33
release_type = alpha
61 changes: 55 additions & 6 deletions src/main/java/mods/belgabor/bitdrawers/BitDrawers.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@
import mods.belgabor.bitdrawers.core.BlockRegistry;
import mods.belgabor.bitdrawers.core.CommonProxy;
import mods.belgabor.bitdrawers.core.RecipeRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import mods.belgabor.bitdrawers.gui.GuiScreenStartup;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.*;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@Mod(modid = BitDrawers.MODID, version = BitDrawers.VERSION, name = BitDrawers.MODNAME, dependencies = "required-after:chiselsandbits@[11.6,);required-after:StorageDrawers@[1.10.2-3.3.0,);required-after:Chameleon")
@Mod(modid = BitDrawers.MODID, version = BitDrawers.VERSION, name = BitDrawers.MODNAME, dependencies = "required-after:chiselsandbits@[11.6,);required-after:StorageDrawers@[1.10.2-"+BitDrawers.SD_VERSION+",);required-after:Chameleon")
@ChiselsAndBitsAddon
public class BitDrawers implements IChiselsAndBitsAddon
{
public static final String MODNAME = "Drawers & Bits";
public static final String MODID = "bitdrawers";
public static final String VERSION = "0.32";
public static final String VERSION = "0.33";
public static final String SD_VERSION = "3.4.4";
public static final int[] SD_VERSIONS = {3, 4, 4};

@SidedProxy(
clientSide = "mods.belgabor.bitdrawers.client.ClientProxy",
Expand All @@ -41,6 +46,11 @@ public class BitDrawers implements IChiselsAndBitsAddon
public static IChiselAndBitsAPI cnb_api;

public static SimpleNetworkWrapper network;

public static boolean sdVersionCheckFailed = true;
public static boolean sdMajorMismatch = false;
public static boolean sdMinorMismatch = false;
public static String detectedSdVersion = "";

public static BlockRegistry blocks = new BlockRegistry();
public static RecipeRegistry recipes = new RecipeRegistry();
Expand All @@ -53,20 +63,59 @@ public void preInit(FMLPreInitializationEvent event)
network = NetworkRegistry.INSTANCE.newSimpleChannel(MODID);
blocks.init();
proxy.initClient();

MinecraftForge.EVENT_BUS.register(this);

if (FMLCommonHandler.instance().getSide() == Side.CLIENT) {
network.registerMessage(CountUpdateMessage.Handler.class, CountUpdateMessage.class, 1, Side.CLIENT);
}
else {
network.registerMessage(CountUpdateMessage.HandlerStub.class, CountUpdateMessage.class, 1, Side.CLIENT);
}

ModContainer testContainer = Loader.instance().getIndexedModList().get("StorageDrawers");
if (testContainer != null) {
String[] testVersion = testContainer.getDisplayVersion().split("-");
if (testVersion.length == 2) {
String[] testVersionParts = testVersion[1].split("\\.");
detectedSdVersion = testVersion[1];
if (testVersionParts.length == 3) {
sdVersionCheckFailed = false;
try {
if ((Integer.parseInt(testVersionParts[0]) != SD_VERSIONS[0]) || (Integer.parseInt(testVersionParts[1]) != SD_VERSIONS[1])) {
sdMajorMismatch = true;
BDLogger.warn("Your version of Storage Drawers (%s) differs majorly from the one Drawers & Bits was compiled with (%s). Use at your own discretion, in case of issues please open an issue on GitHub and revert the version of Storage Drawers to the one known working until I can fix compatibility.", detectedSdVersion, SD_VERSION);
} else if (Integer.parseInt(testVersionParts[2]) != SD_VERSIONS[2]) {
sdMinorMismatch = true;
BDLogger.warn("Your version of Storage Drawers (%s) differs from the one Drawers & Bits was compiled with (%s). The difference is minor so issues are unlikely, but if one occurs, please open an issue on GitHub and revert the version of Storage Drawers to the one known working until I can fix compatibility.", detectedSdVersion, SD_VERSION);
} else if (config.debugTrace) {
BDLogger.info("Drawers & Bits: Storage Drawers version check OK (%s).", detectedSdVersion);
}
} catch (NumberFormatException e) {
sdVersionCheckFailed = true;
}
}
}
}
if (sdVersionCheckFailed) {
BDLogger.error("Drawers & Bits: Unable to verify StorageDrawers version. This probably isn't going to end well...");
}
}

@EventHandler
public void postInit(FMLPostInitializationEvent event) {
recipes.init();
}

@SubscribeEvent
@SideOnly( Side.CLIENT )
public void openMainMenu(final GuiOpenEvent event ) {
// if the max shades has changed in form the user of the new usage.
if ((!detectedSdVersion.equals(config.lastSDVersionWarned)) && (sdMajorMismatch || sdMinorMismatch || sdVersionCheckFailed)) {
event.setGui(new GuiScreenStartup());
}
}

@Override
public void onReadyChiselsAndBits(IChiselAndBitsAPI api) {
cnb_api = api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ protected void rebuildBitLookup (Map<Integer, List<SlotRecord>> lookup, List<Slo

for (int i = 0; i < records.size(); i++) {
SlotRecord record = records.get(i);
IDrawerGroup group = getGroupForCoord(record.coord);
IDrawerGroup group = getGroupForSlotRecord(record);
if (group == null)
continue;

Expand Down Expand Up @@ -256,7 +256,7 @@ protected void rebuildBitLookup (Map<Integer, List<SlotRecord>> lookup, List<Slo
protected IDrawer getAccessibleBitDrawer(SlotRecord slotRecord, GameProfile profile) {
if (slotRecord == null)
return null;
IDrawerGroup group = this.getGroupForCoord(slotRecord.coord);
IDrawerGroup group = this.getGroupForSlotRecord(slotRecord);
if (!(group instanceof IProtectable) || SecurityManager.hasAccess(profile, (IProtectable) group)) {
return group.getDrawer(slotRecord.slot);
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/mods/belgabor/bitdrawers/config/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mods.belgabor.bitdrawers.config;

import mods.belgabor.bitdrawers.BitDrawers;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

import java.io.File;

Expand All @@ -18,6 +20,9 @@ public class ConfigManager {
public boolean allowChiseledBlockMultiInsertion = false;
public boolean chatty = true;
public boolean enableBitController = true;
public String lastSDVersionWarned = "";

private Property propLastSDVersionWarned;

public ConfigManager(File config) {
this.config = new Configuration(config);
Expand Down Expand Up @@ -48,8 +53,20 @@ public void sync() {
enableBitController = config.get(Configuration.CATEGORY_GENERAL, "enableBitController", enableBitController,
"Enable the bit drawer controller.")
.setLanguageKey(LANG_PREFIX + "prop.enableBitController").getBoolean();

propLastSDVersionWarned = config.get(Configuration.CATEGORY_GENERAL, "lastSDVersionWarned", lastSDVersionWarned,
"Last Storage Drawer version warned about (internal, you should not change this without good reason).")
.setLanguageKey(LANG_PREFIX + "prop.lastSDVersionWarned");

lastSDVersionWarned = propLastSDVersionWarned.getString();

if (config.hasChanged())
config.save();
}

public void updateSDVersion() {
propLastSDVersionWarned.set(BitDrawers.detectedSdVersion);
lastSDVersionWarned = BitDrawers.detectedSdVersion;
config.save();
}
}
4 changes: 4 additions & 0 deletions src/main/java/mods/belgabor/bitdrawers/core/BDLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static void error(String message, Object ... args) {
log(Level.ERROR, message, args);
}

public static void warn(String message, Object ... args) {
log(Level.WARN, message, args);
}

public static void error(Throwable t) {
log(Level.ERROR, t);
}
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/mods/belgabor/bitdrawers/gui/GuiScreenStartup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package mods.belgabor.bitdrawers.gui;

import mods.belgabor.bitdrawers.BitDrawers;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.translation.I18n;
import org.lwjgl.opengl.GL11;

import java.util.List;

/**
* Created by Belgabor on 14.11.2016.
* Adapted from flatcoloredblocks by AlgortihmX2
*/
public class GuiScreenStartup extends GuiScreen
{
String[] lines;

@Override
public void initGui() {
final String msga = I18n.translateToLocal( "flatcoloredblocks.startup_a" );
final String msgb = I18n.translateToLocal( "flatcoloredblocks.startup_b" );
final String msgc = I18n.translateToLocal( "flatcoloredblocks.startup_c" );
final String msgd = I18n.translateToLocal( "flatcoloredblocks.startup_d" );
final String msge = I18n.translateToLocal( "flatcoloredblocks.startup_e" );
final String msgf = I18n.translateToLocal( "flatcoloredblocks.startup_f" );

String msg = I18n.translateToLocal("bitDrawers.startup_a") + "\n\n";
msg += I18n.translateToLocalFormatted("bitDrawers.startup_b", BitDrawers.SD_VERSION, BitDrawers.detectedSdVersion) + "\n";
if (BitDrawers.sdVersionCheckFailed) {
msg += I18n.translateToLocal("bitDrawers.startup_fubar") + "\n\n";
} else if (BitDrawers.sdMajorMismatch) {
msg += I18n.translateToLocal("bitDrawers.startup_maj") + "\n\n";
} else if (BitDrawers.sdMinorMismatch) {
msg += I18n.translateToLocal("bitDrawers.startup_min") + "\n\n";
}
msg += I18n.translateToLocal("bitDrawers.startup_c") + "\n\n";
msg += I18n.translateToLocal("bitDrawers.startup_d") + "\n\n";
msg += I18n.translateToLocal("bitDrawers.startup_e");

lines = msg.split( "\n" );

buttonList.add( new GuiButton( 0, width / 2 - 144 / 2, height / 2 + 96, 144, 20, "Ok" ) );
}

@Override
public void drawScreen(final int mouseX, final int mouseY, final float partialTicks ) {
GL11.glEnable( GL11.GL_TEXTURE_2D );
drawDefaultBackground();

int heightLoc = 90;
drawCenteredString( fontRendererObj, TextFormatting.YELLOW + "Drawers & Bits", width / 2, height / 2 - 110, 0xFFFFFF );

for ( final String s : lines )
{
final List<String> info = fontRendererObj.listFormattedStringToWidth( s, width - 40 );
for ( final String infoCut : info )
{
drawCenteredString( fontRendererObj, infoCut, width / 2, height / 2 - heightLoc, 0xFFFFFF );
heightLoc = heightLoc - 12;
}
}

super.drawScreen( mouseX, mouseY, partialTicks );
}

@Override
public void actionPerformed(final GuiButton button ) {
switch (button.id) {
case 0: {
for (final GuiButton b : buttonList) {
b.enabled = false;
}

if (!BitDrawers.detectedSdVersion.equals(""))
BitDrawers.config.updateSDVersion();

mc.displayGuiScreen( null );

break;
}
}
}

@Override
public boolean doesGuiPauseGame()
{
return false;
}
}
10 changes: 10 additions & 0 deletions src/main/resources/assets/bitdrawers/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@ bitDrawers.config.prop.enableDebugLogging.tooltip=Prints extra information to th
bitDrawers.config.prop.bitdrawerBaseStorage=Bit Drawer Base Storage
bitDrawers.config.prop.bitdrawerBaseStorage.tooltip=Base storage of a bit drawer (stacks).
chat.notEnough=Not enough bits available: %s
bitDrawers.startup_a=Due to it's internal workings, Drawers & Bits highly depends on the version of Storage Drawers.
bitDrawers.startup_b=This version was developed for version %s, you have installed version %s.
bitDrawers.startup_min=That's a minor difference, so it is unlikely to cause an issue.
bitDrawers.startup_maj=The numbers indicate a possibly breaking change, so crashes may occur.
bitDrawers.startup_fubar=The version check failed, so things will probably fall apart.
bitDrawers.startup_c=In any case it is highly recommended to make a backup before loading any world.
bitDrawers.startup_d=If any problem occurs, please open an issue on the GitHub issue tracker (linked on the Curse project page).
bitDrawers.startup_e=Note: This warning will not show up again until the version of Storage Drawers changes.


0 comments on commit 86f7fa0

Please sign in to comment.