Fix 559 Allow mod wrenches to activate compass function

This commit is contained in:
Ryan Bemrose 2017-01-10 01:35:26 -08:00
parent c6aa2201ef
commit e38437dfa8
3 changed files with 67 additions and 4 deletions

View file

@ -57,6 +57,7 @@ import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.event.*;
import lib.mcjty.varia.WrenchChecker;
// So that BuildCraft Oil always gets used // So that BuildCraft Oil always gets used
@Mod(modid = ModUtil.MOD_ID, name = ModUtil.NAME, version = ModUtil.VERSION, dependencies = "after:BuildCraft|Energy", guiFactory = "de.ellpeck.actuallyadditions.mod.config.GuiFactory") @Mod(modid = ModUtil.MOD_ID, name = ModUtil.NAME, version = ModUtil.VERSION, dependencies = "after:BuildCraft|Energy", guiFactory = "de.ellpeck.actuallyadditions.mod.config.GuiFactory")
@ -105,6 +106,8 @@ public class ActuallyAdditions{
new UpdateChecker(); new UpdateChecker();
proxy.preInit(event); proxy.preInit(event);
WrenchChecker.init();
ModUtil.LOGGER.info("PreInitialization Finished."); ModUtil.LOGGER.info("PreInitialization Finished.");
} }

View file

@ -28,6 +28,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemCompass; import net.minecraft.item.ItemCompass;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -48,6 +49,7 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import lib.mcjty.varia.WrenchChecker;
public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
@ -163,7 +165,8 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
if(tile instanceof TileEntityLaserRelay){ if(tile instanceof TileEntityLaserRelay){
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile; TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
if(StackUtil.isValid(stack) && stack.getItem() instanceof ItemCompass){ Item item = stack.getItem();
if(StackUtil.isValid(stack) && (item instanceof ItemCompass || WrenchChecker.isAWrench(item))){
if(!world.isRemote){ if(!world.isRemote){
relay.onCompassAction(player); relay.onCompassAction(player);
@ -210,8 +213,9 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){ public void displayHud(Minecraft minecraft, EntityPlayer player, ItemStack stack, RayTraceResult posHit, ScaledResolution resolution){
if(posHit != null && posHit.getBlockPos() != null && minecraft.world != null && StackUtil.isValid(stack)){ if(posHit != null && posHit.getBlockPos() != null && minecraft.world != null && StackUtil.isValid(stack)){
boolean compass = stack.getItem() instanceof ItemCompass; Item item = stack.getItem();
if(compass || stack.getItem() instanceof ItemLaserWrench){ boolean compass = (item instanceof ItemCompass || WrenchChecker.isAWrench(item));
if(compass || item instanceof ItemLaserWrench){
TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos()); TileEntity tile = minecraft.world.getTileEntity(posHit.getBlockPos());
if(tile instanceof TileEntityLaserRelay){ if(tile instanceof TileEntityLaserRelay){
TileEntityLaserRelay relay = (TileEntityLaserRelay)tile; TileEntityLaserRelay relay = (TileEntityLaserRelay)tile;
@ -224,7 +228,7 @@ public class BlockLaserRelay extends BlockContainerBase implements IHudDisplay{
expl = relay.getCompassDisplayString(); expl = relay.getCompassDisplayString();
} }
else{ else{
expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a Compass to modify!"; expl = TextFormatting.GRAY.toString()+TextFormatting.ITALIC+"Hold a Compass or wrench to modify!";
} }
StringUtil.drawSplitString(minecraft.fontRendererObj, expl, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+15, Integer.MAX_VALUE, StringUtil.DECIMAL_COLOR_WHITE, true); StringUtil.drawSplitString(minecraft.fontRendererObj, expl, resolution.getScaledWidth()/2+5, resolution.getScaledHeight()/2+15, Integer.MAX_VALUE, StringUtil.DECIMAL_COLOR_WHITE, true);

View file

@ -0,0 +1,56 @@
package lib.mcjty.varia;
import net.minecraft.item.Item;
import java.util.ArrayList;
import java.util.List;
public class WrenchChecker {
private static List<Class> wrenchClasses=new ArrayList<Class>();
public static void init() {
for (String className : new String[] {
/*
* Can add or remove class names here
* Use API interface names where possible, in case of refactoring
* note that many mods implement BC wrench API iff BC is installed
* and include no wrench API of their own - we use implementation
* classes here to catch these cases.
*/
"buildcraft.api.tools.IToolWrench", //Buildcraft
"resonant.core.content.ItemScrewdriver", //Resonant Induction
"ic2.core.item.tool.ItemToolWrench", //IC2
"ic2.core.item.tool.ItemToolWrenchElectric", //IC2 (more)
"mrtjp.projectred.api.IScrewdriver", //Project Red
"mods.railcraft.api.core.items.IToolCrowbar", //Railcraft
"com.bluepowermod.items.ItemScrewdriver", //BluePower
"cofh.api.item.IToolHammer", //Thermal Expansion and compatible
"thermalexpansion.item.tool.ItemWrench",
"appeng.items.tools.quartz.ToolQuartzWrench", //Applied Energistics
"crazypants.enderio.api.tool.ITool", //Ender IO
"mekanism.api.IMekWrench", //Mekanism
"mcjty.rftools.items.smartwrench", //RFTools
"pneumaticCraft.common.item.ItemPneumaticWrench",
"powercrystals.minefactoryreloaded.api.IToolHammer"
}) {
try {
wrenchClasses.add(Class.forName(className));
de.ellpeck.actuallyadditions.mod.util.ModUtil.LOGGER.info("Found wrench class " + className);
} catch (ClassNotFoundException e) {
// Logging.log("Failed to load wrench class " + className + " (this is not an error)");
}
}
}
public static boolean isAWrench(Item item) {
for (Class c : wrenchClasses) {
if (c.isAssignableFrom(item.getClass())) {
return true;
}
}
return false;
}
}