Skip to content

Commit

Permalink
Slab Refactor and Everything Burns
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruling-0 committed Jan 16, 2025
1 parent 859b5d6 commit 5a54630
Show file tree
Hide file tree
Showing 19 changed files with 289 additions and 452 deletions.
33 changes: 28 additions & 5 deletions src/main/java/mods/natura/blocks/GrassSlab.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package mods.natura.blocks;

import java.util.List;
import java.util.Random;

import mods.natura.common.NContent;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSlab;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
Expand All @@ -18,12 +22,17 @@
import mods.natura.client.GrassColorizerAlternate;
import mods.natura.common.NaturaTab;

public class GrassSlab extends NSlabBase {
public class GrassSlab extends BlockSlab {

public GrassSlab() {
super(Material.ground);
setHardness(0.6F);
this.setCreativeTab(NaturaTab.tab);
public static final String blockType[] = { "grass", "bluegrass", "autumngrass" };

public GrassSlab(boolean isDoubleSlab) {
super(isDoubleSlab, Material.ground);
this.setHardness(0.6F);
this.setStepSound(Block.soundTypeGrass);
if (!isDoubleSlab) {
this.setCreativeTab(NaturaTab.tab);
}
}

@Override
Expand All @@ -32,12 +41,26 @@ public void registerBlockIcons(IIconRegister iconRegister) {
this.blockIcon = iconRegister.registerIcon("natura:grass_top");
}

@Override
public String func_150002_b(int meta)
{
if (meta < 0 || meta >= blockType.length) meta = 0;
return "block.soil." + blockType[meta] + ".slab";
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {
return this.blockIcon;
}

@Override
public Item getItemDropped(int meta, Random random, int fortune) {
// if double slab
if (field_150004_a) return Item.getItemFromBlock(NContent.grassSlab);
return Item.getItemFromBlock(this);
}

@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item id, CreativeTabs tab, List list) {
Expand Down
124 changes: 68 additions & 56 deletions src/main/java/mods/natura/blocks/NSlabBase.java
Original file line number Diff line number Diff line change
@@ -1,102 +1,114 @@
package mods.natura.blocks;

import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import mods.natura.common.NContent;
import net.minecraft.block.BlockWoodSlab;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mods.natura.common.NaturaTab;
import net.minecraftforge.common.util.ForgeDirection;

public class NSlabBase extends Block {
public class NSlabBase extends BlockWoodSlab {

Block modelBlock;
int startingMeta;
int totalSize;
public static String[] woodNames = new String[] { "eucalyptus", "sakura", "ghost", "redwood", "blood",
"bush", "maple", "silverbell", "purpleheart", "tiger", "willow", "darkwood", "fusewood" };
private final int group;

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;
public NSlabBase(boolean isDoubleSlab, int grp) {
super(isDoubleSlab);
this.setHardness(2.0F);
this.setResistance(5.0F);
if (!isDoubleSlab) {
this.setCreativeTab(NaturaTab.tab);
}
group = grp;
}

@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);
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta) {
return NContent.planks.getIcon(side, getWoodMeta(meta));
}

@Override
public void setBlockBoundsForItemRender() {
setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.5F, 1.0F);
public Item getItemDropped(int meta, Random random, int fortune) {
// if double slab
if (field_150004_a) {
if (this == NContent.plankSlab1Double) return Item.getItemFromBlock(NContent.plankSlab1);
else return Item.getItemFromBlock(NContent.plankSlab2);
}
else return Item.getItemFromBlock(this);
}

@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);
public String func_150002_b(int meta)
{
return "block.wood." + woodNames[getWoodMeta(meta)] + ".slab";
}

@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;
public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = getWoodMeta(world.getBlockMetadata(x, y, z));
if (metadata == 2 || metadata == 4 || metadata > 10) return 0;
return Blocks.fire.getFlammability(this);
}

@Override
public boolean isOpaqueCube() {
return false;
public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = getWoodMeta(world.getBlockMetadata(x, y, z));
if (metadata == 2 || metadata == 4 || metadata > 10) return 0;
return Blocks.fire.getEncouragement(this);
}

@Override
public boolean renderAsNormalBlock() {
return false;
public boolean isFlammable(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = getWoodMeta(world.getBlockMetadata(x, y, z));
if (metadata == 2 || metadata == 4 || metadata > 10) return false;
return getFlammability(world, x, y, z, face) > 0;
}

@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 void getSubBlocks(Item id, CreativeTabs tab, List list) {
if (group == 1) {
if (id != Item.getItemFromBlock(NContent.plankSlab1Double)) {
for (int iter = 0; iter < 8; iter++) {
list.add(new ItemStack(id, 1, iter));
}
}
}
else {
if (id != Item.getItemFromBlock(NContent.plankSlab2Double)) {
for (int iter = 0; iter < 5; iter++) {
list.add(new ItemStack(id, 1, iter));
}
}
}
}

@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));
protected ItemStack createStackedBlock(int meta)
{
if (group == 1) {
return new ItemStack(Item.getItemFromBlock(NContent.plankSlab1), 2, meta & 7);
}
else {
return new ItemStack(Item.getItemFromBlock(NContent.plankSlab2), 2, meta & 7);
}
}

@Override
public int damageDropped(int meta) {
return meta % 8;
private int getWoodMeta(int meta) {
meta = (meta & 7) + (group-1) * 8;
if (meta < 0 || meta >= woodNames.length) meta = 0;
return meta;
}
}
23 changes: 21 additions & 2 deletions src/main/java/mods/natura/blocks/overrides/AlternateBookshelf.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import net.minecraft.block.BlockBookshelf;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mods.natura.common.NContent;
import net.minecraftforge.common.util.ForgeDirection;

public class AlternateBookshelf extends BlockBookshelf {

Expand Down Expand Up @@ -41,8 +44,24 @@ public void registerBlockIcons(IIconRegister iconRegister) {
}

@Override
public int damageDropped(int meta) {
return 0;
public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 2 || metadata == 4 || metadata > 10) return 0;
return Blocks.fire.getFlammability(this);
}

@Override
public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 2 || metadata == 4 || metadata > 10) return 0;
return Blocks.fire.getEncouragement(this);
}

@Override
public boolean isFlammable(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 2 || metadata == 4 || metadata > 10) return false;
return getFlammability(world, x, y, z, face) > 0;
}

@Override
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/mods/natura/blocks/overrides/AlternateFence.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mods.natura.client.FenceRender;
import mods.natura.common.NContent;
import net.minecraftforge.common.util.ForgeDirection;

public class AlternateFence extends BlockFence {

Expand Down Expand Up @@ -43,6 +46,27 @@ public void getSubBlocks(Item item, CreativeTabs tabs, List list) {
for (int i = 0; i < NContent.woodTextureNames.length; i++) list.add(new ItemStack(item, 1, i));
}

@Override
public int getFlammability(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 2 || metadata == 4 || metadata > 10) return 0;
return Blocks.fire.getFlammability(this);
}

@Override
public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 2 || metadata == 4 || metadata > 10) return 0;
return Blocks.fire.getEncouragement(this);
}

@Override
public boolean isFlammable(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int metadata = world.getBlockMetadata(x, y, z);
if (metadata == 2 || metadata == 4 || metadata > 10) return false;
return getFlammability(world, x, y, z, face) > 0;
}

@Override
public boolean canPlaceTorchOnTop(World world, int x, int y, int z) {
return true;
Expand Down
26 changes: 4 additions & 22 deletions src/main/java/mods/natura/blocks/trees/DarkTreeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public DarkTreeBlock() {
this.setHardness(3.5F);
this.setResistance(40F);
this.setStepSound(Block.soundTypeWood);
// setBurnProperties(this.blockID, 5, 20);
this.setCreativeTab(NaturaTab.tab);
}

Expand Down Expand Up @@ -74,35 +73,25 @@ public void registerBlockIcons(IIconRegister iconRegister) {
}

@Override
public Item getItemDropped(int par1, Random par2Random, int par3) {
return Item.getItemFromBlock(this);
}

/**
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
*/
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
public void breakBlock(World worldIn, int x, int y, int z, Block blockBroken, int meta) {
byte b0 = 4;
int j1 = b0 + 1;

if (par1World.checkChunksExist(par2 - j1, par3 - j1, par4 - j1, par2 + j1, par3 + j1, par4 + j1)) {
if (worldIn.checkChunksExist(x - j1, y - j1, z - j1, x + j1, y + j1, z + j1)) {
for (int k1 = -b0; k1 <= b0; ++k1) {
for (int l1 = -b0; l1 <= b0; ++l1) {
for (int i2 = -b0; i2 <= b0; ++i2) {
Block j2 = par1World.getBlock(par2 + k1, par3 + l1, par4 + i2);
Block j2 = worldIn.getBlock(x + k1, y + l1, z + i2);

if (j2 != null) {
j2.beginLeavesDecay(par1World, par2 + k1, par3 + l1, par4 + i2);
j2.beginLeavesDecay(worldIn, x + k1, y + l1, z + i2);
}
}
}
}
}
}

/**
* Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY, hitZ, block metadata
*/
@Override
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7,
float par8, int par9) {
Expand All @@ -126,9 +115,6 @@ public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5
return j1 | b0;
}

/**
* Determines the damage on the item the block drops. Used in cloth and wood.
*/
@Override
public int damageDropped(int par1) {
return par1 & 3;
Expand All @@ -146,10 +132,6 @@ protected ItemStack createStackedBlock(int par1) {
return new ItemStack(this, 1, limitToValidMetadata(par1));
}

public boolean isBlockReplaceable(World world, int x, int y, int z) {
return false;
}

@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {
if (meta % 4 == 1) {
Expand Down
Loading

0 comments on commit 5a54630

Please sign in to comment.