More stuff, starting to work in a test world. Nice...

This commit is contained in:
Christian Weeks 2012-01-26 23:50:52 -05:00
parent c640fd5e63
commit 1afe4d8e61
10 changed files with 208 additions and 66 deletions

View File

@ -68,7 +68,7 @@
<property name="jarname" value="${modname}-${side}-${version}" />
<jar destfile="${basedir}/${jarname}.zip">
<fileset dir="${output}" includes="**/*.class" />
<fileset dir="${resource.dir}" />
<fileset dir="${resource.dir}" includes="**/*.png"/>
</jar>
</target>
<target name="build" depends="merge-client,merge-server,build-client,build-server" />
@ -114,8 +114,9 @@
<exec executable="${mcp.home}/reobfuscate.sh" dir="${mcp.home}" />
</target>
<target name="deploy" depends="init,build">
<move file="${deploy.dir}/${output}.zip" tofile="${deploy.dir}/${output}.zip.${timestamp}" failonerror="false" verbose="true" />
<copy file="${basedir}/${output}.zip" todir="${deploy.dir}" verbose="true" />
<target name="deploy" depends="init,build-client">
<property name="jarname" value="${modname}-client-${version}" />
<move file="${deploy.dir}/${jarname}.zip" tofile="${deploy.dir}/${jarname}.zip.${timestamp}" failonerror="false" verbose="true" />
<copy file="${basedir}/${jarname}.zip" todir="${deploy.dir}" verbose="true" />
</target>
</project>

View File

@ -3,13 +3,16 @@ package net.minecraft.src;
import java.io.File;
import cpw.mods.ironchest.BlockIronChest;
import cpw.mods.ironchest.IronChestType;
import cpw.mods.ironchest.ItemIronChest;
import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.Configuration;
import net.minecraft.src.forge.MinecraftForgeClient;
public class mod_IronChest extends BaseModMp {
public static BlockIronChest ironChestBlock;
public static boolean compatibilityMode;
@Override
public String getVersion() {
@ -18,10 +21,17 @@ public class mod_IronChest extends BaseModMp {
@Override
public void load() {
Configuration cfg=new Configuration(new File(Minecraft.getMinecraftDir(),"config/IronChest.cfg"));
File cfgFile = new File(Minecraft.getMinecraftDir(), "config/IronChest.cfg");
// If our config file exists
boolean defaultCompatibility = cfgFile.exists();
Configuration cfg = new Configuration(cfgFile);
try {
cfg.load();
ironChestBlock=new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("blockVeryLargeChest", 181).value));
// But doesn't have the compatibilityMode flag, enable compatibility
// mode
compatibilityMode = Boolean.parseBoolean(cfg.getOrCreateBooleanProperty("compatibilityMode", Configuration.GENERAL_PROPERTY,
defaultCompatibility).value);
ironChestBlock = new BlockIronChest(Integer.parseInt(cfg.getOrCreateBlockIdProperty("blockVeryLargeChest", 181).value));
} catch (Exception e) {
ModLoader.getLogger().severe("IronChest was unable to load it's configuration successfully");
e.printStackTrace(System.err);
@ -29,6 +39,12 @@ public class mod_IronChest extends BaseModMp {
} finally {
cfg.save();
}
ModLoader.RegisterBlock(ironChestBlock, ItemIronChest.class);
IronChestType.registerTileEntities();
IronChestType.registerRecipes(ironChestBlock);
MinecraftForgeClient.preloadTexture("ic2/sprites/ironchest_block_tex.png");
}
}

View File

@ -28,7 +28,7 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
@Override
public TileEntity getBlockEntity(int metadata) {
return TileEntityIronChest.makeEntity(metadata);
return IronChestType.makeEntity(metadata);
}
public int getBlockTexture(IBlockAccess worldAccess, int i, int j, int k, int l) {
@ -36,34 +36,38 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
if (te != null && te instanceof TileEntityIronChest) {
TileEntityIronChest icte=(TileEntityIronChest) te;
if (l==0 || l==1) { // Top and Bottom
return icte.getType().getTextureRow()*16;
} else if (l==getTextureFace(icte.getFacing())) { // Front
return icte.getType().getTextureRow()*16+1;
} else { // Back and Sides
} else if (l==icte.getFacing()) { // Front
return icte.getType().getTextureRow()*16+2;
} else { // Back and Sides
return icte.getType().getTextureRow()*16;
}
}
return 0;
}
public byte getTextureFace(byte facing) {
switch (facing) {
@Override
public int getBlockTextureFromSideAndMetadata(int i, int j) {
IronChestType typ=IronChestType.values()[j];
switch (i) {
case 0:
return 3;
case 1:
return 4;
return typ.getTextureRow()*16+1;
case 2:
return 2;
case 3:
return 5;
return typ.getTextureRow()*16+2;
default:
return 0;
return typ.getTextureRow()*16;
}
}
@Override
public void onBlockAdded(World world, int i, int j, int k) {
super.onBlockAdded(world, i, j, k);
world.markBlockNeedsUpdate(i, j, k);
}
@Override
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) {
super.onBlockPlacedBy(world, i, j, k, entityliving);
byte chestFacing = 0;
int facing = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;
if (facing == 0) {
@ -78,9 +82,11 @@ public class BlockIronChest extends BlockContainer implements ITextureProvider {
if (facing == 3) {
chestFacing = 4;
}
System.out.printf("Facing %d %d\n", facing,chestFacing);
TileEntity te = world.getBlockTileEntity(i, j, k);
if (te != null && te instanceof TileEntityIronChest) {
((TileEntityIronChest) te).setFacing(chestFacing);
world.markBlockNeedsUpdate(i, j, k);
}
}
}

View File

@ -0,0 +1,87 @@
package cpw.mods.ironchest;
import java.util.Arrays;
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemStack;
import net.minecraft.src.ModLoader;
import net.minecraft.src.TileEntity;
import net.minecraft.src.mod_IronChest;
public enum IronChestType {
IRON(54, "IronChest", "ironchest.png", 0, Item.ingotIron, TileEntityIronChest.class, "mmmmPmmmm"),
GOLD(81, "GoldChest", "goldchest.png", 1, Item.ingotGold, TileEntityGoldChest.class, "mmmmPmmmm");
// DIAMOND(108,"DiamondChest","diamondchest.png",2);
int size;
String friendlyName;
private String modelTexture;
private int textureRow;
private Class<? extends TileEntityIronChest> clazz;
private Item mat;
private String[] recipes;
IronChestType(int size, String friendlyName, String modelTexture, int textureRow, Item mat, Class<? extends TileEntityIronChest> clazz, String... recipes) {
this.size = size;
this.friendlyName = friendlyName;
this.modelTexture = modelTexture;
this.textureRow = textureRow;
this.clazz = clazz;
this.mat = mat;
this.recipes=recipes;
}
public String getModelTexture() {
return modelTexture;
}
public int getTextureRow() {
return textureRow;
}
public static TileEntity makeEntity(int metadata) {
//Compatibility
int chesttype=metadata;
int facing=0;
if (metadata>2) {
chesttype=metadata<<2;
facing=metadata&3;
}
try {
TileEntityIronChest te=values()[chesttype].clazz.newInstance();
if (mod_IronChest.compatibilityMode) {
te.setFacing((byte)facing);
}
return te;
} catch (InstantiationException e) {
// unpossible
e.printStackTrace();
} catch (IllegalAccessException e) {
// unpossible
e.printStackTrace();
}
return null;
}
public static void registerTileEntities() {
for (IronChestType typ : values()) {
System.out.printf("Registering %s\n",typ.friendlyName);
ModLoader.RegisterTileEntity(typ.clazz, typ.friendlyName);
}
}
public static void registerRecipes(BlockIronChest blockResult) {
ItemStack previous=new ItemStack(Block.chest);
for (IronChestType typ : values()) {
for (String recipe : typ.recipes) {
addRecipe(new ItemStack(blockResult, typ.ordinal()), recipe, 'm', typ.mat, 'P', previous, 'G', Block.glass, 'C', Block.chest);
}
previous=new ItemStack(blockResult,typ.ordinal());
}
}
private static void addRecipe(ItemStack is, Object... parts) {
System.out.printf("Recipe : %s\n",Arrays.asList(parts));
ModLoader.AddRecipe(is, parts);
}
}

View File

@ -0,0 +1,26 @@
package cpw.mods.ironchest;
import net.minecraft.src.ItemBlock;
import net.minecraft.src.ItemStack;
public class ItemIronChest extends ItemBlock {
public ItemIronChest(int id) {
super(id);
setMaxDamage(0);
setHasSubtypes(true);
}
@Override
public int getMetadata(int i) {
if (i<=IronChestType.values().length) {
return i;
} else {
return 0;
}
}
@Override
public String getItemNameIS(ItemStack itemstack) {
return IronChestType.values()[itemstack.getItemDamage()].friendlyName;
}
}

View File

@ -0,0 +1,8 @@
package cpw.mods.ironchest;
public class TileEntityGoldChest extends TileEntityIronChest {
public TileEntityGoldChest() {
super(IronChestType.GOLD);
}
}

View File

@ -8,41 +8,21 @@ import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;
public class TileEntityIronChest extends TileEntity implements IInventory {
public enum Type {
IRON(54,"IronChest","ironchest.png",0),
GOLD(81,"GoldChest","goldchest.png",1),
DIAMOND(108,"DiamondChest","diamondchest.png",2);
private int size;
private String friendlyName;
private String modelTexture;
private int textureRow;
Type(int size, String friendlyName, String modelTexture, int textureRow) {
this.size=size;
this.friendlyName=friendlyName;
this.modelTexture=modelTexture;
this.textureRow=textureRow;
}
public String getModelTexture() {
return modelTexture;
}
public int getTextureRow() {
return textureRow;
}
}
private int ticksSinceSync;
public float prevLidAngle;
public float lidAngle;
private int numUsingPlayers;
private Type type;
private IronChestType type;
public ItemStack[] chestContents;
private byte facing;
public TileEntityIronChest(Type type, byte facing) {
public TileEntityIronChest() {
this(IronChestType.IRON);
}
protected TileEntityIronChest(IronChestType type) {
super();
this.type=type;
this.facing=facing;
this.chestContents=new ItemStack[getSizeInventory()];
}
@Override
@ -58,25 +38,47 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
return type.friendlyName;
}
public Type getType() {
public IronChestType getType() {
return type;
}
@Override
public ItemStack getStackInSlot(int i) {
// TODO Auto-generated method stub
return null;
return chestContents[i];
}
@Override
public ItemStack decrStackSize(int i, int j) {
// TODO Auto-generated method stub
if (chestContents[i] != null)
{
if (chestContents[i].stackSize <= j)
{
ItemStack itemstack = chestContents[i];
chestContents[i] = null;
onInventoryChanged();
return itemstack;
}
ItemStack itemstack1 = chestContents[i].splitStack(j);
if (chestContents[i].stackSize == 0)
{
chestContents[i] = null;
}
onInventoryChanged();
return itemstack1;
}
else
{
return null;
}
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
// TODO Auto-generated method stub
chestContents[i] = itemstack;
if (itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
onInventoryChanged();
}
@Override
@ -94,6 +96,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
facing=nbttagcompound.getByte("facing");
}
@Override
@ -113,6 +116,7 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
}
nbttagcompound.setTag("Items", nbttaglist);
nbttagcompound.setByte("facing", facing);
}
@Override
@ -170,6 +174,8 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
if (i == 1)
{
numUsingPlayers = j;
} else if (i == 2) {
facing = (byte)j;
}
}
@ -185,19 +191,11 @@ public class TileEntityIronChest extends TileEntity implements IInventory {
worldObj.playNoteAt(xCoord, yCoord, zCoord, 1, numUsingPlayers);
}
protected static TileEntity makeEntity(int metadata) {
//Compatibility
int chesttype=metadata;
int facing=0;
if (metadata>2) {
chesttype=metadata<<2;
facing=metadata&3;
}
return new TileEntityIronChest(Type.values()[chesttype],(byte)facing);
}
public void setFacing(byte chestFacing) {
this.facing=chestFacing;
if (worldObj!=null) {
worldObj.playNoteAt(xCoord, yCoord, zCoord, 2, facing);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.