Skip to content

Commit

Permalink
Angelica/NotFine leaf render mode support (#19)
Browse files Browse the repository at this point in the history
* Simplify berry bush shouldSideBeRendered

* NLeaves Angelica/NotFine leaf render mode support
  • Loading branch information
jss2a98aj authored May 9, 2024
1 parent ed90e72 commit 4f2dcd1
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 174 deletions.
31 changes: 8 additions & 23 deletions src/main/java/mods/natura/blocks/crops/BerryBush.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public BerryBush() {

/* Berries show up at meta 12-15 */

@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
this.fastIcons = new IIcon[textureNames.length];
this.fancyIcons = new IIcon[textureNames.length];
Expand Down Expand Up @@ -185,34 +185,19 @@ public int getRenderType() {
return BerryRender.berryModel;
}

@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side) {
Block block = blockAccess.getBlock(x, y, z);
// If the block touching the side is same type of bush and not fully grown then render side.
if (block == this & blockAccess.getBlockMetadata(x, y, z) < 8) {
if (block == this && blockAccess.getBlockMetadata(x, y, z) < 8) {
return true;
// If this block is fully grown and is touching a bush (fast mode) or solid block then don't render (Would
// be way less complex if metadata was passed in)
} else if ((Blocks.leaves.isOpaqueCube() & block == this) | block.isOpaqueCube()) {
switch (side) {
case 0: // -y
return false;
case 1: // +y
if (blockAccess.getBlockMetadata(x, y - 1, z) > 7) return false;
break;
case 2: // -z
if (blockAccess.getBlockMetadata(x, y, z + 1) > 7) return false;
break;
case 3: // +z
if (blockAccess.getBlockMetadata(x, y, z - 1) > 7) return false;
break;
case 4: // -x
if (blockAccess.getBlockMetadata(x + 1, y, z) > 7) return false;
break;
case 5: // +x
if (blockAccess.getBlockMetadata(x - 1, y, z) > 7) return false;
// If this block is fully grown and is touching a bush (fast mode) or solid block then don't render side.
} else if ((Blocks.leaves.isOpaqueCube() && block == this) || block.isOpaqueCube()) {
if (side == 0) {
return false;
}
return maxY < 1f;
}
// If none of the above then render side.
return true;
Expand Down
29 changes: 7 additions & 22 deletions src/main/java/mods/natura/blocks/crops/NetherBerryBush.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,34 +182,19 @@ public int getRenderType() {
return BerryRender.berryModel;
}

@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess blockAccess, int x, int y, int z, int side) {
Block block = blockAccess.getBlock(x, y, z);
// If the block touching the side is same type of bush and not fully grown then render side.
if (block == this & blockAccess.getBlockMetadata(x, y, z) < 8) {
if (block == this && blockAccess.getBlockMetadata(x, y, z) < 8) {
return true;
// If this block is fully grown and is touching a bush (fast mode) or solid block then don't render (Would
// be way less complex if metadata was passed in)
} else if ((Blocks.leaves.isOpaqueCube() & block == this) | block.isOpaqueCube()) {
switch (side) {
case 0: // -y
return false;
case 1: // +y
if (blockAccess.getBlockMetadata(x, y - 1, z) > 7) return false;
break;
case 2: // -z
if (blockAccess.getBlockMetadata(x, y, z + 1) > 7) return false;
break;
case 3: // +z
if (blockAccess.getBlockMetadata(x, y, z - 1) > 7) return false;
break;
case 4: // -x
if (blockAccess.getBlockMetadata(x + 1, y, z) > 7) return false;
break;
case 5: // +x
if (blockAccess.getBlockMetadata(x - 1, y, z) > 7) return false;
// If this block is fully grown and is touching a bush (fast mode) or solid block then don't render side.
} else if ((Blocks.leaves.isOpaqueCube() && block == this) || block.isOpaqueCube()) {
if (side == 0) {
return false;
}
return maxY < 1f;
}
// If none of the above then render side.
return true;
Expand Down
52 changes: 17 additions & 35 deletions src/main/java/mods/natura/blocks/trees/NLeaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,11 @@

public class NLeaves extends BlockLeaves {

int[] adjacentTreeBlocks;

public NLeaves() {
super();
this.setTickRandomly(true);
this.setHardness(0.2F);
this.setLightOpacity(1);
this.setStepSound(Block.soundTypeGrass);
this.setBlockName("floraLeaves");
setBlockName("floraLeaves");
setCreativeTab(NaturaTab.tab);
// Blocks.fire.setFireInfo(this, 30, 60);
this.setCreativeTab(NaturaTab.tab);
}

@Override
Expand Down Expand Up @@ -102,14 +95,6 @@ public void removeLeaves(World world, int x, int y, int z) {
world.setBlock(x, y, z, Blocks.air, 0, 7);
}

/**
* Returns the quantity of items to drop on block destruction.
*/
@Override
public int quantityDropped(Random var1) {
return var1.nextInt(20) == 0 ? 1 : 0;
}

/**
* Returns the ID of the items to drop on destruction.
*/
Expand All @@ -132,30 +117,26 @@ public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int p
}
}

public IIcon[] fastIcons;
public IIcon[] fancyIcons;

@Override
public boolean isOpaqueCube() {
return Blocks.leaves.isOpaqueCube();
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
return (Blocks.leaves.isOpaqueCube() ? fastIcons : fancyIcons)[metadata % 4];
public IIcon getIcon(int side, int meta) {
return field_150129_M[Blocks.leaves.isOpaqueCube() ? 1 : 0][(meta % 4) % field_150129_M[0].length];
}

@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
String[] textureNames = new String[] { "redwood", "eucalyptus", "hopseed" };
this.fastIcons = new IIcon[textureNames.length];
this.fancyIcons = new IIcon[textureNames.length];

for (int i = 0; i < this.fastIcons.length; i++) {
this.fastIcons[i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fast");
this.fancyIcons[i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fancy");
final String[] textureNames = new String[] { "redwood", "eucalyptus", "hopseed" };
field_150129_M[0] = new IIcon[textureNames.length];
field_150129_M[1] = new IIcon[textureNames.length];
for (int i = 0; i < textureNames.length; ++i) {
field_150129_M[0][i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fancy");
field_150129_M[1][i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fast");
}
}

Expand All @@ -164,14 +145,16 @@ public void registerBlockIcons(IIconRegister iconRegister) {
* coordinates. Args: blockAccess, x, y, z, side
*/
@Override
public boolean shouldSideBeRendered(IBlockAccess var1, int var2, int var3, int var4, int var5) {
return this.field_150121_P ? super.shouldSideBeRendered(var1, var2, var3, var4, var5) : true;
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockAccess worldIn, int x, int y, int z, int side) {
return Blocks.leaves.shouldSideBeRendered(worldIn, x, y, z, side);
}

@SideOnly(Side.CLIENT)
/**
* returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
*/
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List) {
par3List.add(new ItemStack(par1, 1, 0));
par3List.add(new ItemStack(par1, 1, 1));
Expand All @@ -184,11 +167,10 @@ public int getDamageValue(World par1World, int par2, int par3, int par4) {

@Override
public int getLightOpacity(IBlockAccess world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z) % 4;
if (meta == 0) {
if (world.getBlockMetadata(x, y, z) % 4 == 0) {
return 255;
}
return super.getLightOpacity(world, x, y, z); // this.getLightOpacity(world, x, y, z);//lightOpacity[blockID];
return super.getLightOpacity(world, x, y, z);
}

@Override
Expand Down
50 changes: 13 additions & 37 deletions src/main/java/mods/natura/blocks/trees/NLeavesDark.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,83 +5,58 @@

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 net.minecraftforge.common.util.ForgeDirection;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mods.natura.common.NContent;
import mods.natura.common.NaturaTab;

public class NLeavesDark extends NLeaves {

public NLeavesDark() {
super();
this.setCreativeTab(NaturaTab.tab);
}

@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister) {
String[] textureNames = new String[] { "darkwood", "darkwood_flowering", "darkwood_fruit", "fusewood" };
this.fastIcons = new IIcon[textureNames.length];
this.fancyIcons = new IIcon[textureNames.length];

for (int i = 0; i < this.fastIcons.length; i++) {
this.fastIcons[i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fast");
this.fancyIcons[i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fancy");
final String[] textureNames = new String[] { "darkwood", "darkwood_flowering", "darkwood_fruit", "fusewood" };
field_150129_M[0] = new IIcon[textureNames.length];
field_150129_M[1] = new IIcon[textureNames.length];
for (int i = 0; i < textureNames.length; ++i) {
field_150129_M[0][i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fancy");
field_150129_M[1][i] = iconRegister.registerIcon("natura:" + textureNames[i] + "_leaves_fast");
}
}

@Override
public boolean isOpaqueCube() {
return Blocks.leaves.isOpaqueCube();
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int metadata) {
return (Blocks.leaves.isOpaqueCube() ? fastIcons : fancyIcons)[metadata % 4];
}

@Override
@SideOnly(Side.CLIENT)
public int getBlockColor() {
return 16777215;
}

@Override
@SideOnly(Side.CLIENT)
/**
* Returns the color this block should be rendered. Used by leaves.
*/
@Override
@SideOnly(Side.CLIENT)
public int getRenderColor(int par1) {
return 16777215;
}

@Override
@SideOnly(Side.CLIENT)
/**
* Returns a integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
* Returns an integer with hex for 0xrrggbb with this color multiplied against the blocks color. Note only called
* when first determining what to render.
*/
@Override
@SideOnly(Side.CLIENT)
public int colorMultiplier(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
return 16777215;
}

public int getFlammability(IBlockAccess world, int x, int y, int z, int metadata, ForgeDirection face) {
return 0;
}

public int getFireSpreadSpeed(World world, int x, int y, int z, int metadata, ForgeDirection face) {
return 0;
}

@Override
public Item getItemDropped(int metadata, Random random, int fortune) {
if (metadata % 4 == 2) return NContent.potashApple;
Expand Down Expand Up @@ -113,4 +88,5 @@ public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List
public int getLightOpacity(IBlockAccess world, int x, int y, int z) {
return this.getLightOpacity();
}

}
Loading

0 comments on commit 4f2dcd1

Please sign in to comment.