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>

424
build.xml
View file

@ -1,212 +1,212 @@
<project name="Buildcraft" basedir="../" default="main">
<property environment="env" />
<!-- Properties -->
<property name="build.dir" value="build"/>
<property name="src.dir" value="BuildCraft"/>
<property name="lang.dir" value="BuildCraft-Localization"/>
<property name="download.dir" value="download"/>
<property name="files.minecraft.dir" value="jars"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/dist"/>
<property name="mcp.dir" value="${build.dir}/mcp"/>
<property name="forge.dir" value="${mcp.dir}/forge"/>
<property name="mcpsrc.dir" value="${mcp.dir}/src/minecraft"/>
<property name="mcp.version" value="72"/>
<property name="forge.version" value="4.1.4.287"/>
<property name="bc.version" value="3.1.8"/>
<available property="forge-exists" file="${download.dir}/minecraftforge-src-${forge.version}.zip"/>
<condition property="should-download-ant-contrib">
<or>
<available file="${download.dir}/ant-contrib/ant-contrib-1.0b3.jar"/>
<available file="${download.dir}/minecraftforge-src-${forge.version}.zip"/>
</or>
</condition>
<mkdir dir="${download.dir}"/>
<!-- Targets -->
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<!-- Set build number -->
<target name="initialize-version" depends="version-provided,version-not-provided">
<property name="bc.version.full" value="${bc.version}.${build.number}"/>
<echo message="Starting build for ${bc.version.full}"/>
</target>
<target name="version-not-provided" unless="env.BUILD_NUMBER">
<buildnumber/>
</target>
<target name="version-provided" if="env.BUILD_NUMBER">
<property name="build.number" value="${env.BUILD_NUMBER}"/>
</target>
<!-- Download necessary files -->
<target name="download-files" depends="download-mcp,download-forge"/>
<!-- Download ant-contrib, necessary to be able to download forge (only if neither forge zip nor ant-contrib exist) -->
<target name="download-ant-contrib" unless="should-download-ant-contrib">
<echo message="Getting: ant-contrib"/>
<mkdir dir="${download.dir}/tmp"/>
<get src="http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip/download" dest="${download.dir}/tmp/ant-contrib-1.0b3-bin.zip"/>
<get src="http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.6-bin.zip" dest="${download.dir}/tmp/commons-codec-1.6-bin.zip"/>
<unzip src="${download.dir}/tmp/ant-contrib-1.0b3-bin.zip" dest="${download.dir}"/>
<unzip src="${download.dir}/tmp/commons-codec-1.6-bin.zip" dest="${download.dir}/tmp"/>
<move todir="${download.dir}/ant-contrib/lib">
<fileset file="${download.dir}/tmp/commons-codec-1.6/commons-codec-1.6.jar"/>
</move>
<!-- Delete useless files -->
<delete dir="${download.dir}/ant-contrib/docs"/>
<delete dir="${download.dir}/tmp"/>
</target>
<!-- Download mcp -->
<target name="download-mcp">
<get src="http://mcp.ocean-labs.de/files/mcp${mcp.version}.zip" dest="${download.dir}" usetimestamp="True"/>
</target>
<!-- Download forge (if it doesn't exist) -->
<target name="download-forge" depends="download-ant-contrib" unless="forge-exists" >
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${download.dir}/ant-contrib/ant-contrib-1.0b3.jar"/>
<fileset dir="${download.dir}/ant-contrib/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<getMethod url="http://files.minecraftforge.net/minecraftforge-src-${forge.version}.zip"
responseDataFile="${download.dir}/minecraftforge-src-${forge.version}.zip">
<header name="User-Agent" value="Ant-${ant.version}/${ant.java.version}"/>
</getMethod>
</target>
<!-- Setup mcp and forge -->
<target name="setup" depends="initialize-version">
<!-- Unzip them -->
<unzip dest="${mcp.dir}">
<fileset dir="${download.dir}">
<include name="mcp${mcp.version}.zip"/>
</fileset>
</unzip>
<unzip dest="${mcp.dir}">
<fileset dir="${download.dir}">
<include name="minecraftforge-src-${forge.version}.zip"/>
</fileset>
</unzip>
<!-- Copy the necessary jars -->
<copy todir="${mcp.dir}/jars">
<fileset dir="${files.minecraft.dir}"/>
</copy>
<!-- Change executables' permitions -->
<chmod file="${mcp.dir}/updatemd5.sh" perm="+x"/>
<chmod file="${mcp.dir}/recompile.sh" perm="+x"/>
<chmod file="${mcp.dir}/reobfuscate.sh" perm="+x"/>
<chmod file="${forge.dir}/install.sh" perm="+x"/>
<!-- if your building on OSX these 2 should be executable -->
<chmod file="${mcp.dir}/runtime/bin/astyle-osx" perm="+x" />
<chmod file="${mcp.dir}/runtime/bin/jad-osx" perm="+x" />
<!-- Install forge -->
<exec dir="${forge.dir}" executable="cmd" osfamily="windows">
<arg line="/c install.cmd"/>
</exec>
<exec dir="${forge.dir}" executable="sh" osfamily="unix">
<arg value="install.sh" />
</exec>
<!-- Copy BC source -->
<copy todir="${mcpsrc.dir}">
<fileset dir="${src.dir}/common">
<exclude name="**/buildcraft/devel"/>
</fileset>
<filterset>
<filter token="VERSION" value="${bc.version}" />
<filter token="BUILD_NUMBER" value="${build.number}" />
</filterset>
</copy>
</target>
<target name="compile" depends="setup">
<!-- Recompile -->
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows">
<arg line="/c recompile.bat"/>
</exec>
<exec dir="${mcp.dir}" executable="sh" osfamily="unix">
<arg value="recompile.sh" />
</exec>
<!-- Reobf -->
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows">
<arg line="/c reobfuscate.bat"/>
</exec>
<exec dir="${mcp.dir}" executable="sh" osfamily="unix">
<arg value="reobfuscate.sh" />
</exec>
<!-- Copy BC classes -->
<copy todir="${classes.dir}">
<fileset dir="${mcp.dir}/reobf/minecraft"/>
</copy>
<!-- Copy resources -->
<copy todir="${classes.dir}">
<fileset dir="${src.dir}/buildcraft_resources">
<exclude name="build.xml"/>
<exclude name="build.number"/>
</fileset>
</copy>
<!-- Copy localizations -->
<copy todir="${classes.dir}">
<fileset dir="${lang.dir}">
<exclude name="README.md"/>
</fileset>
</copy>
</target>
<!-- Zip the compiled files -->
<target name="package" depends="compile">
<jar destfile="${jar.dir}/buildcraft-A-${bc.version.full}.jar" basedir="${classes.dir}"/>
</target>
<!-- Default target to run -->
<target name="main" depends="initialize-version,download-files,clean,package"/>
</project>
<project name="Buildcraft" basedir="../" default="main">
<property environment="env" />
<!-- Properties -->
<property name="build.dir" value="build"/>
<property name="src.dir" value="BuildCraft"/>
<property name="lang.dir" value="BuildCraft-Localization"/>
<property name="download.dir" value="download"/>
<property name="files.minecraft.dir" value="jars"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/dist"/>
<property name="mcp.dir" value="${build.dir}/mcp"/>
<property name="forge.dir" value="${mcp.dir}/forge"/>
<property name="mcpsrc.dir" value="${mcp.dir}/src/minecraft"/>
<property name="mcp.version" value="72"/>
<property name="forge.version" value="4.1.4.287"/>
<property name="bc.version" value="3.1.8"/>
<available property="forge-exists" file="${download.dir}/minecraftforge-src-${forge.version}.zip"/>
<condition property="should-download-ant-contrib">
<or>
<available file="${download.dir}/ant-contrib/ant-contrib-1.0b3.jar"/>
<available file="${download.dir}/minecraftforge-src-${forge.version}.zip"/>
</or>
</condition>
<mkdir dir="${download.dir}"/>
<!-- Targets -->
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<!-- Set build number -->
<target name="initialize-version" depends="version-provided,version-not-provided">
<property name="bc.version.full" value="${bc.version}.${build.number}"/>
<echo message="Starting build for ${bc.version.full}"/>
</target>
<target name="version-not-provided" unless="env.BUILD_NUMBER">
<buildnumber/>
</target>
<target name="version-provided" if="env.BUILD_NUMBER">
<property name="build.number" value="${env.BUILD_NUMBER}"/>
</target>
<!-- Download necessary files -->
<target name="download-files" depends="download-mcp,download-forge"/>
<!-- Download ant-contrib, necessary to be able to download forge (only if neither forge zip nor ant-contrib exist) -->
<target name="download-ant-contrib" unless="should-download-ant-contrib">
<echo message="Getting: ant-contrib"/>
<mkdir dir="${download.dir}/tmp"/>
<get src="http://sourceforge.net/projects/ant-contrib/files/ant-contrib/1.0b3/ant-contrib-1.0b3-bin.zip/download" dest="${download.dir}/tmp/ant-contrib-1.0b3-bin.zip"/>
<get src="http://archive.apache.org/dist/commons/codec/binaries/commons-codec-1.6-bin.zip" dest="${download.dir}/tmp/commons-codec-1.6-bin.zip"/>
<unzip src="${download.dir}/tmp/ant-contrib-1.0b3-bin.zip" dest="${download.dir}"/>
<unzip src="${download.dir}/tmp/commons-codec-1.6-bin.zip" dest="${download.dir}/tmp"/>
<move todir="${download.dir}/ant-contrib/lib">
<fileset file="${download.dir}/tmp/commons-codec-1.6/commons-codec-1.6.jar"/>
</move>
<!-- Delete useless files -->
<delete dir="${download.dir}/ant-contrib/docs"/>
<delete dir="${download.dir}/tmp"/>
</target>
<!-- Download mcp -->
<target name="download-mcp">
<get src="http://mcp.ocean-labs.de/files/mcp${mcp.version}.zip" dest="${download.dir}" usetimestamp="True"/>
</target>
<!-- Download forge (if it doesn't exist) -->
<target name="download-forge" depends="download-ant-contrib" unless="forge-exists" >
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${download.dir}/ant-contrib/ant-contrib-1.0b3.jar"/>
<fileset dir="${download.dir}/ant-contrib/lib">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
<getMethod url="http://files.minecraftforge.net/minecraftforge-src-${forge.version}.zip"
responseDataFile="${download.dir}/minecraftforge-src-${forge.version}.zip">
<header name="User-Agent" value="Ant-${ant.version}/${ant.java.version}"/>
</getMethod>
</target>
<!-- Setup mcp and forge -->
<target name="setup" depends="initialize-version">
<!-- Unzip them -->
<unzip dest="${mcp.dir}">
<fileset dir="${download.dir}">
<include name="mcp${mcp.version}.zip"/>
</fileset>
</unzip>
<unzip dest="${mcp.dir}">
<fileset dir="${download.dir}">
<include name="minecraftforge-src-${forge.version}.zip"/>
</fileset>
</unzip>
<!-- Copy the necessary jars -->
<copy todir="${mcp.dir}/jars">
<fileset dir="${files.minecraft.dir}"/>
</copy>
<!-- Change executables' permitions -->
<chmod file="${mcp.dir}/updatemd5.sh" perm="+x"/>
<chmod file="${mcp.dir}/recompile.sh" perm="+x"/>
<chmod file="${mcp.dir}/reobfuscate.sh" perm="+x"/>
<chmod file="${forge.dir}/install.sh" perm="+x"/>
<!-- if your building on OSX these 2 should be executable -->
<chmod file="${mcp.dir}/runtime/bin/astyle-osx" perm="+x" />
<chmod file="${mcp.dir}/runtime/bin/jad-osx" perm="+x" />
<!-- Install forge -->
<exec dir="${forge.dir}" executable="cmd" osfamily="windows">
<arg line="/c install.cmd"/>
</exec>
<exec dir="${forge.dir}" executable="sh" osfamily="unix">
<arg value="install.sh" />
</exec>
<!-- Copy BC source -->
<copy todir="${mcpsrc.dir}">
<fileset dir="${src.dir}/common">
<exclude name="**/buildcraft/devel"/>
</fileset>
<filterset>
<filter token="VERSION" value="${bc.version}" />
<filter token="BUILD_NUMBER" value="${build.number}" />
</filterset>
</copy>
</target>
<target name="compile" depends="setup">
<!-- Recompile -->
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows">
<arg line="/c recompile.bat"/>
</exec>
<exec dir="${mcp.dir}" executable="sh" osfamily="unix">
<arg value="recompile.sh" />
</exec>
<!-- Reobf -->
<exec dir="${mcp.dir}" executable="cmd" osfamily="windows">
<arg line="/c reobfuscate.bat"/>
</exec>
<exec dir="${mcp.dir}" executable="sh" osfamily="unix">
<arg value="reobfuscate.sh" />
</exec>
<!-- Copy BC classes -->
<copy todir="${classes.dir}">
<fileset dir="${mcp.dir}/reobf/minecraft"/>
</copy>
<!-- Copy resources -->
<copy todir="${classes.dir}">
<fileset dir="${src.dir}/buildcraft_resources">
<exclude name="build.xml"/>
<exclude name="build.number"/>
</fileset>
</copy>
<!-- Copy localizations -->
<copy todir="${classes.dir}">
<fileset dir="${lang.dir}">
<exclude name="README.md"/>
</fileset>
</copy>
</target>
<!-- Zip the compiled files -->
<target name="package" depends="compile">
<jar destfile="${jar.dir}/buildcraft-A-${bc.version.full}.jar" basedir="${classes.dir}"/>
</target>
<!-- Default target to run -->
<target name="main" depends="initialize-version,download-files,clean,package"/>
</project>

View file

@ -9,13 +9,22 @@
package buildcraft;
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.IMCCallback;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.Mod.PostInit;
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.FMLPostInitializationEvent;
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) {
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,19 +1,19 @@
package buildcraft.api.transport;
import net.minecraft.src.World;
/**
* Implement and register with the PipeManager if you want to suppress connections from wooden pipes.
*/
public interface IExtractionHandler {
/**
* Can this pipe extract items from the block located at these coordinates?
*/
boolean canExtractItems(IPipe pipe, World world, int i, int j, int k);
/**
* Can this pipe extract liquids from the block located at these coordinates?
*/
boolean canExtractLiquids(IPipe pipe, World world, int i, int j, int k);
}
package buildcraft.api.transport;
import net.minecraft.src.World;
/**
* Implement and register with the PipeManager if you want to suppress connections from wooden pipes.
*/
public interface IExtractionHandler {
/**
* Can this pipe extract items from the block located at these coordinates?
*/
boolean canExtractItems(IPipe pipe, World world, int i, int j, int k);
/**
* Can this pipe extract liquids from the block located at these coordinates?
*/
boolean canExtractLiquids(IPipe pipe, World world, int i, int j, int k);
}

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,16 @@
package buildcraft.transport;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Set;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;
@ -90,67 +94,32 @@ public class ItemFacade extends ItemBuildCraft {
@SuppressWarnings("rawtypes")
public static void initialize(){
List creativeItems = getCreativeContents();
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())));
//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)
for (Field f : Block.class.getDeclaredFields())
{
if (i instanceof ItemBlock)
{
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 {
if (! base.equals(i.getItemNameIS(comp)) && !Strings.isNullOrEmpty(i.getItemNameIS(comp)))
{
list.add(comp);
}
} catch (Exception e)
{
break;
}
}
}
list.add(rootIS);
}
if (Modifier.isStatic(f.getModifiers()) && Block.class.isAssignableFrom(f.getType()))
{
Block b;
try {
b = (Block) f.get(null);
} catch (Exception e) {
continue;
}
if (b.blockID == 7 || b.blockID == 18 || b.blockID == 19 || b.blockID == 95) continue;
if (!b.isOpaqueCube() || b.hasTileEntity(0)|| !b.renderAsNormalBlock()) continue;
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);
}
}
}
return list;
}
public static int encode(int blockId, int metaData){
@ -165,6 +134,14 @@ public class ItemFacade extends ItemBuildCraft {
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()))));
}
}