forked from progwml6/Natura
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slab Refactor, Leaf Refactor, and Everything Burns (#29)
- Loading branch information
Showing
23 changed files
with
368 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,63 @@ | ||
package mods.natura.blocks; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.client.renderer.texture.IIconRegister; | ||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.AxisAlignedBB; | ||
import net.minecraft.block.BlockWoodSlab; | ||
import net.minecraft.util.IIcon; | ||
import net.minecraft.world.IBlockAccess; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.common.util.ForgeDirection; | ||
|
||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import mods.natura.blocks.trees.Planks; | ||
import mods.natura.common.NContent; | ||
import mods.natura.common.NaturaTab; | ||
|
||
public class NSlabBase extends Block { | ||
|
||
Block modelBlock; | ||
int startingMeta; | ||
int totalSize; | ||
|
||
public NSlabBase(Material material) { | ||
super(material); | ||
this.setCreativeTab(NaturaTab.tab); | ||
} | ||
|
||
public NSlabBase(Material material, Block model, int meta, int totalSize) { | ||
super(material); | ||
this.setCreativeTab(NaturaTab.tab); | ||
this.modelBlock = model; | ||
this.startingMeta = meta; | ||
this.totalSize = totalSize; | ||
} | ||
|
||
@Override | ||
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List arraylist, | ||
Entity entity) { | ||
setBlockBoundsBasedOnState(world, x, y, z); | ||
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, arraylist, entity); | ||
} | ||
|
||
@Override | ||
public void setBlockBoundsForItemRender() { | ||
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F); | ||
} | ||
|
||
@Override | ||
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { | ||
int meta = world.getBlockMetadata(x, y, z) / 8; | ||
float minY = meta == 1 ? 0.5F : 0.0F; | ||
float maxY = meta == 1 ? 1.0F : 0.5F; | ||
setBlockBounds(0.0F, minY, 0F, 1.0F, maxY, 1.0F); | ||
import mods.natura.items.blocks.PlanksItem; | ||
|
||
public abstract class NSlabBase extends BlockWoodSlab { | ||
|
||
// metaGroup 1 is the first 8 types, metaGroup 2 is the next 8, etc. | ||
// slabs are max of 8 per group due to vanilla use of metadata, so this variable maps | ||
// wooden slabs to the overall wood metadata used elsewhere, such as for textures and flammability | ||
private final int metaGroup; | ||
|
||
public NSlabBase(boolean isDoubleSlab, int grp) { | ||
super(isDoubleSlab); | ||
this.setHardness(2.0F); | ||
this.setResistance(5.0F); | ||
this.useNeighborBrightness = true; | ||
if (!isDoubleSlab) { | ||
this.setCreativeTab(NaturaTab.tab); | ||
} | ||
metaGroup = grp; | ||
} | ||
|
||
@Override | ||
public int onBlockPlaced(World par1World, int blockX, int blockY, int blockZ, int side, float clickX, float clickY, | ||
float clickZ, int metadata) { | ||
if (side == 1) return metadata; | ||
if (side == 0 || clickY >= 0.5F) return metadata | 8; | ||
|
||
return metadata; | ||
@SideOnly(Side.CLIENT) | ||
public IIcon getIcon(int side, int meta) { | ||
return NContent.planks.getIcon(side, getWoodMeta(meta)); | ||
} | ||
|
||
@Override | ||
public boolean isOpaqueCube() { | ||
return false; | ||
public String func_150002_b(int meta) { | ||
// unlocalized name | ||
meta = getWoodMeta(meta); | ||
return "block.wood." + PlanksItem.blockType[meta] + ".slab"; | ||
} | ||
|
||
@Override | ||
public boolean renderAsNormalBlock() { | ||
return false; | ||
public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face) { | ||
int meta = getWoodMeta(world.getBlockMetadata(x, y, z)); | ||
return Planks.getPlankFlammability(this, meta); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void registerBlockIcons(IIconRegister iconRegister) {} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public IIcon getIcon(int side, int meta) { | ||
meta = meta % 8 + startingMeta; | ||
return modelBlock.getIcon(side, meta); | ||
public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) { | ||
int meta = getWoodMeta(world.getBlockMetadata(x, y, z)); | ||
return Planks.getPlankFireSpreadSpeed(this, meta); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void getSubBlocks(Item id, CreativeTabs tab, List list) { | ||
for (int iter = 0; iter < totalSize; iter++) { | ||
list.add(new ItemStack(id, 1, iter)); | ||
} | ||
} | ||
|
||
@Override | ||
public int damageDropped(int meta) { | ||
return meta % 8; | ||
private int getWoodMeta(int meta) { | ||
meta = (meta & 7) + (metaGroup - 1) * 8; | ||
if (meta < 0 || meta >= PlanksItem.blockType.length) meta = 0; | ||
return meta; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package mods.natura.blocks; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.world.World; | ||
|
||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import mods.natura.common.NContent; | ||
|
||
public class PlankSlab1 extends NSlabBase { | ||
|
||
public PlankSlab1(boolean isDoubleSlab) { | ||
super(isDoubleSlab, 1); | ||
} | ||
|
||
@Override | ||
public Item getItemDropped(int meta, Random random, int fortune) { | ||
// handles so both double and single drop the single slab version | ||
return Item.getItemFromBlock(NContent.plankSlab1); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void getSubBlocks(Item id, CreativeTabs tab, List list) { | ||
for (int iter = 0; iter < 8; iter++) { | ||
list.add(new ItemStack(id, 1, iter)); | ||
} | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public Item getItem(World worldIn, int x, int y, int z) { | ||
return Item.getItemFromBlock(NContent.plankSlab1); | ||
} | ||
|
||
@Override | ||
protected ItemStack createStackedBlock(int meta) { | ||
return new ItemStack(Item.getItemFromBlock(NContent.plankSlab1), 2, meta & 7); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package mods.natura.blocks; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
|
||
import net.minecraft.creativetab.CreativeTabs; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.world.World; | ||
|
||
import cpw.mods.fml.relauncher.Side; | ||
import cpw.mods.fml.relauncher.SideOnly; | ||
import mods.natura.common.NContent; | ||
|
||
public class PlankSlab2 extends NSlabBase { | ||
|
||
public PlankSlab2(boolean isDoubleSlab) { | ||
super(isDoubleSlab, 2); | ||
} | ||
|
||
@Override | ||
public Item getItemDropped(int meta, Random random, int fortune) { | ||
// handles so both double and single drop the single slab version | ||
return Item.getItemFromBlock(NContent.plankSlab2); | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public void getSubBlocks(Item id, CreativeTabs tab, List list) { | ||
for (int iter = 0; iter < 5; iter++) { | ||
list.add(new ItemStack(id, 1, iter)); | ||
} | ||
} | ||
|
||
@Override | ||
@SideOnly(Side.CLIENT) | ||
public Item getItem(World worldIn, int x, int y, int z) { | ||
return Item.getItemFromBlock(NContent.plankSlab2); | ||
} | ||
|
||
@Override | ||
protected ItemStack createStackedBlock(int meta) { | ||
return new ItemStack(Item.getItemFromBlock(NContent.plankSlab2), 2, meta & 7); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.