Skip to content

Commit

Permalink
Slab Refactor, Leaf Refactor, and Everything Burns (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruling-0 authored Jan 20, 2025
1 parent 859b5d6 commit 21965a4
Show file tree
Hide file tree
Showing 23 changed files with 368 additions and 392 deletions.
40 changes: 35 additions & 5 deletions src/main/java/mods/natura/blocks/GrassSlab.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package mods.natura.blocks;

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

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 @@ -11,19 +14,27 @@
import net.minecraft.util.MathHelper;
import net.minecraft.world.ColorizerGrass;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mods.natura.client.GrassColorizerAlternate;
import mods.natura.common.NContent;
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);
this.useNeighborBrightness = true;
if (!isDoubleSlab) {
this.setCreativeTab(NaturaTab.tab);
}
}

@Override
Expand All @@ -32,12 +43,25 @@ 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 All @@ -46,6 +70,12 @@ public void getSubBlocks(Item id, CreativeTabs tab, List list) {
}
}

@Override
@SideOnly(Side.CLIENT)
public Item getItem(World worldIn, int x, int y, int z) {
return Item.getItemFromBlock(NContent.grassSlab);
}

@Override
@SideOnly(Side.CLIENT)
public int getBlockColor() {
Expand Down
117 changes: 39 additions & 78 deletions src/main/java/mods/natura/blocks/NSlabBase.java
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;
}
}
45 changes: 45 additions & 0 deletions src/main/java/mods/natura/blocks/PlankSlab1.java
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);
}
}
45 changes: 45 additions & 0 deletions src/main/java/mods/natura/blocks/PlankSlab2.java
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);
}
}
14 changes: 12 additions & 2 deletions src/main/java/mods/natura/blocks/overrides/AlternateBookshelf.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
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 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;

public class AlternateBookshelf extends BlockBookshelf {
Expand Down Expand Up @@ -41,8 +44,15 @@ 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 meta = world.getBlockMetadata(x, y, z);
return Planks.getPlankFlammability(this, meta);
}

@Override
public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int meta = world.getBlockMetadata(x, y, z);
return Planks.getPlankFireSpreadSpeed(this, meta);
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/mods/natura/blocks/overrides/AlternateFence.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
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 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.client.FenceRender;
import mods.natura.common.NContent;

Expand Down Expand Up @@ -43,6 +46,18 @@ 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 meta = world.getBlockMetadata(x, y, z);
return Planks.getPlankFlammability(this, meta);
}

@Override
public int getFireSpreadSpeed(IBlockAccess world, int x, int y, int z, ForgeDirection face) {
int meta = world.getBlockMetadata(x, y, z);
return Planks.getPlankFireSpreadSpeed(this, meta);
}

@Override
public boolean canPlaceTorchOnTop(World world, int x, int y, int z) {
return true;
Expand Down
Loading

0 comments on commit 21965a4

Please sign in to comment.