mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-19 11:59:17 +00:00
#1662 add interfaces to control hiding conduits and display modes
This commit is contained in:
1 parent
83eee6beb0
commit
3cb8da4e87
18 files changed
+131
-41
No files matched your search
@@ -375,7 +375,7 @@ public class ClientProxy extends CommonProxy {
|
||||
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(EnderIO.blockTransceiver), tr);
|
||||
}
|
||||
|
||||
new YetaWrenchOverlayRenderer(EnderIO.itemYetaWench);
|
||||
new YetaWrenchOverlayRenderer();
|
||||
new ConduitProbeOverlayRenderer();
|
||||
if(Config.useSneakMouseWheelYetaWrench) {
|
||||
ToolTickHandler th = new ToolTickHandler();
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package crazypants.enderio.api.tool;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Interface for items which support the overlay and conduit view modes
|
||||
*/
|
||||
public interface IConduitControl extends IHideFacades {
|
||||
|
||||
/**
|
||||
* Controls whether the overlay is shown and the player can change the display
|
||||
* mode.
|
||||
*
|
||||
* @param stack
|
||||
* The itemstack
|
||||
* @param player
|
||||
* The player holding the itemstack
|
||||
* @return True if the overlay should be rendered and the player should be
|
||||
* able to change modes. False otherwise.
|
||||
*/
|
||||
boolean showOverlay(ItemStack stack, EntityPlayer player);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package crazypants.enderio.api.tool;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IHideFacades {
|
||||
|
||||
boolean shouldHideFacades(ItemStack stack, EntityPlayer player);
|
||||
|
||||
}
|
||||
@@ -4,12 +4,10 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface ITool {
|
||||
public interface ITool extends IHideFacades {
|
||||
|
||||
boolean canUse(ItemStack stack, EntityPlayer player, int x, int y, int z);
|
||||
|
||||
void used(ItemStack stack, EntityPlayer player, int x, int y, int z);
|
||||
|
||||
boolean shouldHideFacades(ItemStack stack, EntityPlayer player);
|
||||
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
package crazypants.enderio.conduit;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.api.tool.IConduitControl;
|
||||
import crazypants.enderio.conduit.gas.GasUtil;
|
||||
import crazypants.enderio.conduit.me.MEUtil;
|
||||
|
||||
@@ -45,20 +46,31 @@ public enum ConduitDisplayMode {
|
||||
return res;
|
||||
}
|
||||
|
||||
private static final String NBT_KEY = "enderio.displaymode";
|
||||
|
||||
public static ConduitDisplayMode getDisplayMode(ItemStack equipped) {
|
||||
if(equipped == null || equipped.getItem() != EnderIO.itemYetaWench) {
|
||||
if(equipped == null || !(equipped.getItem() instanceof IConduitControl)) {
|
||||
return ALL;
|
||||
}
|
||||
int index = equipped.getItemDamage();
|
||||
initDisplayModeTag(equipped);
|
||||
int index = equipped.stackTagCompound.getInteger(NBT_KEY);
|
||||
index = MathHelper.clamp_int(index, 0, ConduitDisplayMode.values().length - 1);
|
||||
return ConduitDisplayMode.values()[index];
|
||||
}
|
||||
|
||||
public static void setDisplayMode(ItemStack equipped, ConduitDisplayMode mode) {
|
||||
if(mode == null || equipped == null) {
|
||||
if(mode == null || equipped == null || !(equipped.getItem() instanceof IConduitControl)) {
|
||||
return;
|
||||
}
|
||||
equipped.setItemDamage(mode.ordinal());
|
||||
initDisplayModeTag(equipped);
|
||||
equipped.stackTagCompound.setInteger(NBT_KEY, mode.ordinal());
|
||||
}
|
||||
|
||||
private static void initDisplayModeTag(ItemStack stack) {
|
||||
if (stack.stackTagCompound == null) {
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
stack.stackTagCompound.setInteger(NBT_KEY, ConduitDisplayMode.ALL.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
public ConduitDisplayMode next() {
|
||||
|
||||
@@ -24,6 +24,8 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.Log;
|
||||
import crazypants.enderio.api.tool.IConduitControl;
|
||||
import crazypants.enderio.api.tool.IHideFacades;
|
||||
import crazypants.enderio.conduit.IConduitBundle.FacadeRenderState;
|
||||
import crazypants.enderio.conduit.gas.GasConduitNetwork;
|
||||
import crazypants.enderio.conduit.gas.IGasConduit;
|
||||
@@ -44,7 +46,6 @@ import crazypants.enderio.conduit.redstone.IRedstoneConduit;
|
||||
import crazypants.enderio.conduit.redstone.RedstoneConduitNetwork;
|
||||
import crazypants.enderio.conduit.redstone.Signal;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.tool.ToolUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.DyeColor;
|
||||
|
||||
@@ -177,7 +178,7 @@ public class ConduitUtil {
|
||||
}
|
||||
|
||||
public static boolean isFacadeHidden(IConduitBundle bundle, EntityPlayer player) {
|
||||
return bundle.getFacadeId() != null && ((ToolUtil.isToolEquipped(player) && (player == null || ToolUtil.getEquippedTool(player).shouldHideFacades(player.getCurrentEquippedItem(), player))) || isConduitEquipped(player) || isProbeEquipped(player));
|
||||
return bundle.getFacadeId() != null && shouldHeldItemHideFacades(player);
|
||||
}
|
||||
|
||||
public static ConduitDisplayMode getDisplayMode(EntityPlayer player) {
|
||||
@@ -190,10 +191,6 @@ public class ConduitUtil {
|
||||
return ConduitDisplayMode.ALL;
|
||||
}
|
||||
|
||||
if(equipped.getItem() != EnderIO.itemYetaWench) {
|
||||
return ConduitDisplayMode.ALL;
|
||||
}
|
||||
|
||||
ConduitDisplayMode result = ConduitDisplayMode.getDisplayMode(equipped);
|
||||
if(result == null) {
|
||||
return ConduitDisplayMode.ALL;
|
||||
@@ -234,6 +231,18 @@ public class ConduitUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean shouldHeldItemHideFacades(EntityPlayer player) {
|
||||
player = player == null ? EnderIO.proxy.getClientPlayer() : player;
|
||||
if (player == null) {
|
||||
return false;
|
||||
}
|
||||
ItemStack held = player.getCurrentEquippedItem();
|
||||
if (held != null && held.getItem() instanceof IHideFacades) {
|
||||
return ((IHideFacades)held.getItem()).shouldHideFacades(held, player);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isConduitEquipped(EntityPlayer player) {
|
||||
player = player == null ? EnderIO.proxy.getClientPlayer() : player;
|
||||
if(player == null) {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package crazypants.enderio.conduit;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.enderio.api.tool.IHideFacades;
|
||||
|
||||
public interface IConduitItem {
|
||||
public interface IConduitItem extends IHideFacades {
|
||||
|
||||
Class<? extends IConduit> getBaseConduitType();
|
||||
|
||||
|
||||
@@ -65,5 +65,10 @@ public class ItemGasConduit extends AbstractItemConduit implements IAdvancedTool
|
||||
list.add(Lang.localize("itemGasConduit.tooltip.maxIo") + " " + maxIo + gpt);
|
||||
TooltipAddera.addDetailedTooltipFromResources(list, "enderio.itemGasConduit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package crazypants.enderio.conduit.item;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.AbstractItemConduit;
|
||||
@@ -36,4 +37,8 @@ public class ItemItemConduit extends AbstractItemConduit {
|
||||
return new ItemConduit(item.getItemDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,9 @@ public class ItemLiquidConduit extends AbstractItemConduit implements IAdvancedT
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package crazypants.enderio.conduit.me;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.AbstractItemConduit;
|
||||
@@ -34,4 +35,9 @@ public class ItemMEConduit extends AbstractItemConduit {
|
||||
public IConduit createConduit(ItemStack item) {
|
||||
return new MEConduit(item.getItemDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -56,5 +56,9 @@ public class ItemPowerConduit extends AbstractItemConduit {
|
||||
ICapacitor cap = PowerConduit.getCapacitors()[itemStack.getItemDamage()];
|
||||
list.add(PREFIX + PowerDisplayUtil.formatPower(cap.getMaxEnergyExtracted()) + POSTFIX);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package crazypants.enderio.conduit.redstone;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.AbstractItemConduit;
|
||||
@@ -42,4 +43,8 @@ public class ItemRedstoneConduit extends AbstractItemConduit {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,8 @@ package crazypants.enderio.item;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -19,18 +15,15 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.ConduitUtil;
|
||||
import crazypants.enderio.api.tool.IHideFacades;
|
||||
import crazypants.enderio.conduit.IConduit;
|
||||
import crazypants.enderio.conduit.IConduitBundle;
|
||||
import crazypants.enderio.conduit.redstone.IInsulatedRedstoneConduit;
|
||||
import crazypants.enderio.gui.IResourceTooltipProvider;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
|
||||
public class ItemConduitProbe extends Item implements IResourceTooltipProvider {
|
||||
public class ItemConduitProbe extends Item implements IResourceTooltipProvider, IHideFacades {
|
||||
|
||||
private static final NumberFormat NF = NumberFormat.getIntegerInstance();
|
||||
|
||||
@@ -124,5 +117,9 @@ public class ItemConduitProbe extends Item implements IResourceTooltipProvider {
|
||||
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.api.tool.IConduitControl;
|
||||
import crazypants.enderio.api.tool.ITool;
|
||||
import crazypants.enderio.conduit.ConduitDisplayMode;
|
||||
import crazypants.enderio.config.Config;
|
||||
@@ -27,7 +28,7 @@ import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.tool.ToolUtil;
|
||||
import crazypants.util.Lang;
|
||||
|
||||
public class ItemYetaWrench extends Item implements ITool, IAdvancedTooltipProvider, InvocationHandler {
|
||||
public class ItemYetaWrench extends Item implements ITool, IConduitControl, IAdvancedTooltipProvider, InvocationHandler {
|
||||
|
||||
public static ItemYetaWrench create() {
|
||||
if(Config.useSneakMouseWheelYetaWrench) {
|
||||
@@ -107,6 +108,11 @@ public class ItemYetaWrench extends Item implements ITool, IAdvancedTooltipProvi
|
||||
public boolean shouldHideFacades(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean showOverlay(ItemStack stack, EntityPlayer player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IAdvancedTooltipProvider */
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.item.darksteel.DarkSteelItems;
|
||||
import crazypants.enderio.api.tool.IConduitControl;
|
||||
import crazypants.enderio.conduit.ConduitDisplayMode;
|
||||
import crazypants.enderio.item.darksteel.DarkSteelController;
|
||||
import crazypants.enderio.item.darksteel.GogglesOfRevealingUpgrade;
|
||||
@@ -143,7 +144,7 @@ public class KeyTracker {
|
||||
if(equipped == null) {
|
||||
return;
|
||||
}
|
||||
if(equipped.getItem() == EnderIO.itemYetaWench) {
|
||||
if(equipped.getItem() instanceof IConduitControl) {
|
||||
ConduitDisplayMode curMode = ConduitDisplayMode.getDisplayMode(equipped);
|
||||
if(curMode == null) {
|
||||
curMode = ConduitDisplayMode.ALL;
|
||||
|
||||
@@ -2,6 +2,7 @@ package crazypants.enderio.item;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
@@ -12,6 +13,7 @@ import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.api.tool.IConduitControl;
|
||||
import crazypants.enderio.conduit.ConduitDisplayMode;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
|
||||
@@ -47,8 +49,8 @@ public class ToolTickHandler {
|
||||
}
|
||||
if(stack.getItem() == EnderIO.itemConduitProbe) {
|
||||
changeConduitProbeMode(stack);
|
||||
} else if(stack.getItem() ==EnderIO.itemYetaWench) {
|
||||
changeYetaWrenchMode(stack);
|
||||
} else if(stack.getItem() instanceof IConduitControl) {
|
||||
changeDisplayMode(stack, player);
|
||||
}
|
||||
}
|
||||
slotSelected = -1;
|
||||
@@ -57,7 +59,10 @@ public class ToolTickHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void changeYetaWrenchMode(ItemStack stack) {
|
||||
private void changeDisplayMode(ItemStack stack, EntityPlayer player) {
|
||||
if (!((IConduitControl)stack.getItem()).showOverlay(stack, player)) {
|
||||
return;
|
||||
}
|
||||
ConduitDisplayMode curMode = ConduitDisplayMode.getDisplayMode(stack);
|
||||
if(curMode == null) {
|
||||
curMode = ConduitDisplayMode.ALL;
|
||||
@@ -85,7 +90,7 @@ public class ToolTickHandler {
|
||||
|
||||
private boolean isToolSelected(EntityClientPlayerMP player) {
|
||||
return player != null && player.getCurrentEquippedItem() != null &&
|
||||
(player.getCurrentEquippedItem().getItem() == EnderIO.itemYetaWench || player.getCurrentEquippedItem().getItem() == EnderIO.itemConduitProbe);
|
||||
(player.getCurrentEquippedItem().getItem() instanceof IConduitControl || player.getCurrentEquippedItem().getItem() == EnderIO.itemConduitProbe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
@@ -14,6 +15,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import crazypants.enderio.api.tool.IConduitControl;
|
||||
import crazypants.enderio.conduit.ConduitDisplayMode;
|
||||
import crazypants.enderio.conduit.gas.GasUtil;
|
||||
import crazypants.enderio.conduit.me.MEUtil;
|
||||
@@ -21,15 +23,12 @@ import crazypants.enderio.gui.IconEIO;
|
||||
|
||||
public class YetaWrenchOverlayRenderer {
|
||||
|
||||
private ItemYetaWrench wrench;
|
||||
|
||||
private IconEIO[] onIcons;
|
||||
private IconEIO[] offIcons;
|
||||
private Point[] iconOffsets;
|
||||
private Map<ConduitDisplayMode, Integer> indices = new EnumMap<ConduitDisplayMode, Integer>(ConduitDisplayMode.class);
|
||||
|
||||
public YetaWrenchOverlayRenderer(ItemYetaWrench wrench) {
|
||||
this.wrench = wrench;
|
||||
public YetaWrenchOverlayRenderer() {
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@@ -42,9 +41,10 @@ public class YetaWrenchOverlayRenderer {
|
||||
}
|
||||
|
||||
private ItemStack getEquippedWrench() {
|
||||
ItemStack equipped = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem();
|
||||
if(equipped != null && equipped.getItem() == wrench) {
|
||||
return equipped;
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
ItemStack equipped = player.getCurrentEquippedItem();
|
||||
if(equipped != null && equipped.getItem() instanceof IConduitControl) {
|
||||
return ((IConduitControl) equipped.getItem()).showOverlay(equipped, player) ? equipped : null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user