Almost finished the Power Ore

This commit is contained in:
Timo Ley 2021-04-07 16:15:02 +02:00
parent 2c6ae04a27
commit 613df94604
5 changed files with 257 additions and 1 deletions

View file

@ -15,4 +15,7 @@ public class Config {
public static int sturdyLevel;
public static float gemValue;
public static int powerOreRenderID;
}

View file

@ -1,23 +1,34 @@
package ley.modding.dartcraft.block;
import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.item.DartItems;
import ley.modding.dartcraft.util.Util;
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.item.EntityXPOrb;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import java.util.List;
import java.util.Random;
public class BlockPowerOre extends Block {
public static IIcon stoneicon;
public static IIcon nethericon;
public static IIcon powericon;
public BlockPowerOre() {
super(Material.rock);
Util.configureBlock(this, "powerore");
setHardness(3.0F);
setResistance(10.0F);
setStepSound(soundTypeStone);
setBlockTextureName(Dartcraft.MODID + ":powerore");
}
@Override
@ -30,6 +41,49 @@ public class BlockPowerOre extends Block {
return rand.nextInt(3) + 2;
}
@Override
public void registerBlockIcons(IIconRegister reg) {
powericon = reg.registerIcon(Dartcraft.MODID + ":powerore");
stoneicon = reg.registerIcon("stone");
nethericon = reg.registerIcon("netherrack");
}
@Override
public IIcon getIcon(int side, int meta) {
if (meta == 1) {
return nethericon;
}
return stoneicon;
}
@Override
public int getRenderType() {
return Config.powerOreRenderID;
}
@Override
public void dropXpOnBlockBreak(World world, int x, int y, int z, int exp)
{
exp = world.rand.nextInt(3) + 2;
if (Dartcraft.proxy.isSimulating(world))
{
while (exp > 0)
{
int amt = EntityXPOrb.getXPSplit(exp);
exp -= amt;
world.spawnEntityInWorld(new EntityXPOrb(world, x + 0.5D, y + 0.5D, z + 0.5D, amt));
}
}
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
list.add(new ItemStack(this, 1, 0));
list.add(new ItemStack(this, 1, 1));
}
@Override
protected boolean canSilkHarvest() {
return false;
}
}

View file

@ -0,0 +1,134 @@
package ley.modding.dartcraft.client.renderer.block;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
public class BlockRenderer {
protected static float W1 = 0.0625F;
protected static float W2 = 0.125F;
protected static float W3 = 0.1875F;
protected static float W4 = 0.25F;
protected static float W5 = 0.3125F;
protected static float W6 = 0.375F;
protected static float W7 = 0.4375F;
protected static float W8 = 0.5F;
protected static float W9 = 0.5625F;
protected static float W10 = 0.625F;
protected static float W11 = 0.6875F;
protected static float W12 = 0.75F;
protected static float W13 = 0.8125F;
protected static float W15 = 0.9375F;
public static void DrawFaces(RenderBlocks renderblocks, Block block, IIcon i, boolean st) {
DrawFaces(renderblocks, block, i, i, i, i, i, i, st);
}
public static void DrawFaces(RenderBlocks renderblocks, Block block, IIcon i1, IIcon i2, IIcon i3, IIcon i4, IIcon i5, IIcon i6, boolean solidtop) {
Tessellator tessellator = Tessellator.instance;
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1.0F, 0.0F);
renderblocks.renderFaceYNeg(block, 0.0D, 0.0D, 0.0D, i1);
tessellator.draw();
if (solidtop)
GL11.glDisable(3008);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
renderblocks.renderFaceYPos(block, 0.0D, 0.0D, 0.0D, i2);
tessellator.draw();
if (solidtop)
GL11.glEnable(3008);
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderblocks.renderFaceXNeg(block, 0.0D, 0.0D, 0.0D, i3);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1.0F);
renderblocks.renderFaceXPos(block, 0.0D, 0.0D, 0.0D, i4);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderblocks.renderFaceZNeg(block, 0.0D, 0.0D, 0.0D, i5);
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
renderblocks.renderFaceZPos(block, 0.0D, 0.0D, 0.0D, i6);
tessellator.draw();
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}
public static int setBrightness(IBlockAccess blockAccess, int i, int j, int k, Block block) {
Tessellator tessellator = Tessellator.instance;
int mb = block.getMixedBrightnessForBlock(blockAccess, i, j, k);
tessellator.setBrightness(mb);
float f = 1.0F;
int l = block.colorMultiplier(blockAccess, i, j, k);
float f1 = (l >> 16 & 0xFF) / 255.0F;
float f2 = (l >> 8 & 0xFF) / 255.0F;
float f3 = (l & 0xFF) / 255.0F;
if (EntityRenderer.anaglyphEnable) {
float f6 = (f1 * 30.0F + f2 * 59.0F + f3 * 11.0F) / 100.0F;
float f4 = (f1 * 30.0F + f2 * 70.0F) / 100.0F;
float f7 = (f1 * 30.0F + f3 * 70.0F) / 100.0F;
f1 = f6;
f2 = f4;
f3 = f7;
}
tessellator.setColorOpaque_F(f * f1, f * f2, f * f3);
return mb;
}
protected static void renderAllSides(IBlockAccess world, int x, int y, int z, Block block, RenderBlocks renderer, IIcon tex) {
renderAllSides(world, x, y, z, block, renderer, tex, true);
}
public static void renderAllSides(IBlockAccess world, int x, int y, int z, Block block, RenderBlocks renderer, IIcon tex, boolean allsides) {
if (allsides || block.shouldSideBeRendered(world, x + 1, y, z, 6))
renderer.renderFaceXPos(block, x, y, z, tex);
if (allsides || block.shouldSideBeRendered(world, x - 1, y, z, 6))
renderer.renderFaceXNeg(block, x, y, z, tex);
if (allsides || block.shouldSideBeRendered(world, x, y, z + 1, 6))
renderer.renderFaceZPos(block, x, y, z, tex);
if (allsides || block.shouldSideBeRendered(world, x, y, z - 1, 6))
renderer.renderFaceZNeg(block, x, y, z, tex);
if (allsides || block.shouldSideBeRendered(world, x, y + 1, z, 6))
renderer.renderFaceYPos(block, x, y, z, tex);
if (allsides || block.shouldSideBeRendered(world, x, y - 1, z, 6))
renderer.renderFaceYNeg(block, x, y, z, tex);
}
protected static void renderAllSidesInverted(IBlockAccess world, int x, int y, int z, Block block, RenderBlocks renderer, IIcon tex, boolean allsides) {
if (allsides || !block.shouldSideBeRendered(world, x - 1, y, z, 6))
renderer.renderFaceXPos(block, (x - 1), y, z, tex);
if (allsides || !block.shouldSideBeRendered(world, x + 1, y, z, 6))
renderer.renderFaceXNeg(block, (x + 1), y, z, tex);
if (allsides || !block.shouldSideBeRendered(world, x, y, z - 1, 6))
renderer.renderFaceZPos(block, x, y, (z - 1), tex);
if (allsides || !block.shouldSideBeRendered(world, x, y, z + 1, 6))
renderer.renderFaceZNeg(block, x, y, (z + 1), tex);
if (allsides || !block.shouldSideBeRendered(world, x, y - 1, z, 6))
renderer.renderFaceYPos(block, x, (y - 1), z, tex);
if (allsides || !block.shouldSideBeRendered(world, x, y + 1, z, 6))
renderer.renderFaceYNeg(block, x, (y + 1), z, tex);
}
}

View file

@ -0,0 +1,61 @@
package ley.modding.dartcraft.client.renderer.block;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.block.BlockPowerOre;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
public class PowerOreRenderer extends BlockRenderer implements ISimpleBlockRenderingHandler {
public void renderInventoryBlock(Block block, int meta, int modelID, RenderBlocks renderer) {
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
renderer.setRenderBoundsFromBlock(block);
IIcon bgIcon = null;
if (meta == 1) {
bgIcon = BlockPowerOre.nethericon;
} else {
bgIcon = BlockPowerOre.stoneicon;
}
DrawFaces(renderer, block, bgIcon, false);
GL11.glColor3f(1.0F, 1.0F, 0.0F);
DrawFaces(renderer, block, BlockPowerOre.powericon, false);
GL11.glColor3f(1.0F, 1.0F, 1.0F);
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
int brightness = setBrightness(world, x, y, z, block);
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
renderer.setRenderBoundsFromBlock(block);
renderer.renderStandardBlock(block, x, y, z);
Tessellator tessy = Tessellator.instance;
GL11.glEnable(3042);
tessy.setColorOpaque(255, 255, 0);
tessy.setBrightness(185);
renderAllSides(world, x, y, z, block, renderer, BlockPowerOre.powericon, false);
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
renderer.setRenderBoundsFromBlock(block);
GL11.glDisable(3042);
return true;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return true;
}
@Override
public int getRenderId() {
return Config.powerOreRenderID;
}
}

View file

@ -1,7 +1,9 @@
package ley.modding.dartcraft.proxy;
import cpw.mods.fml.client.registry.RenderingRegistry;
import ley.modding.dartcraft.Config;
import ley.modding.dartcraft.Dartcraft;
import ley.modding.dartcraft.client.renderer.block.PowerOreRenderer;
import ley.modding.dartcraft.client.renderer.entity.RenderColdAnimal;
import ley.modding.dartcraft.client.renderer.entity.RenderEntityBottle;
import ley.modding.dartcraft.client.renderer.item.RenderItemForceFlask;
@ -35,6 +37,8 @@ public class ClientProxy extends CommonProxy {
RenderingRegistry.registerEntityRenderingHandler(EntityColdChicken.class, new RenderColdAnimal(new ModelChicken(), 0.6f, "textures/entity/coldChicken.png"));
RenderingRegistry.registerEntityRenderingHandler(EntityColdCow.class, new RenderColdAnimal(new ModelCow(), 0.6f, "textures/entity/coldCow.png"));
RenderingRegistry.registerEntityRenderingHandler(EntityColdPig.class, new RenderColdAnimal(new ModelPig(), 0.6f, "textures/entity/coldPig.png"));
Config.powerOreRenderID = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new PowerOreRenderer());
}
}