Item Facades now use the IMC comms system to know about custom facade

block types. Send your blocks through the API (FacadeManager) or 
the IMC system (use key "add-facade" and value "blockid@meta")
This commit is contained in:
Christian 2012-10-24 21:57:31 -04:00
parent 047120b324
commit 58c7dd3d1e
9 changed files with 1167 additions and 1120 deletions

7
.classpath Normal file
View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="common"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry combineaccessrules="false" kind="src" path="/Forge-Client"/>
<classpathentry kind="output" path="bin"/>
</classpath>

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/bin

17
.project Normal file
View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BuildCraft</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View file

@ -9,13 +9,22 @@
package buildcraft; package buildcraft;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.primitives.Ints;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.IMCCallback;
import cpw.mods.fml.common.Mod.Init; import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit; import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.PostInit; import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLInterModComms.IMCMessage;
import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkMod;
@ -402,6 +411,31 @@ public class BuildCraftTransport {
} }
} }
@IMCCallback
public void processIMCRequests(FMLInterModComms.IMCEvent event) {
Splitter splitter = Splitter.on("@").trimResults();
for (IMCMessage m : event.getMessages())
{
if ("add-facade".equals(m.key))
{
String[] array = Iterables.toArray(splitter.split(m.value), String.class);
if (array.length!=2)
{
Logger.getLogger("Buildcraft").log(Level.INFO,String.format("Received an invalid add-facade request %s from mod %s",m.value,m.sender));
continue;
}
Integer blId = Ints.tryParse(array[0]);
Integer metaId = Ints.tryParse(array[1]);
if (blId == null || metaId == null)
{
Logger.getLogger("Buildcraft").log(Level.INFO,String.format("Received an invalid add-facade request %s from mod %s",m.value,m.sender));
continue;
}
ItemFacade.addFacade(new ItemStack(blId, 0, metaId));
}
}
}
private static Item createPipe(int defaultID, Class<? extends Pipe> clas, String descr, Object ingredient1, Object ingredient2, Object ingredient3) { private static Item createPipe(int defaultID, Class<? extends Pipe> clas, String descr, Object ingredient1, Object ingredient2, Object ingredient3) {
String name = Character.toLowerCase(clas.getSimpleName().charAt(0)) + clas.getSimpleName().substring(1); String name = Character.toLowerCase(clas.getSimpleName().charAt(0)) + clas.getSimpleName().substring(1);

View file

@ -0,0 +1,11 @@
package buildcraft.api.transport;
import buildcraft.transport.ItemFacade;
import net.minecraft.src.ItemStack;
public class FacadeManager
{
public static void addFacade(ItemStack is) {
ItemFacade.addFacade(is);
}
}

View file

@ -1,12 +1,16 @@
package buildcraft.transport; package buildcraft.transport;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.Set;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.Side; import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly; import cpw.mods.fml.common.asm.SideOnly;
@ -90,67 +94,32 @@ public class ItemFacade extends ItemBuildCraft {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public static void initialize(){ public static void initialize(){
List creativeItems = getCreativeContents(); for (Field f : Block.class.getDeclaredFields())
ListIterator creativeIterator = creativeItems.listIterator();
while(creativeIterator.hasNext()){
ItemStack stack = (ItemStack) creativeIterator.next();
if (stack.getItem() instanceof ItemBlock){
ItemBlock itemBlock = (ItemBlock) stack.getItem();
int blockId = itemBlock.getBlockID();
//Block certain IDs (Bedrock, leaves, sponge, lockedchest)
if (blockId == 7 || blockId == 18 || blockId == 19 || blockId == 95) continue;
if (Block.blocksList[blockId] != null
&& Block.blocksList[blockId].isOpaqueCube()
&& Block.blocksList[blockId].getBlockName() != null
&& !Block.blocksList[blockId].hasTileEntity(0)
&& Block.blocksList[blockId].renderAsNormalBlock())
{ {
allFacades.add(new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(blockId, stack.getItemDamage()))); if (Modifier.isStatic(f.getModifiers()) && Block.class.isAssignableFrom(f.getType()))
//3 Structurepipes + this block makes 6 facades
AssemblyRecipe.assemblyRecipes.add(
new AssemblyRecipe(
new ItemStack[] {new ItemStack(BuildCraftTransport.pipeStructureCobblestone, 3), new ItemStack(blockId, 1, stack.getItemDamage())},
8000,
new ItemStack(BuildCraftTransport.facadeItem, 6, ItemFacade.encode(blockId, stack.getItemDamage()))));
}
}
}
}
private static List<ItemStack> getCreativeContents() {
List<ItemStack> list = Lists.newArrayList();
for (Item i : Item.itemsList)
{ {
if (i instanceof ItemBlock) Block b;
{
int blId = ((ItemBlock) i).getBlockID();
ItemStack rootIS = new ItemStack(blId, 0, 0);
if (i.getHasSubtypes())
{
String base = i.getItemNameIS(rootIS);
for (int j = 0; j < 16; j++)
{
int md = i.getMetadata(j);
ItemStack comp = new ItemStack(blId, 0, j);
try { try {
if (! base.equals(i.getItemNameIS(comp)) && !Strings.isNullOrEmpty(i.getItemNameIS(comp))) b = (Block) f.get(null);
{ } catch (Exception e) {
list.add(comp); continue;
} }
} catch (Exception e) if (b.blockID == 7 || b.blockID == 18 || b.blockID == 19 || b.blockID == 95) continue;
{ if (!b.isOpaqueCube() || b.hasTileEntity(0)|| !b.renderAsNormalBlock()) continue;
break; ItemStack base = new ItemStack(b,1);
if (base.getHasSubtypes()) {
Set<String> names = Sets.newHashSet();
for (int meta = 0; meta < 15; meta++) {
ItemStack is = new ItemStack(b, 1, meta);
if (!Strings.isNullOrEmpty(is.getItemName()) && names.add(is.getItemName())) {
ItemFacade.addFacade(is);
}
}
} else {
ItemFacade.addFacade(base);
} }
} }
} }
list.add(rootIS);
}
}
return list;
} }
public static int encode(int blockId, int metaData){ public static int encode(int blockId, int metaData){
@ -165,6 +134,14 @@ public class ItemFacade extends ItemBuildCraft {
return ((encoded & 0xFFF0) >>> 4); return ((encoded & 0xFFF0) >>> 4);
} }
public static void addFacade(ItemStack itemStack) {
allFacades.add(new ItemStack(BuildCraftTransport.facadeItem, 1, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage())));
//3 Structurepipes + this block makes 6 facades
AssemblyRecipe.assemblyRecipes.add(new AssemblyRecipe(
new ItemStack[] {new ItemStack(BuildCraftTransport.pipeStructureCobblestone, 3), itemStack},
8000,
new ItemStack(BuildCraftTransport.facadeItem, 6, ItemFacade.encode(itemStack.itemID, itemStack.getItemDamage()))));
}
} }