Battlefield's mods

Battlefield's API

This is the place where all the syntaxes and information about BAPI can be get.

Table of content




Installation

1. Download and install forge sources into your MCP installation directory.

2. Extract BAPI folder into your MCP installation directory.

3. Go inside BAPI folder and run install.cmd/.sh(depending on your system).




Before starting you have to import this

import net.minecraft.src.BAPI.*;

It's allso recommended to put in your calls into constructor instead of putting them into public void load()(they have to be put into constructor in SMP)




Creative

Syntax

Full mod-test file that you can use as a template

package net.minecraft.src;
						
public class mod_test extends BaseMod {
	public String getVersion() {
		return "BAPI V1.4.0 test";
	}
	
	
	public void load(){
	
	}
	
	public mod_test() {
		ModLoader.RegisterBlock(lolblock);

		BAPI.registerCreativeHandler(new CreativeTest());
									
		ModLoader.AddName(lolblock, "Lol Block");
		ModLoader.AddName(lolitem, "Lol Item");
	}
								
	public static final Block lolblock = (new BlockDirt(135, 1).setBlockName("lolblock").setHardness(0F).setLightValue(1F));
	public static final Item lolitem = (new SubItem(200).setItemName("lolitem"));

}

PlaceableHandlerTest class

package net.minecraft.src;

import net.minecraft.src.BAPI.interfaces.*;

public class CreativeTest implements ICreativeHandler{

	public void addCreativeItems(ArrayList itemList) {
		itemList.add(new ItemStack(mod_test.lolblock, 1));
		itemList.add(new ItemStack(mod_test.lolitem, 1));
	}

}





Placeable

Syntax

Full mod-test file that you can use as a template

package net.minecraft.src;
						
public class mod_test extends BaseMod {
	public String getVersion() {
		return "BAPI V1.4.0 test";
	}
	
	public void load(){
		ModLoader.RegisterBlock(testFence);
		ModLoader.RegisterBlock(customdirt);
		
		ModLoader.AddName(testFence, "Lol Fence");
		ModLoader.AddName(customdirt, "Lol Dirt");
	}
	
	public mod_test() {
		BAPI.registerPlacableHandler(new PlaceableHandlerTest());
	}
								
	public static final Block customdirt = new CustomDirt(144,3).setBlockName("CDirt");
	public static final Block testFence = (new BlockFence(135, 1, Material.rock).setBlockName("lolblock").setHardness(0F).setLightValue(1F));

}

PlaceableHandlerTest class

package net.minecraft.src;

import net.minecraft.src.BAPI.interfaces.*;

public class PlaceableHandlerTest implements IPlaceable{

	public boolean canPlantFlower(int flowerID, int plantableID, int plantableMeta) {
		if(flowerID == Block.deadBush.blockID)
		{
			return plantableID == mod_test.customdirt.blockID;
		}
		return false;
	}

	public boolean canCactusGrowOn(int plantableID, int plantableMeta) {
		return plantableID == mod_test.customdirt.blockID;
	}

	public boolean canReedGrowOn(int plantableID, int plantableMeta) {
		return plantableID == mod_test.customdirt.blockID;
	}

	public boolean canPlaceTorchOn(int placeableID, int placeableMeta) {
		return placeableID == mod_test.testFence.blockID;
	}

}





Biome

Since 1.3.0 you need to define biomes differently and implement some stuff.




Full mod-test file that you can use as a template

package net.minecraft.src;
						
public class mod_test extends BaseMod {
	public String getVersion() {
		return "BAPI V1.4.0 test";
	}
	
	public void load(){
		BAPI.registerBiomeHandler(testBiome);
	}
	
	public mod_test() {

	}
								
	public static final BiomeGenBase testBiome = (new BiomeGenTest(BAPI.getBiomeID()).setColor(0x8db360).setBiomeName
	("testBiome").setTemperatureRainfall(2F, 2F).setMinMaxHeight(0F, -0.1F);

}

Full biome file that you can use as a template

package net.minecraft.src;

import java.util.Random;
import net.minecraft.src.BAPI.interfaces.*;

public class BiomeGenTest extends BiomeGenBase implements IBiome
{

    protected BiomeGenTest(int i)
    {
        super(i);
        topBlock = (byte)Block.blockDiamond.blockID;
        BAPI.registerBiomeHandler(this);
    }

	public BiomeGenBase getBiome() {
		return mod_test.testBiome;
	}

	public boolean canGenerateInFlat() {
		return true;
	}
	
	public boolean canSpawnIn() {
		return true;
	}

	public boolean canGenerateVillage() {
		return true;
	}

	public boolean canGenerateStronghold() {
		return true;
	}
    
}





Version check

Usage

This is a custom class that connects to the given page and reads the text on it. All the stuff that is in the actually checks version, otherwise this class just connects to webpage reads it and returns it's content as string(BAPI version check website)

package net.minecraft.src;
						
public class mod_test extends BaseMod {
	
	private static String ver = "1.4.0";
	
	public String getVersion() {
		return "TEST V" + ver + " test";
	}
	
	
	public void load() {
		
		if(!VersionCheck.run("http://www.websiteadress.derp").equals(ver))
		{
			System.out.println("New version available");
		}
		
	}

}





NBT

Full mod-test file that you can use as a template

package net.minecraft.src;
						
public class mod_test extends BaseMod {
	public String getVersion() {
		return "BAPI V1.5.0 test";
	}
	
	public void load(){
		BAPI.registerNBT(new NBTTest());
	}
	
	public mod_test() {

	}
								
	public static int lolInt = 10;

}

Full NBT handler

package net.minecraft.src;

import net.minecraft.src.BAPI.interfaces.*;

public class NBTTest implements INBT
{

	public String nbtName()
    {
        return "TestNbt";
    }
	
	public boolean savePerPlayer()
	//this is used only on SMP if you want it to save info per player, return true otherwise it will save it for whole world.
	{
		return true;
	}

    public void writeToNBT(NBTTagCompound nbttagcompound)
    {
        nbttagcompound.setInteger("lol", mod_Test.lolInt);
    }

    public void readFromNBT(NBTTagCompound nbttagcompound)
    {
        mod_Test.lolInt = nbttagcompound.getInteger("lol");
    }
    
}



Downloads
Older versions



Do you want me to add in some extra hooks? PM me on minecraft forums(battlefield) and I'll se what I can do.