mirror of
https://github.com/GTNewHorizons/Applied-Energistics-2-Unofficial.git
synced 2026-11-14 01:14:11 +00:00
Rework icon null checks (#517)
* Rework icon null checks * Make those client only as well
This commit is contained in:
1 parent
9428922271
commit
059b54c1f3
15 files changed
+87
-51
No files matched your search
@@ -10,10 +10,6 @@
|
||||
|
||||
package appeng.client.texture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -217,7 +213,6 @@ public enum CableBusTextures {
|
||||
|
||||
private final String name;
|
||||
public IIcon IIcon;
|
||||
private static TextureAtlasSprite missingTexture = null;
|
||||
|
||||
CableBusTextures(final String name) {
|
||||
this.name = name;
|
||||
@@ -229,24 +224,7 @@ public enum CableBusTextures {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static IIcon getMissing() {
|
||||
if (missingTexture == null) {
|
||||
missingTexture = ((TextureMap) Minecraft.getMinecraft().getTextureManager()
|
||||
.getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
|
||||
}
|
||||
|
||||
return missingTexture;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Nonnull
|
||||
public static IIcon checkTexture(IIcon val) {
|
||||
if (val == null) {
|
||||
val = CableBusTextures.getMissing();
|
||||
}
|
||||
|
||||
assert val != null;
|
||||
|
||||
return val;
|
||||
return TextureUtils.getMissingBlock();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
package appeng.client.texture;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -167,8 +166,7 @@ public enum ExtraBlockTextures {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static IIcon getMissing() {
|
||||
return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture))
|
||||
.getAtlasSprite("missingno");
|
||||
return TextureUtils.getMissingBlock();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
package appeng.client.texture;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -42,8 +41,7 @@ public enum ExtraItemTextures {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static IIcon getMissing() {
|
||||
return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationItemsTexture))
|
||||
.getAtlasSprite("missingno");
|
||||
return TextureUtils.getMissingItem();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
@@ -20,7 +20,8 @@ public class FlippableIcon implements IIcon {
|
||||
private boolean flip_u;
|
||||
private boolean flip_v;
|
||||
|
||||
public FlippableIcon(final IIcon o) {
|
||||
public FlippableIcon(IIcon o) {
|
||||
o = TextureUtils.checkTexture(o);
|
||||
if (o == null) {
|
||||
throw new IllegalArgumentException("Cannot create a wrapper icon with a null icon.");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ public class FullIcon implements IIcon {
|
||||
|
||||
private final IIcon p;
|
||||
|
||||
public FullIcon(final IIcon o) {
|
||||
public FullIcon(IIcon o) {
|
||||
o = TextureUtils.checkTexture(o);
|
||||
if (o == null) {
|
||||
throw new IllegalArgumentException("Cannot create a wrapper icon with a null icon.");
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
package appeng.client.texture;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -33,9 +31,7 @@ public class MissingIcon implements IIcon {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon getMissing() {
|
||||
return ((TextureMap) Minecraft.getMinecraft().getTextureManager()
|
||||
.getTexture(this.isBlock ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture))
|
||||
.getAtlasSprite("missingno");
|
||||
return isBlock ? TextureUtils.getMissingBlock() : TextureUtils.getMissingItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,8 @@ public class OffsetIcon implements IIcon {
|
||||
|
||||
private final IIcon p;
|
||||
|
||||
public OffsetIcon(final IIcon o, final float x, final float y) {
|
||||
public OffsetIcon(IIcon o, final float x, final float y) {
|
||||
o = TextureUtils.checkTexture(o);
|
||||
if (o == null) {
|
||||
throw new IllegalArgumentException("Cannot create a wrapper icon with a null icon.");
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ public class TaughtIcon implements IIcon {
|
||||
|
||||
private final IIcon icon;
|
||||
|
||||
public TaughtIcon(final IIcon icon, final float tightness) {
|
||||
public TaughtIcon(IIcon icon, final float tightness) {
|
||||
icon = TextureUtils.checkTexture(icon);
|
||||
if (icon == null) {
|
||||
throw new IllegalArgumentException("Cannot create a wrapper icon with a null icon.");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package appeng.client.texture;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TextureUtils {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Nonnull
|
||||
public static IIcon checkTexture(IIcon val) {
|
||||
return checkTexture(val, true);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Nonnull
|
||||
public static IIcon checkTexture(IIcon val, boolean isBlock) {
|
||||
if (val == null) {
|
||||
val = isBlock ? getMissingBlock() : getMissingItem();
|
||||
}
|
||||
|
||||
assert val != null;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static TextureAtlasSprite missingBlockTexture;
|
||||
@SideOnly(Side.CLIENT)
|
||||
private static TextureAtlasSprite missingItemTexture;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static IIcon getMissingBlock() {
|
||||
if (missingBlockTexture == null) {
|
||||
missingBlockTexture = ((TextureMap) Minecraft.getMinecraft().getTextureManager()
|
||||
.getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
|
||||
}
|
||||
|
||||
return missingBlockTexture;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static IIcon getMissingItem() {
|
||||
if (missingItemTexture == null) {
|
||||
missingItemTexture = ((TextureMap) Minecraft.getMinecraft().getTextureManager()
|
||||
.getTexture(TextureMap.locationItemsTexture)).getAtlasSprite("missingno");
|
||||
}
|
||||
|
||||
return missingItemTexture;
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ import appeng.block.AEBaseBlock;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.client.texture.FlippableIcon;
|
||||
import appeng.client.texture.TaughtIcon;
|
||||
import appeng.client.texture.TextureUtils;
|
||||
import appeng.items.parts.ItemMultiPart;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.AEBasePart;
|
||||
@@ -206,7 +207,7 @@ public class PartCable extends AEBasePart implements IPartCable {
|
||||
}
|
||||
|
||||
public IIcon getGlassTexture(final AEColor c) {
|
||||
return CableBusTextures.checkTexture(switch (c) {
|
||||
return TextureUtils.checkTexture(switch (c) {
|
||||
case Black -> CableBusTextures.MECable_Black.getIcon();
|
||||
case Blue -> CableBusTextures.MECable_Blue.getIcon();
|
||||
case Brown -> CableBusTextures.MECable_Brown.getIcon();
|
||||
@@ -451,7 +452,7 @@ public class PartCable extends AEBasePart implements IPartCable {
|
||||
}
|
||||
|
||||
public IIcon getCoveredTexture(final AEColor c) {
|
||||
return CableBusTextures.checkTexture(switch (c) {
|
||||
return TextureUtils.checkTexture(switch (c) {
|
||||
case Black -> CableBusTextures.MECovered_Black.getIcon();
|
||||
case Blue -> CableBusTextures.MECovered_Blue.getIcon();
|
||||
case Brown -> CableBusTextures.MECovered_Brown.getIcon();
|
||||
@@ -690,7 +691,7 @@ public class PartCable extends AEBasePart implements IPartCable {
|
||||
}
|
||||
|
||||
IIcon getSmartTexture(final AEColor c) {
|
||||
return CableBusTextures.checkTexture(switch (c) {
|
||||
return TextureUtils.checkTexture(switch (c) {
|
||||
case Black -> CableBusTextures.MESmart_Black.getIcon();
|
||||
case Blue -> CableBusTextures.MESmart_Blue.getIcon();
|
||||
case Brown -> CableBusTextures.MESmart_Brown.getIcon();
|
||||
|
||||
@@ -39,6 +39,7 @@ import appeng.client.texture.CableBusTextures;
|
||||
import appeng.client.texture.FlippableIcon;
|
||||
import appeng.client.texture.OffsetIcon;
|
||||
import appeng.client.texture.TaughtIcon;
|
||||
import appeng.client.texture.TextureUtils;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -152,7 +153,7 @@ public class PartDenseCable extends PartCable {
|
||||
@Override
|
||||
public IIcon getTexture(final AEColor c) {
|
||||
if (c == AEColor.Transparent) {
|
||||
CableBusTextures.checkTexture(
|
||||
TextureUtils.checkTexture(
|
||||
AEApi.instance().definitions().parts().cableSmart().stack(AEColor.Transparent, 1).getIconIndex());
|
||||
}
|
||||
|
||||
@@ -344,7 +345,7 @@ public class PartDenseCable extends PartCable {
|
||||
}
|
||||
|
||||
protected IIcon getDenseTexture(final AEColor c) {
|
||||
return CableBusTextures.checkTexture(switch (c) {
|
||||
return TextureUtils.checkTexture(switch (c) {
|
||||
case Black -> CableBusTextures.MEDense_Black.getIcon();
|
||||
case Blue -> CableBusTextures.MEDense_Blue.getIcon();
|
||||
case Brown -> CableBusTextures.MEDense_Brown.getIcon();
|
||||
|
||||
@@ -37,6 +37,7 @@ import appeng.block.AEBaseBlock;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.client.texture.FlippableIcon;
|
||||
import appeng.client.texture.OffsetIcon;
|
||||
import appeng.client.texture.TextureUtils;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -138,7 +139,7 @@ public class PartDenseCableCovered extends PartCable {
|
||||
@Override
|
||||
public IIcon getTexture(final AEColor c) {
|
||||
if (c == AEColor.Transparent) {
|
||||
return CableBusTextures.checkTexture(
|
||||
return TextureUtils.checkTexture(
|
||||
AEApi.instance().definitions().parts().cableCovered().stack(AEColor.Transparent, 1).getIconIndex());
|
||||
}
|
||||
|
||||
@@ -257,7 +258,7 @@ public class PartDenseCableCovered extends PartCable {
|
||||
}
|
||||
|
||||
protected IIcon getDenseCoveredTexture(final AEColor c) {
|
||||
return CableBusTextures.checkTexture(switch (c) {
|
||||
return TextureUtils.checkTexture(switch (c) {
|
||||
case Black -> CableBusTextures.MEDenseCovered_Black.getIcon();
|
||||
case Blue -> CableBusTextures.MEDenseCovered_Blue.getIcon();
|
||||
case Brown -> CableBusTextures.MEDenseCovered_Brown.getIcon();
|
||||
|
||||
@@ -33,7 +33,7 @@ import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.client.texture.TextureUtils;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.parts.AEBasePart;
|
||||
@@ -83,7 +83,7 @@ public class PartQuartzFiber extends AEBasePart implements IEnergyGridProvider {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(final int x, final int y, final int z, final IPartRenderHelper rh,
|
||||
final RenderBlocks renderer) {
|
||||
final IIcon myIcon = CableBusTextures.checkTexture(this.getItemStack().getIconIndex());
|
||||
final IIcon myIcon = TextureUtils.checkTexture(this.getItemStack().getIconIndex());
|
||||
rh.setTexture(myIcon);
|
||||
rh.setBounds(6, 6, 10, 10, 10, 16);
|
||||
rh.renderBlock(x, y, z, renderer);
|
||||
|
||||
@@ -8,6 +8,7 @@ import appeng.api.networking.GridFlags;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.client.texture.TextureUtils;
|
||||
import appeng.helpers.Reflected;
|
||||
|
||||
public class PartUltraDenseCableCovered extends PartDenseCableCovered {
|
||||
@@ -26,7 +27,7 @@ public class PartUltraDenseCableCovered extends PartDenseCableCovered {
|
||||
@Override
|
||||
public IIcon getTexture(final AEColor c) {
|
||||
if (c == AEColor.Transparent) {
|
||||
return CableBusTextures.checkTexture(
|
||||
return TextureUtils.checkTexture(
|
||||
AEApi.instance().definitions().parts().cableUltraDenseCovered().stack(AEColor.Transparent, 1)
|
||||
.getIconIndex());
|
||||
}
|
||||
@@ -36,7 +37,7 @@ public class PartUltraDenseCableCovered extends PartDenseCableCovered {
|
||||
|
||||
@Override
|
||||
protected IIcon getDenseCoveredTexture(final AEColor c) {
|
||||
return CableBusTextures.checkTexture(switch (c) {
|
||||
return TextureUtils.checkTexture(switch (c) {
|
||||
case Black -> CableBusTextures.MEUltraDenseCovered_Black.getIcon();
|
||||
case Blue -> CableBusTextures.MEUltraDenseCovered_Blue.getIcon();
|
||||
case Brown -> CableBusTextures.MEUltraDenseCovered_Brown.getIcon();
|
||||
|
||||
@@ -8,6 +8,7 @@ import appeng.api.networking.GridFlags;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.client.texture.TextureUtils;
|
||||
import appeng.helpers.Reflected;
|
||||
|
||||
public class PartUltraDenseCableSmart extends PartDenseCable {
|
||||
@@ -26,7 +27,7 @@ public class PartUltraDenseCableSmart extends PartDenseCable {
|
||||
@Override
|
||||
public IIcon getTexture(final AEColor c) {
|
||||
if (c == AEColor.Transparent) {
|
||||
return CableBusTextures.checkTexture(
|
||||
return TextureUtils.checkTexture(
|
||||
AEApi.instance().definitions().parts().cableUltraDenseSmart().stack(AEColor.Transparent, 1)
|
||||
.getIconIndex());
|
||||
}
|
||||
@@ -36,7 +37,7 @@ public class PartUltraDenseCableSmart extends PartDenseCable {
|
||||
|
||||
@Override
|
||||
protected IIcon getDenseTexture(final AEColor c) {
|
||||
return CableBusTextures.checkTexture(switch (c) {
|
||||
return TextureUtils.checkTexture(switch (c) {
|
||||
case Black -> CableBusTextures.MEUltraDense_Black.getIcon();
|
||||
case Blue -> CableBusTextures.MEUltraDense_Blue.getIcon();
|
||||
case Brown -> CableBusTextures.MEUltraDense_Brown.getIcon();
|
||||
|
||||
Reference in new issue
Block a user