Make creative tab configuration more resilient to disabled items/blocks; fix #4640
This commit is contained in:
parent
f7ea40193c
commit
2ba3baf43e
8 changed files with 68 additions and 24 deletions
|
@ -278,8 +278,6 @@ public class BuildCraftCore extends BuildCraftMod {
|
||||||
BCLog.logger.info("Copyright (c) the BuildCraft team, 2011-2017");
|
BCLog.logger.info("Copyright (c) the BuildCraft team, 2011-2017");
|
||||||
BCLog.logger.info("http://www.mod-buildcraft.com");
|
BCLog.logger.info("http://www.mod-buildcraft.com");
|
||||||
|
|
||||||
new BCCreativeTab("main");
|
|
||||||
|
|
||||||
commandBuildcraft.addAlias("bc");
|
commandBuildcraft.addAlias("bc");
|
||||||
commandBuildcraft.addChildCommand(new SubCommandVersion());
|
commandBuildcraft.addChildCommand(new SubCommandVersion());
|
||||||
commandBuildcraft.addChildCommand(new SubCommandChangelog());
|
commandBuildcraft.addChildCommand(new SubCommandChangelog());
|
||||||
|
@ -445,7 +443,9 @@ public class BuildCraftCore extends BuildCraftMod {
|
||||||
loadRecipes();
|
loadRecipes();
|
||||||
}
|
}
|
||||||
|
|
||||||
BCCreativeTab.get("main").setIcon(new ItemStack(BuildCraftCore.wrenchItem, 1));
|
if (BCCreativeTab.isPresent("main")) {
|
||||||
|
BCCreativeTab.get("main").setIcon(new ItemStack(BuildCraftCore.wrenchItem, 1));
|
||||||
|
}
|
||||||
|
|
||||||
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcLaser");
|
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcLaser");
|
||||||
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcEnergyLaser");
|
EntityList.stringToClassMapping.remove("BuildCraft|Core.bcEnergyLaser");
|
||||||
|
|
|
@ -191,8 +191,6 @@ public class BuildCraftRobotics extends BuildCraftMod {
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent evt) {
|
public void preInit(FMLPreInitializationEvent evt) {
|
||||||
new BCCreativeTab("boards");
|
|
||||||
|
|
||||||
BuildCraftCore.mainConfigManager.register("general", "boards.blacklist", new String[]{}, "Blacklisted robots boards", ConfigManager.RestartRequirement.GAME);
|
BuildCraftCore.mainConfigManager.register("general", "boards.blacklist", new String[]{}, "Blacklisted robots boards", ConfigManager.RestartRequirement.GAME);
|
||||||
|
|
||||||
reloadConfig(ConfigManager.RestartRequirement.GAME);
|
reloadConfig(ConfigManager.RestartRequirement.GAME);
|
||||||
|
@ -265,7 +263,9 @@ public class BuildCraftRobotics extends BuildCraftMod {
|
||||||
loadRecipes();
|
loadRecipes();
|
||||||
}
|
}
|
||||||
|
|
||||||
BCCreativeTab.get("boards").setIcon(new ItemStack(BuildCraftRobotics.redstoneBoard, 1));
|
if (BCCreativeTab.isPresent("boards")) {
|
||||||
|
BCCreativeTab.get("boards").setIcon(new ItemStack(BuildCraftRobotics.redstoneBoard, 1));
|
||||||
|
}
|
||||||
|
|
||||||
BuilderAPI.schematicRegistry.registerSchematicBlock(requesterBlock, SchematicTile.class);
|
BuilderAPI.schematicRegistry.registerSchematicBlock(requesterBlock, SchematicTile.class);
|
||||||
|
|
||||||
|
|
|
@ -292,11 +292,6 @@ public class BuildCraftTransport extends BuildCraftMod {
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent evt) {
|
public void preInit(FMLPreInitializationEvent evt) {
|
||||||
new BCCreativeTab("pipes");
|
|
||||||
if (Loader.isModLoaded("BuildCraft|Silicon")) {
|
|
||||||
new BCCreativeTab("gates");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
BuildCraftCore.mainConfigManager.register("experimental.kinesisPowerLossOnTravel", false, "Should kinesis pipes lose power over distance (think IC2 or BC pre-3.7)?", ConfigManager.RestartRequirement.WORLD);
|
BuildCraftCore.mainConfigManager.register("experimental.kinesisPowerLossOnTravel", false, "Should kinesis pipes lose power over distance (think IC2 or BC pre-3.7)?", ConfigManager.RestartRequirement.WORLD);
|
||||||
|
|
||||||
|
@ -387,6 +382,9 @@ public class BuildCraftTransport extends BuildCraftMod {
|
||||||
|
|
||||||
pipeGate = new ItemGate();
|
pipeGate = new ItemGate();
|
||||||
pipeGate.setUnlocalizedName("pipeGate");
|
pipeGate.setUnlocalizedName("pipeGate");
|
||||||
|
if (Loader.isModLoaded("BuildCraft|Silicon") && BCRegistry.INSTANCE.isItemEnabled(pipeGate)) {
|
||||||
|
new BCCreativeTab("gates");
|
||||||
|
}
|
||||||
BCRegistry.INSTANCE.registerItem(pipeGate, false);
|
BCRegistry.INSTANCE.registerItem(pipeGate, false);
|
||||||
|
|
||||||
facadeItem = new ItemFacade();
|
facadeItem = new ItemFacade();
|
||||||
|
@ -492,11 +490,13 @@ public class BuildCraftTransport extends BuildCraftMod {
|
||||||
|
|
||||||
PipeEventBus.registerGlobalHandler(new LensFilterHandler());
|
PipeEventBus.registerGlobalHandler(new LensFilterHandler());
|
||||||
|
|
||||||
BCCreativeTab.get("pipes").setIcon(new ItemStack(BuildCraftTransport.pipeItemsDiamond, 1));
|
if (BCCreativeTab.isPresent("pipes")) {
|
||||||
if (showAllFacadesCreative) {
|
BCCreativeTab.get("pipes").setIcon(new ItemStack(BuildCraftTransport.pipeItemsDiamond, 1));
|
||||||
|
}
|
||||||
|
if (BCCreativeTab.isPresent("facades")) {
|
||||||
BCCreativeTab.get("facades").setIcon(facadeItem.getFacadeForBlock(Blocks.brick_block, 0));
|
BCCreativeTab.get("facades").setIcon(facadeItem.getFacadeForBlock(Blocks.brick_block, 0));
|
||||||
}
|
}
|
||||||
if (Loader.isModLoaded("BuildCraft|Silicon")) {
|
if (BCCreativeTab.isPresent("gates")) {
|
||||||
BCCreativeTab.get("gates").setIcon(ItemGate.makeGateItem(GateMaterial.DIAMOND, GateLogic.AND));
|
BCCreativeTab.get("gates").setIcon(ItemGate.makeGateItem(GateMaterial.DIAMOND, GateLogic.AND));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ package buildcraft.core;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import buildcraft.BuildCraftCore;
|
||||||
|
import buildcraft.core.lib.utils.Utils;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
|
@ -27,17 +29,39 @@ public class BCCreativeTab extends CreativeTabs {
|
||||||
tabs.put(name, this);
|
tabs.put(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isPresent(String name) {
|
||||||
|
return tabs.containsKey(name);
|
||||||
|
}
|
||||||
|
|
||||||
public static BCCreativeTab get(String name) {
|
public static BCCreativeTab get(String name) {
|
||||||
|
BCCreativeTab tab = tabs.get(name);
|
||||||
|
if (tab == null) {
|
||||||
|
tab = new BCCreativeTab(name);
|
||||||
|
tabs.put(name, tab);
|
||||||
|
}
|
||||||
|
return tab;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BCCreativeTab getIfPresent(String name) {
|
||||||
return tabs.get(name);
|
return tabs.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(ItemStack icon) {
|
public void setIcon(ItemStack icon) {
|
||||||
|
if (!Utils.isRegistered(icon)) {
|
||||||
|
// TODO: This could pick the first matching item for a given inventory,
|
||||||
|
// but it's a very niche use case.
|
||||||
|
icon = new ItemStack(BuildCraftCore.wrenchItem, 1);
|
||||||
|
if (!Utils.isRegistered(icon)) {
|
||||||
|
icon = new ItemStack(Blocks.brick_block, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemStack getItem() {
|
private ItemStack getItem() {
|
||||||
if (icon == null || icon.getItem() == null) {
|
if (icon == null) {
|
||||||
return new ItemStack(Blocks.brick_block, 1);
|
// Set default icon.
|
||||||
|
setIcon(null);
|
||||||
}
|
}
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,18 +32,36 @@ public final class BCRegistry {
|
||||||
return registerBlock(block, ItemBlockBuildCraft.class, forced);
|
return registerBlock(block, ItemBlockBuildCraft.class, forced);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isBlockEnabled(String name) {
|
||||||
|
return regCfg.get("blocks", name, true).getBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBlockEnabled(Block block) {
|
||||||
|
String name = block.getUnlocalizedName().replace("tile.", "");
|
||||||
|
return isBlockEnabled(name);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean registerBlock(Block block, Class<? extends ItemBlock> item, boolean forced) {
|
public boolean registerBlock(Block block, Class<? extends ItemBlock> item, boolean forced) {
|
||||||
String name = block.getUnlocalizedName().replace("tile.", "");
|
String name = block.getUnlocalizedName().replace("tile.", "");
|
||||||
if (forced || regCfg.get("blocks", name, true).getBoolean()) {
|
if (forced || isBlockEnabled(name)) {
|
||||||
GameRegistry.registerBlock(block, item, name);
|
GameRegistry.registerBlock(block, item, name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isItemEnabled(String name) {
|
||||||
|
return regCfg.get("items", name, true).getBoolean();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isItemEnabled(Item item) {
|
||||||
|
String name = item.getUnlocalizedName().replace("item.", "");
|
||||||
|
return isItemEnabled(name);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean registerItem(Item item, boolean forced) {
|
public boolean registerItem(Item item, boolean forced) {
|
||||||
String name = item.getUnlocalizedName().replace("item.", "");
|
String name = item.getUnlocalizedName().replace("item.", "");
|
||||||
if (forced || regCfg.get("items", name, true).getBoolean()) {
|
if (forced || isItemEnabled(name)) {
|
||||||
GameRegistry.registerItem(item, name);
|
GameRegistry.registerItem(item, name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,10 +84,12 @@ public final class Utils {
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Block block = Block.getBlockFromItem(stack.getItem());
|
if (stack.getItem() != null) {
|
||||||
if (block instanceof BlockEngineBase) {
|
Block block = Block.getBlockFromItem(stack.getItem());
|
||||||
return isRegistered(block) && ((BlockEngineBase) block).hasEngine(stack.getItemDamage());
|
if (block instanceof BlockEngineBase) {
|
||||||
}
|
return isRegistered(block) && ((BlockEngineBase) block).hasEngine(stack.getItemDamage());
|
||||||
|
}
|
||||||
|
}
|
||||||
return isRegistered(stack.getItem());
|
return isRegistered(stack.getItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,7 +154,7 @@ public class ItemFacade extends ItemBuildCraft implements IFacadeItem, IPipePlug
|
||||||
private static int RANDOM_FACADE_ID = -1;
|
private static int RANDOM_FACADE_ID = -1;
|
||||||
|
|
||||||
public ItemFacade() {
|
public ItemFacade() {
|
||||||
super(BuildCraftTransport.showAllFacadesCreative ? BCCreativeTab.get("facades") : BCCreativeTab.get("main"));
|
super(BCCreativeTab.isPresent("facades") ? BCCreativeTab.get("facades") : BCCreativeTab.get("main"));
|
||||||
|
|
||||||
setHasSubtypes(true);
|
setHasSubtypes(true);
|
||||||
setMaxDamage(0);
|
setMaxDamage(0);
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class ItemGate extends ItemBuildCraft implements IPipePluggableItem {
|
||||||
setHasSubtypes(false);
|
setHasSubtypes(false);
|
||||||
setMaxDamage(0);
|
setMaxDamage(0);
|
||||||
setPassSneakClick(true);
|
setPassSneakClick(true);
|
||||||
setCreativeTab(BCCreativeTab.get("gates"));
|
setCreativeTab(BCCreativeTab.getIfPresent("gates"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NBTTagCompound getNBT(ItemStack stack) {
|
private static NBTTagCompound getNBT(ItemStack stack) {
|
||||||
|
|
Loading…
Reference in a new issue