Skip to content

Commit

Permalink
Add mangrove roots, pink petals
Browse files Browse the repository at this point in the history
  • Loading branch information
Roadhog360 committed Nov 25, 2023
1 parent 336ae79 commit 85ed813
Show file tree
Hide file tree
Showing 20 changed files with 523 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/main/java/ganymedes01/etfuturum/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ public enum ModBlocks {
TINTED_GLASS(ConfigBlocksItems.enableAmethyst, new BlockTintedGlass()),

MUD(ConfigBlocksItems.enableMud, new BlockMud()),
MUDDY_MANGROVE_ROOTS(ConfigBlocksItems.enableMud, new BlockMuddyMangroveRoots()),
PACKED_MUD(ConfigBlocksItems.enableMud, new BlockPackedMud()),
MANGROVE_ROOTS(ConfigBlocksItems.enableMangroveBlocks, new BlockMangroveRoots()),
MUDDY_MANGROVE_ROOTS(ConfigBlocksItems.enableMangroveBlocks, new BlockMuddyMangroveRoots()),

MOSS_BLOCK(ConfigBlocksItems.enableMoss, new BlockMoss()),
MOSS_CARPET(ConfigBlocksItems.enableMoss, new BlockMossCarpet()),
Expand Down Expand Up @@ -279,6 +280,7 @@ public enum ModBlocks {
WEEPING_VINES(ConfigBlocksItems.enableCrimsonBlocks, new BlockWeepingVines()),
TWISTING_VINES(ConfigBlocksItems.enableWarpedBlocks, new BlockTwistingVines()),

PINK_PETALS(ConfigBlocksItems.enableCherryBlocks, new BlockPinkPetals()),
SAPLING(ConfigBlocksItems.enableCherryBlocks || ConfigBlocksItems.enableMangroveBlocks, new BlockModernSapling()),
LEAVES(ConfigBlocksItems.enableCherryBlocks || ConfigBlocksItems.enableMangroveBlocks, new BlockModernLeaves()),
WOOD_PLANKS(ConfigBlocksItems.woodVariants, new BlockModernWoodPlanks()),
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/ganymedes01/etfuturum/blocks/BlockMangroveRoots.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ganymedes01.etfuturum.blocks;

import ganymedes01.etfuturum.client.sound.ModSounds;
import ganymedes01.etfuturum.lib.RenderIDs;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;

public class BlockMangroveRoots extends BaseBlock {

private IIcon sideIcon;

public BlockMangroveRoots() {
super(Material.wood);
setLightOpacity(1);
setResistance(0.7F);
setHardness(0.7F);
setNames("mangrove_roots");
setBlockSound(ModSounds.soundMangroveRoots);
}

@Override
public boolean renderAsNormalBlock() {
return false;
}

@Override
public boolean isOpaqueCube() {
return false;
}

@Override
public IIcon getIcon(int side, int meta) {
if (side < 2) {
return blockIcon;
}
return sideIcon;
}

@Override
public void registerBlockIcons(IIconRegister reg) {
blockIcon = reg.registerIcon(getTextureName() + "_top");
sideIcon = reg.registerIcon(getTextureName() + "_side");
}

@Override
public int getRenderType() {
return RenderIDs.MANGROVE_ROOTS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ public void registerBlockIcons(IIconRegister p_149651_1_) {
private static final WorldGenAbstractTree cherry = new WorldGenCherryTrees(true);

public void func_149878_d(World p_149878_1_, int p_149878_2_, int p_149878_3_, int p_149878_4_, Random p_149878_5_) {
if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(p_149878_1_, p_149878_5_, p_149878_2_, p_149878_3_, p_149878_4_))
if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(p_149878_1_, p_149878_5_, p_149878_2_, p_149878_3_, p_149878_4_)) {
return;
}

int l = p_149878_1_.getBlockMetadata(p_149878_2_, p_149878_3_, p_149878_4_) & 7;
WorldGenAbstractTree tree = null;

if (ConfigBlocksItems.enableCherryBlocks) {
tree = cherry;
switch (l) {
case 1:
if (ConfigBlocksItems.enableCherryBlocks) {
tree = cherry;
}
break;
}

if (tree != null) {
Expand Down
121 changes: 121 additions & 0 deletions src/main/java/ganymedes01/etfuturum/blocks/BlockPinkPetals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package ganymedes01.etfuturum.blocks;

import ganymedes01.etfuturum.client.sound.ModSounds;
import ganymedes01.etfuturum.core.utils.Utils;
import ganymedes01.etfuturum.lib.RenderIDs;
import net.minecraft.block.IGrowable;
import net.minecraft.client.renderer.IconFlipped;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import java.util.Random;

public class BlockPinkPetals extends BaseFlower implements IGrowable {

private IIcon stemIcon;

public BlockPinkPetals() {
super();
setNames("pink_petals");
Utils.setBlockSound(this, ModSounds.soundPinkPetals);
}

@Override
public boolean isReplaceable(IBlockAccess world, int x, int y, int z) {
return false;
}

@Override
public void registerBlockIcons(IIconRegister reg) {
blockIcon = new IconFlipped(reg.registerIcon(getTextureName()), true, false);
stemIcon = reg.registerIcon(getTextureName() + "_stem");
}

@Override
public IIcon getIcon(int side, int meta) {
return side == 7 ? stemIcon : blockIcon;
}

@Override
public void onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_) {
int ordinal = MathHelper.floor_double((double) (p_149689_5_.rotationYaw / 90.0F) + 0.5D) & 3;
switch (ordinal) {
case 1:
ordinal = 8;
break;
case 2:
ordinal = 12;
break;
case 3:
ordinal = 4;
break;
}
p_149689_1_.setBlockMetadataWithNotify(p_149689_2_, p_149689_3_, p_149689_4_, ordinal, 2);
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
if (player.getHeldItem() != null && player.getHeldItem().getItem() == Item.getItemFromBlock(this)) {
int meta = world.getBlockMetadata(x, y, z);
if (meta % 4 < 3) {
world.playSound((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F, stepSound.func_150496_b(), (stepSound.getVolume() + 1.0F) / 2.0F, stepSound.getPitch() * 0.8F, false);
world.setBlockMetadataWithNotify(x, y, z, meta + 1, 3);
return true;
}
}
return false;
}

@Override
public int quantityDropped(int meta, int fortune, Random random) {
return (meta % 4) + 1;
}

@Override
public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_) {
setBlockBounds(0, 0, 0, 1, 0.1875F, 1);
}

@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World p_149633_1_, int p_149633_2_, int p_149633_3_, int p_149633_4_) {
return AxisAlignedBB.getBoundingBox(p_149633_2_, p_149633_3_, p_149633_4_, 1 + p_149633_2_, 0.1875 + p_149633_3_, 1 + p_149633_4_);
}

@Override
public String getItemIconName() {
return getTextureName();
}

@Override
public int getRenderType() {
return RenderIDs.PINK_PETALS;
}

@Override
public boolean func_149851_a(World world, int x, int y, int z, boolean p_149851_5_) {
return true;
}

@Override
public boolean func_149852_a(World world, Random random, int x, int y, int z) {
return true;
}

@Override
public void func_149853_b(World world, Random random, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
if (meta % 4 < 3) {
world.setBlockMetadataWithNotify(x, y, z, meta + 1, 3);
} else {
dropBlockAsItem(world, x, y, z, new ItemStack(getItemDropped(meta, random, 0), 1, quantityDropped(meta, 0, random)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ protected void renderInventoryModel(Block block, int meta, int modelId, RenderBl
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
//We don't need to cull the bottom (0) face because we do that in
renderer.drawCrossedSquares(block.getBlockTextureFromSide(0), x, y, z, 1.0F);
boolean prev = renderer.renderAllFaces;
renderer.renderFromInside = true;
renderStandardWorldCube(world, x, y, z, block, modelId, renderer, 0, 0, 0, 1, 1, 1);
renderer.renderFromInside = false;
renderer.renderFromInside = prev;
return renderStandardWorldCube(world, x, y, z, block, modelId, renderer, 0, 0, 0, 1, 1, 1);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ganymedes01.etfuturum.client.renderer.block;

import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;

public class BlockMangroveRootsRenderer extends BlockModelBase {
public BlockMangroveRootsRenderer(int renderID) {
super(renderID);
}

@Override
protected void renderInventoryModel(Block block, int meta, int modelId, RenderBlocks renderer, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) {
super.renderInventoryModel(block, meta, modelId, renderer, minX, minY, minZ, maxX, maxY, maxZ);
boolean prev = renderer.renderFromInside;
renderer.renderFromInside = true;
super.renderInventoryModel(block, meta, modelId, renderer, minX, minY, minZ, maxX, maxY, maxZ);
renderer.renderFromInside = prev;

renderer.setRenderBounds(0.5, 0, 0, 0.5, 1, 1);
tessellator.setNormal(0.0F, 0.0F, -1.0F);
renderer.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 2, meta));
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderer.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 3, meta));

renderer.setRenderBounds(0, 0, 0.5, 1, 1, 0.5);
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
renderer.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 4, meta));
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderer.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, renderer.getBlockIconFromSideAndMetadata(block, 5, meta));
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
if (super.renderWorldBlock(world, x, y, z, block, modelId, renderer)) {
boolean prev = renderer.renderAllFaces;
renderer.renderAllFaces = true;
drawStraightCrossedSquares(renderer, block, x, y, z);
renderer.renderAllFaces = prev;
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public BlockModelBase(int modelID) {

@Override
public void renderInventoryBlock(Block block, int meta, int modelID, RenderBlocks renderer) {
if (block.getRenderBlockPass() == 2) {
if (block.getRenderBlockPass() == 1) {
OpenGLHelper.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
OpenGLHelper.enableBlend();
}
Expand Down Expand Up @@ -82,12 +82,52 @@ public BlockModelBase set2DInventory() {
return this;
}

public void renderRawFace(RenderBlocks renderer, Block block, double x, double y, double z, double startX, double endX, double startY, double endY, double startZ, double endZ, double startU, double startV, double endU, double endV, IIcon iicon) {
this.renderRawFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon);
public void drawStraightCrossedSquares(RenderBlocks renderer, Block block, double dx, double dy, double dz) {
drawStraightCrossedSquares(renderer, block, dx, dy, dz, 0, 0, 0);
}

public void drawStraightCrossedSquares(RenderBlocks renderer, Block block, double dx, double dy, double dz, double offx, double offy, double offz) {
double minX = renderer.renderMinX;
double minY = renderer.renderMinY;
double minZ = renderer.renderMinZ;
double maxX = renderer.renderMaxX;
double maxY = renderer.renderMaxY;
double maxZ = renderer.renderMaxZ;

renderer.setRenderBounds(0.5, 0, 0, 0.5, 1, 1);
renderFaceXNeg(renderer, block, dx + offx, dy + offy, dz + offz);
renderFaceXPos(renderer, block, dx + offx, dy + offy, dz + offz);

renderer.setRenderBounds(0, 0, 0.5, 1, 1, 0.5);
renderFaceZNeg(renderer, block, dx + offx, dy + offy, dz + offz);
renderFaceZPos(renderer, block, dx + offx, dy + offy, dz + offz);

renderer.setRenderBounds(minX, minY, minZ, maxX, maxY, maxZ);
}

public void renderRawFace(RenderBlocks renderer, Block block, double x, double y, double z,
double startX, double endX, double startY, double endY, double startZ, double endZ,
double startU, double startV, double endU, double endV, IIcon iicon,
float r, float g, float b) {
renderRawFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, 0, r, g, b);
}

public void renderRawFace(RenderBlocks renderer, Block block, double x, double y, double z, double startX, double endX, double startY, double endY, double startZ, double endZ, double startU, double startV, double endU, double endV, IIcon iicon, int rotate) {
public void renderRawFace(RenderBlocks renderer, Block block, double x, double y, double z,
double startX, double endX, double startY, double endY, double startZ, double endZ,
double startU, double startV, double endU, double endV, IIcon iicon) {
renderRawFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, 0);
}

public void renderRawFace(RenderBlocks renderer, Block block, double x, double y, double z,
double startX, double endX, double startY, double endY, double startZ, double endZ,
double startU, double startV, double endU, double endV, IIcon iicon, int rotate) {
renderRawFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, rotate, 1, 1, 1);
}

public void renderRawFace(RenderBlocks renderer, Block block, double x, double y, double z,
double startX, double endX, double startY, double endY, double startZ, double endZ,
double startU, double startV, double endU, double endV, IIcon iicon, int rotate,
float r, float g, float b) {
double startUInterpolated;
double startVInterpolated;
double endUInterpolated;
Expand Down Expand Up @@ -139,27 +179,43 @@ public void renderRawFace(RenderBlocks renderer, Block block, double x, double y
}

tessellator.setBrightness(block.getMixedBrightnessForBlock(renderer.blockAccess, MathHelper.floor_double(x), MathHelper.floor_double(y), MathHelper.floor_double(z)));
tessellator.setColorOpaque_F(1, 1, 1);
tessellator.setColorOpaque_F(r, g, b);
tessellator.addVertexWithUV(x + startX, y + startY, z + startZ, startUInterpolated, startVInterpolated);
tessellator.addVertexWithUV(x + startX2, y + endY, z + startZ2, startUInterpolated2, startVInterpolated2);
tessellator.addVertexWithUV(x + endX1, y + endY, z + endZ1, endUInterpolated, endVInterpolated);
tessellator.addVertexWithUV(x + endX2, y + startY, z + endZ2, endUInterpolated2, endVInterpolated2);
}


public void renderRawDoubleSidedFace(RenderBlocks renderer, Block block, double x, double y, double z, double startX, double endX, double startY, double endY, double startZ, double endZ, double startU, double startV, double endU, double endV, IIcon iicon, int rotate) {
public void renderRawDoubleSidedFace(RenderBlocks renderer, Block block, double x, double y, double z,
double startX, double endX, double startY, double endY, double startZ, double endZ, double startU, double startV,
double endU, double endV, IIcon iicon, int rotate,
float r, float g, float b) {
if (rotate == 1) {
renderRawFace(renderer, block, x, y, z, startX, endX, endY, startY, startZ, endZ, startU, startV, endU, endV, iicon, 1);
renderRawFace(renderer, block, x, y, z, startX, endX, endY, startY, startZ, endZ, startU, startV, endU, endV, iicon, 1, r, g, b);
renderRawFace(renderer, block, x, y, z, endX, startX, endY, startY, startZ, endZ, endU, endV, startU, startV, iicon, 1);
} else if (rotate == 2) {
renderRawFace(renderer, block, x, y, z, startX, endX, endY, startY, startZ, endZ, startU, startV, endU, endV, iicon, 2);
renderRawFace(renderer, block, x, y, z, startX, endX, endY, startY, endZ, startZ, endU, endV, startU, startV, iicon, 2);
renderRawFace(renderer, block, x, y, z, startX, endX, endY, startY, startZ, endZ, startU, startV, endU, endV, iicon, 2, r, g, b);
renderRawFace(renderer, block, x, y, z, startX, endX, endY, startY, endZ, startZ, endU, endV, startU, startV, iicon, 2, r, g, b);
} else {
renderRawFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, rotate);
renderRawFace(renderer, block, x, y, z, endX, startX, startY, endY, endZ, startZ, startU, startV, endU, endV, iicon, rotate);
renderRawFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, rotate, r, g, b);
renderRawFace(renderer, block, x, y, z, endX, startX, startY, endY, endZ, startZ, startU, startV, endU, endV, iicon, rotate, r, g, b);
}
}

public void renderRawDoubleSidedFace(RenderBlocks renderer, Block block, double x, double y, double z,
double startX, double endX, double startY, double endY, double startZ, double endZ, double startU, double startV,
double endU, double endV, IIcon iicon, int rotate) {
renderRawDoubleSidedFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, rotate, 1, 1, 1);
}

public void renderRawDoubleSidedFace(RenderBlocks renderer, Block block, double x, double y, double z,
double startX, double endX, double startY, double endY, double startZ, double endZ,
double startU, double startV, double endU, double endV, IIcon iicon,
float r, float g, float b) {
renderRawDoubleSidedFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, 0, r, g, b);
}

public void renderRawDoubleSidedFace(RenderBlocks renderer, Block block, double x, double y, double z, double startX, double endX, double startY, double endY, double startZ, double endZ, double startU, double startV, double endU, double endV, IIcon iicon) {
renderRawDoubleSidedFace(renderer, block, x, y, z, startX, endX, startY, endY, startZ, endZ, startU, startV, endU, endV, iicon, 0);
}
Expand Down
Loading

0 comments on commit 85ed813

Please sign in to comment.