Better support for mod blocks in facades

Blocks can be blacklisted from becoming facades in the config
Added an IMC message for blacklisting facades. send an IMC message with the item stack, and the blacklist-facade command
Register FacadeRecipe with the RecipeSorter
Facades store the block registry block name in place of the ID. Existing facades will be updated automatically.
The add-facade IMC string message implementation now requires block registry name instead of id. (but still works with id, for now)
The FacadeRecipe handler will rotate through the meta of the blocks the facade is made from allowing cycling through variants (such as colors of wool).
This commit is contained in:
Cisien 2014-02-22 15:41:46 -08:00
parent 616a59c152
commit 55ef362018
5 changed files with 288 additions and 123 deletions

View file

@ -14,10 +14,10 @@ import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.api.transport.IExtractionHandler;
import buildcraft.api.transport.PipeManager;
import buildcraft.core.DefaultProps;
import buildcraft.core.BuildCraftConfiguration;
import buildcraft.core.InterModComms;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.Version;
import buildcraft.core.network.PacketHandler;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCTrigger;
@ -34,11 +34,6 @@ import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTriggerProvider;
import buildcraft.transport.TransportProxy;
import buildcraft.transport.WireIconProvider;
import buildcraft.transport.blueprints.BptBlockPipe;
import buildcraft.transport.blueprints.BptItemPipeDiamond;
import buildcraft.transport.blueprints.BptItemPipeEmerald;
import buildcraft.transport.blueprints.BptItemPipeIron;
import buildcraft.transport.blueprints.BptItemPipeWooden;
import buildcraft.transport.gates.GateExpansionPulsar;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.transport.PipeWire;
@ -46,7 +41,6 @@ import buildcraft.transport.ItemPipeWire;
import buildcraft.transport.gates.GateExpansionRedstoneFader;
import buildcraft.transport.gates.GateExpansionTimer;
import buildcraft.transport.network.PacketHandlerTransport;
import buildcraft.transport.network.PacketPipeTransportTraveler;
import buildcraft.transport.pipes.PipeFluidsCobblestone;
import buildcraft.transport.pipes.PipeFluidsEmerald;
import buildcraft.transport.pipes.PipeFluidsGold;
@ -115,6 +109,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.common.config.Property;
import net.minecraftforge.oredict.RecipeSorter;
@Mod(version = Version.VERSION, modid = "BuildCraft|Transport", name = "Buildcraft Transport", dependencies = DefaultProps.DEPENDENCY_CORE)
public class BuildCraftTransport extends BuildCraftMod {
@ -159,6 +154,8 @@ public class BuildCraftTransport extends BuildCraftMod {
// public static Item pipeItemsStipes;
public static Item pipeStructureCobblestone;
public static int groupItemsTrigger;
public static String[] facadeBlacklist;
public static BCTrigger[] triggerPipe = new BCTrigger[PipeContents.values().length];
public static BCTrigger[] triggerPipeWireActive = new BCTrigger[PipeWire.values().length];
public static BCTrigger[] triggerPipeWireInactive = new BCTrigger[PipeWire.values().length];
@ -177,6 +174,7 @@ public class BuildCraftTransport extends BuildCraftMod {
public static BCAction actionExtractionPresetYellow = new ActionExtractionPreset(EnumColor.YELLOW);
public IIconProvider pipeIconProvider = new PipeIconProvider();
public IIconProvider wireIconProvider = new WireIconProvider();
@Instance("BuildCraft|Transport")
public static BuildCraftTransport instance;
@ -257,6 +255,9 @@ public class BuildCraftTransport extends BuildCraftMod {
} else
excludedFluidBlocks = new String[0];
filteredBufferBlock = new BlockFilteredBuffer();
CoreProxy.proxy.registerBlock(filteredBufferBlock.setBlockName("filteredBufferBlock"));
PipeManager.registerExtractionHandler(new ExtractionHandler(excludedItemBlocks, excludedFluidBlocks));
GateExpansions.registerExpansion(GateExpansionPulsar.INSTANCE);
@ -267,6 +268,36 @@ public class BuildCraftTransport extends BuildCraftMod {
groupItemsTriggerProp.comment = "when reaching this amount of objects in a pipes, items will be automatically grouped";
groupItemsTrigger = groupItemsTriggerProp.getInt();
Property facadeBlacklistProp = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "facade.blacklist", new String[] {
Block.blockRegistry.getNameForObject(Blocks.bedrock),
Block.blockRegistry.getNameForObject(Blocks.command_block),
Block.blockRegistry.getNameForObject(Blocks.end_portal_frame),
Block.blockRegistry.getNameForObject(Blocks.grass),
Block.blockRegistry.getNameForObject(Blocks.leaves),
Block.blockRegistry.getNameForObject(Blocks.leaves2),
Block.blockRegistry.getNameForObject(Blocks.lit_pumpkin),
Block.blockRegistry.getNameForObject(Blocks.lit_redstone_lamp),
Block.blockRegistry.getNameForObject(Blocks.mob_spawner),
Block.blockRegistry.getNameForObject(Blocks.monster_egg),
Block.blockRegistry.getNameForObject(Blocks.redstone_lamp),
Block.blockRegistry.getNameForObject(Blocks.double_stone_slab),
Block.blockRegistry.getNameForObject(Blocks.double_wooden_slab),
Block.blockRegistry.getNameForObject(Blocks.sponge),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.architectBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.builderBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.fillerBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.libraryBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.autoWorkbenchBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.floodGateBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.miningWellBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.pumpBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.quarryBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftTransport.filteredBufferBlock)),
});
facadeBlacklistProp.comment = "Blocks listed here will not have facades created. The format is modid:blockname.\nFor mods with a | character, the value needs to be surrounded with quotes.";
facadeBlacklist = facadeBlacklistProp.getStringList();
pipeWaterproof = new ItemBuildCraft();
pipeWaterproof.setUnlocalizedName("pipeWaterproof");
LanguageRegistry.addName(pipeWaterproof, "Pipe Sealant");
@ -330,9 +361,6 @@ public class BuildCraftTransport extends BuildCraftMod {
plugItem.setUnlocalizedName("pipePlug");
CoreProxy.proxy.registerItem(plugItem);
filteredBufferBlock = new BlockFilteredBuffer();
CoreProxy.proxy.registerBlock(filteredBufferBlock.setBlockName("filteredBufferBlock"));
for (PipeContents kind : PipeContents.values()) {
triggerPipe[kind.ordinal()] = new TriggerPipeContents(kind);
}
@ -435,6 +463,7 @@ public class BuildCraftTransport extends BuildCraftMod {
//Facade turning helper
GameRegistry.addRecipe(facadeItem.new FacadeRecipe());
RecipeSorter.register("facadeTurningHelper", ItemFacade.FacadeRecipe.class, RecipeSorter.Category.SHAPELESS, "");
BuildcraftRecipes.assemblyTable.addRecipe(1000, new ItemStack(plugItem, 8), new ItemStack(pipeStructureCobblestone));
}

View file

@ -25,4 +25,11 @@ public class BuildCraftConfiguration extends Configuration {
super.save();
}
public static String surroundWithQuotes(String stringToSurroundWithQuotes){
return String.format("\"%s\"", stringToSurroundWithQuotes);
}
public static String stripSurroundingQuotes(String stringToStripQuotes) {
return stringToStripQuotes.replaceAll("^\"|\"$", "");
}
}

View file

@ -11,6 +11,7 @@ package buildcraft.core;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.base.Strings;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
@ -28,9 +29,11 @@ public class InterModComms {
public static void processIMC(IMCEvent event) {
for (IMCMessage m : event.getMessages()) {
if ("add-facade".equals(m.key)) {
processFacadeIMC(event, m);
} else if (m.key.equals("oil-lake-biome")) {
if (m.key.equals("add-facade")) {
processAddFacadeIMC(event, m);
} else if (m.key.equals("blacklist-facade")) {
processBlacklistFacadeIMC(event, m);
} else if (m.key.equals("oil-lake-biome")) {
processOilLakeBiomeIMC(event, m);
} else if (m.key.equals("oil-gen-exclude")) {
processOilGenExcludeIMC(event, m);
@ -38,8 +41,8 @@ public class InterModComms {
}
}
public static void processFacadeIMC(IMCEvent event, IMCMessage m) {
try {
public static void processAddFacadeIMC(IMCEvent event, IMCMessage m) {
try {
if (m.isStringMessage()) {
Splitter splitter = Splitter.on("@").trimResults();
@ -47,24 +50,57 @@ public class InterModComms {
if (array.length != 2) {
Logger.getLogger("Buildcraft").log(Level.INFO, String.format("Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender()));
} else {
Integer blId = Ints.tryParse(array[0]);
Integer metaId = Ints.tryParse(array[1]);
if (blId == null || metaId == null) {
String blockName = array[0];
Integer metaId = Ints.tryParse(array[1]);
if (Strings.isNullOrEmpty(blockName)|| metaId == null) {
Logger.getLogger("Buildcraft").log(Level.INFO, String.format("Received an invalid add-facade request %s from mod %s", m.getStringValue(), m.getSender()));
} else {
Block block = (Block) Block.blockRegistry.getObjectById(blId);
ItemFacade.addFacade(new ItemStack(block, 1, metaId));
Block block = (Block) Block.blockRegistry.getObject(blockName);
if(block.getRenderType() != 0 && block.getRenderType() != 31) {
ItemFacade.addFacade(new ItemStack(block, 1, metaId));
} else {
logRedundantAddFacadeMessage(m, block.toString());
}
}
}
} else if (m.isItemStackMessage()) {
ItemFacade.addFacade(m.getItemStackValue());
ItemStack modItemStack = m.getItemStackValue();
Block block = Block.getBlockFromItem(modItemStack.getItem());
if(block != null && block.getRenderType() != 0 && block.getRenderType() != 31) {
ItemFacade.addFacade(modItemStack);
} else {
logRedundantAddFacadeMessage(m, block.toString());
}
}
} catch (Exception ex) {
}
}
public static void processBlacklistFacadeIMC(IMCEvent event, IMCMessage message){
try {
if(message.isItemStackMessage()) {
ItemStack modItemStack = message.getItemStackValue();
Block block = Block.getBlockFromItem(modItemStack.getItem());
if(block != null) {
String blockName = Block.blockRegistry.getNameForObject(block);
ItemFacade.blacklistFacade(blockName);
}
} else {
Logger.getLogger("Buildcraft").log(Level.INFO, String.format("Invalid blacklist-facade message from mod %s. Send an ItemStackMessage instead.", message.getSender()));
}
} catch (Throwable _) {
}
}
private static void logRedundantAddFacadeMessage(IMCMessage m, String blockName)
{
Logger.getLogger("Buildcraft").log(Level.WARNING, String.format("%s is trying to add %s a facade that Buildcraft will add later. Facade not added.", m.getSender(), blockName));
}
public static void processOilLakeBiomeIMC(IMCEvent event, IMCMessage m) {
try {
String biomeID = m.getStringValue().trim();

View file

@ -12,6 +12,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import buildcraft.core.BlockSpring;
import buildcraft.core.BuildCraftConfiguration;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
@ -41,6 +43,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public class ItemFacade extends ItemBuildCraft {
public final static LinkedList<ItemStack> allFacades = new LinkedList<ItemStack>();
public final static LinkedList<String> blacklistedFacades = new LinkedList<String>();
public ItemFacade() {
super();
@ -62,7 +65,13 @@ public class ItemFacade extends ItemBuildCraft {
if (Item.getItemFromBlock(decodedBlock) != null) {
name += ": " + CoreProxy.proxy.getItemDisplayName(newStack);
} else {
name += " < BROKEN (" + decodedBlock.getLocalizedName() + ":" + decodedMeta + " )>";
String localizedName;
try {
localizedName = decodedBlock.getLocalizedName();
} catch(NullPointerException npe) {
localizedName = "Null";
}
name += " < BROKEN (" + localizedName + ":" + decodedMeta + " )>";
}
return name;
}
@ -95,11 +104,11 @@ public class ItemFacade extends ItemBuildCraft {
TileGenericPipe pipeTile = (TileGenericPipe) tile;
if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), ItemFacade.getBlock(stack), ItemFacade.getMetaData(stack))) {
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}
stack.stackSize--;
return true;
}
return false;
}
@ -107,58 +116,90 @@ public class ItemFacade extends ItemBuildCraft {
for (Object o : Block.blockRegistry) {
Block b = (Block) o;
if (!(b == Blocks.glass)) {
if (b == Blocks.bedrock
|| b == Blocks.grass
|| b == Blocks.leaves
|| b == Blocks.sponge
|| b == Blocks.chest
|| b == Blocks.redstone_lamp
|| b == Blocks.lit_redstone_lamp
|| b == Blocks.lit_pumpkin) {
continue;
}
if (!b.isOpaqueCube()
|| b.hasTileEntity(0)
|| !b.renderAsNormalBlock()
|| b.getRenderType() != 0) {
continue;
}
if (!isBlockValidForFacade(b))
{
continue;
}
Item item = Item.getItemFromBlock(b);
if (item != null) {
ItemStack base = new ItemStack(item, 1);
if (item == null) {
continue;
}
if (base.getHasSubtypes()) {
Set<String> names = Sets.newHashSet();
if (isBlockBlacklisted(b))
{
continue;
}
for (int meta = 0; meta <= 15; meta++) {
try {
ItemStack is = new ItemStack(item, 1, meta);
registerValidFacades(b, item);
}
}
if (!Strings.isNullOrEmpty(is.getUnlocalizedName())
&& names.add(is.getUnlocalizedName())) {
private static void registerValidFacades(Block block, Item item)
{
Set<String> names = Sets.newHashSet();
ItemFacade.addFacade(is);
}
} catch (Throwable t) {
t.printStackTrace();
for(int i=0; i <= 15; i++) {
try {
ItemStack stack = new ItemStack(item, 1, i);
if(!Strings.isNullOrEmpty(stack.getUnlocalizedName())
&& names.add(stack.getUnlocalizedName())) {
ItemFacade.addFacade(stack);
// prevent adding multiple facades if it's a rotatable block
if(block.getRenderType() == 31) {
break;
}
}
} else {
try {
ItemFacade.addFacade(base);
} catch (Throwable t) {
t.printStackTrace();
}
}
} catch(Throwable t) {
System.out.println("Error registering facade for " + block.toString() + ", skipping.");
t.printStackTrace();
}
}
}
private static boolean isBlockBlacklisted(Block block)
{
String blockName = Block.blockRegistry.getNameForObject(block);
for (String blacklistedBlock : BuildCraftTransport.facadeBlacklist) {
if(blockName.equals(BuildCraftConfiguration.stripSurroundingQuotes(blacklistedBlock))) {
return true;
}
}
for(String blacklistedBlock : blacklistedFacades){
if(blockName.equals(blacklistedBlock)){
return true;
}
}
return false;
}
private static boolean isBlockValidForFacade(Block block)
{
if(block.getRenderType() != 0 && block.getRenderType() != 31)
{
System.out.println(block.toString() + " has a render type of " + block.getRenderType() + ", not supported. Skipping.");
return false;
}
if(!block.renderAsNormalBlock()) {
if((block != Blocks.glass && block != Blocks.stained_glass)) {
return false;
}
}
if(block instanceof BlockSpring || block instanceof BlockGenericPipe)
{
return false;
}
return true;
}
public static int getMetaData(ItemStack stack) {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("meta")) {
return stack.getTagCompound().getInteger("meta");
@ -168,11 +209,23 @@ public class ItemFacade extends ItemBuildCraft {
}
public static Block getBlock(ItemStack stack) {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("id")) {
return (Block) Block.blockRegistry.getObjectById(stack.getTagCompound().getInteger("id"));
} else {
return (Block) Block.blockRegistry.getObjectById((stack.getItemDamage() & 0xFFF0) >>> 4);
if(!stack.hasTagCompound()) {
return null;
}
Block facadeBlock = null;
NBTTagCompound stackTagCompound = stack.getTagCompound();
// reading the 'id' tag is kept to maintain back-compat.
// The stack gets upgraded the first time this code is run.
if(stackTagCompound.hasKey("id")) {
facadeBlock = (Block)Block.blockRegistry.getObjectById(stackTagCompound.getInteger("id"));
stackTagCompound.removeTag("id");
stackTagCompound.setString("name", Block.blockRegistry.getNameForObject(facadeBlock));
} else if (stackTagCompound.hasKey("name")) {
facadeBlock = (Block) Block.blockRegistry.getObject(stackTagCompound.getString("name"));
}
return facadeBlock;
}
@Override
@ -183,26 +236,20 @@ public class ItemFacade extends ItemBuildCraft {
public static void addFacade(ItemStack itemStack) {
ItemStack facade = getStack(Block.getBlockFromItem(itemStack.getItem()), itemStack.getItemDamage());
allFacades.add(facade);
if(!allFacades.contains(facade)) {
allFacades.add(facade);
ItemStack facade6 = facade.copy();
facade6.stackSize = 6;
ItemStack facade6 = facade.copy();
facade6.stackSize = 6;
// 3 Structurepipes + this block makes 6 facades
BuildcraftRecipes.assemblyTable.addRecipe(8000, facade6, new ItemStack(BuildCraftTransport.pipeStructureCobblestone, 3), itemStack);
// 3 Structurepipes + this block makes 6 facades
BuildcraftRecipes.assemblyTable.addRecipe(8000, facade6, new ItemStack(BuildCraftTransport.pipeStructureCobblestone, 3), itemStack);
}
}
Block bl = Block.getBlockFromItem(itemStack.getItem());
// Special handling for logs
if (bl != null && bl.getRenderType() == 31) {
ItemStack rotLog1 = getStack(
Block.getBlockFromItem(itemStack.getItem()),
itemStack.getItemDamage() | 4);
ItemStack rotLog2 = getStack(
Block.getBlockFromItem(itemStack.getItem()),
itemStack.getItemDamage() | 8);
allFacades.add(rotLog1);
allFacades.add(rotLog2);
public static void blacklistFacade(String blockName) {
if(!blacklistedFacades.contains(blockName)) {
blacklistedFacades.add(blockName);
}
}
@ -213,51 +260,85 @@ public class ItemFacade extends ItemBuildCraft {
@Override
public boolean matches(InventoryCrafting inventorycrafting, World world) {
ItemStack slotmatch = null;
for (int i = 0; i < inventorycrafting.getSizeInventory(); i++) {
ItemStack slot = inventorycrafting.getStackInSlot(i);
if (slot != null && slot.getItem() == ItemFacade.this && slotmatch == null) {
slotmatch = slot;
} else if (slot != null) {
slotmatch = NO_MATCH;
}
}
if (slotmatch != null && slotmatch != NO_MATCH) {
Block block = ItemFacade.getBlock(slotmatch);
return block != null && block.getRenderType() == 31;
}
Object[] facade = getFacadeBlockFromCraftingGrid(inventorycrafting);
return false;
return facade != null && facade[0] != null;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) {
Object[] facade = getFacadeBlockFromCraftingGrid(inventorycrafting);
if(facade == null) {
return null;
}
Block block = (Block)facade[0];
ItemStack originalFacade = (ItemStack)facade[1];
if(block == null) {
return null;
}
return getNextFacadeItemStack(block, originalFacade);
}
private Object[] getFacadeBlockFromCraftingGrid(InventoryCrafting inventorycrafting) {
ItemStack slotmatch = null;
int countOfItems = 0;
for (int i = 0; i < inventorycrafting.getSizeInventory(); i++) {
ItemStack slot = inventorycrafting.getStackInSlot(i);
if (slot != null && slot.getItem() == ItemFacade.this && slotmatch == null) {
slotmatch = slot;
countOfItems++;
} else if (slot != null) {
slotmatch = NO_MATCH;
}
if(countOfItems > 1) {
return null;
}
}
if (slotmatch != null && slotmatch != NO_MATCH) {
Block block = ItemFacade.getBlock(slotmatch);
int blockMeta = ItemFacade.getMetaData(slotmatch);
if (block != null && block.getRenderType() == 31 && (blockMeta & 0xC) == 0)
return getStack(block, (blockMeta & 0x3) | 4);
// Meta | 4 = true
if (block != null && block.getRenderType() == 31 && (blockMeta & 0x8) == 0)
return getStack(block, (blockMeta & 0x3) | 8);
// Meta | 8 = true
if (block != null && block.getRenderType() == 31 && (blockMeta & 0x4) == 0)
return getStack(block, (blockMeta & 0x3));
return new Object[] { ItemFacade.getBlock(slotmatch), slotmatch };
}
return null;
}
private ItemStack getNextFacadeItemStack(Block block, ItemStack originalFacade)
{
int blockMeta = ItemFacade.getMetaData(originalFacade);
int stackMeta = 0;
switch(block.getRenderType()) {
case 1:
//supports cycling through variants (wool, planks, etc)
if(blockMeta >= 15) {
stackMeta = 0;
} else {
stackMeta = blockMeta + 1;
}
break;
case 31:
if ((blockMeta & 0xC) == 0) {
// Meta | 4 = true
stackMeta = (blockMeta & 0x3) | 4;
} else if ((blockMeta & 0x8) == 0) {
// Meta | 8 = true
stackMeta = (blockMeta & 0x3) | 8;
} else if ((blockMeta & 0x4) == 0) {
stackMeta = (blockMeta & 0x3);
}
break;
default:
stackMeta = blockMeta;
}
return getStack(block, stackMeta);
}
@Override
public int getRecipeSize() {
return 1;
@ -285,7 +366,7 @@ public class ItemFacade extends ItemBuildCraft {
ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, 0);
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("meta", metadata);
nbt.setInteger("id", Block.blockRegistry.getIDForObject(block));
nbt.setString("name", Block.blockRegistry.getNameForObject(block));
stack.setTagCompound(nbt);
return stack;
}

View file

@ -16,11 +16,10 @@ import buildcraft.transport.PipeIconProvider;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.Item;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraftforge.client.IItemRenderer;
import static net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED_FIRST_PERSON;
import org.lwjgl.opengl.GL11;
public class FacadeItemRenderer implements IItemRenderer {
@ -38,38 +37,42 @@ public class FacadeItemRenderer implements IItemRenderer {
Tessellator tessellator = Tessellator.instance;
if (block == null)
if (block == null) {
return;
}
if(block.getIcon(0, decodedMeta) == null) {
return;
}
// Render Facade
GL11.glPushMatrix();
block.setBlockBounds(0F, 0F, 1F - 1F / 16F, 1F, 1F, 1F);
render.setRenderBoundsFromBlock(block);
GL11.glTranslatef(translateX, translateY, translateZ);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1F, 0.0F);
render.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(0, decodedMeta));
render.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 0, decodedMeta));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
render.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(1, decodedMeta));
render.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 1, decodedMeta));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1F);
render.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(2, decodedMeta));
render.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 2, decodedMeta));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
render.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(3, decodedMeta));
render.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 3, decodedMeta));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1F, 0.0F, 0.0F);
render.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, block.getIcon(4, decodedMeta));
render.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 4, decodedMeta));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
render.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, block.getIcon(5, decodedMeta));
render.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, tryGetBlockIcon(block, 5, decodedMeta));
tessellator.draw();
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
GL11.glPopMatrix();
@ -111,6 +114,15 @@ public class FacadeItemRenderer implements IItemRenderer {
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
private IIcon tryGetBlockIcon( Block block, int side, int decodedMeta)
{
try {
return block.getIcon(side, decodedMeta);
} catch (Throwable t) {
return Blocks.cobblestone.getIcon(0, 0);
}
}
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
switch (type) {