- 1,976
- 68
- 220
Всем здравия о/
В общем, сделал я свой ISimple-блаблабла для рендера лиан по туториалу на сайте mcforge. Всё работает, вроде даже хорошо, пока дело не доходит до генерации. Тут начинается какая-то попоболь со светом и цветом - то лианы зеленеют, то темнеют, то вообще ванилла-окраску принимают, ещё и моргают в отдалении. Словом - безобразие.
Есть у кого светлые мысли, что я мог сделать не так и если да, не соизволите-ли вы ими со мною поделиться? Заранее вас благодарю.
В общем, сделал я свой ISimple-блаблабла для рендера лиан по туториалу на сайте mcforge. Всё работает, вроде даже хорошо, пока дело не доходит до генерации. Тут начинается какая-то попоболь со светом и цветом - то лианы зеленеют, то темнеют, то вообще ванилла-окраску принимают, ещё и моргают в отдалении. Словом - безобразие.
Сам блок:
Код:
import java.util.ArrayList;
import java.util.Random;
import alexsocol.osm.ModInfo;
import alexsocol.osm.OSMMain;
import alexsocol.osm.proxy.ClientProxy;
import alexsocol.osm.utils.RegistrationsList;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
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.Direction;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.IShearable;
public class GhostVines extends Block implements IShearable {
@SideOnly(Side.CLIENT)
public IIcon texture;
public GhostVines() {
super(Material.rock);
this.setTickRandomly(true);
this.setCreativeTab(OSMMain.ghostTab);
this.setBlockTextureName(ModInfo.MODID + ":GhostVines");
this.setBlockName("GhostVines");
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister ireg) {
this.texture = ireg.registerIcon(ModInfo.MODID + ":GhostVines");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int meta) {
return this.texture;
}
public void setBlockBoundsForItemRender() {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
public int getRenderType() {
return ClientProxy.ghostVinesRenderID;
}
public boolean isOpaqueCube() {
return false;
}
public boolean renderAsNormalBlock() {
return false;
}
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
float f = 0.0625F;
int l = world.getBlockMetadata(x, y, z);
float f1 = 1.0F;
float f2 = 1.0F;
float f3 = 1.0F;
float f4 = 0.0F;
float f5 = 0.0F;
float f6 = 0.0F;
boolean flag = l > 0;
if ((l & 2) != 0) {
f4 = Math.max(f4, 0.0625F);
f1 = 0.0F;
f2 = 0.0F;
f5 = 1.0F;
f3 = 0.0F;
f6 = 1.0F;
flag = true;
}
if ((l & 8) != 0) {
f1 = Math.min(f1, 0.9375F);
f4 = 1.0F;
f2 = 0.0F;
f5 = 1.0F;
f3 = 0.0F;
f6 = 1.0F;
flag = true;
}
if ((l & 4) != 0) {
f6 = Math.max(f6, 0.0625F);
f3 = 0.0F;
f1 = 0.0F;
f4 = 1.0F;
f2 = 0.0F;
f5 = 1.0F;
flag = true;
}
if ((l & 1) != 0) {
f3 = Math.min(f3, 0.9375F);
f6 = 1.0F;
f1 = 0.0F;
f4 = 1.0F;
f2 = 0.0F;
f5 = 1.0F;
flag = true;
}
if (!flag && this.func_150093_a(world.getBlock(x, y + 1, z))) {
f2 = Math.min(f2, 0.9375F);
f5 = 1.0F;
f1 = 0.0F;
f4 = 1.0F;
f3 = 0.0F;
f6 = 1.0F;
}
this.setBlockBounds(f1, f2, f3, f4, f5, f6);
}
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) {
return null;
}
public boolean canPlaceBlockOnSide(World world, int x, int y, int z, int side) {
switch (side) {
case 1:
return this.func_150093_a(world.getBlock(x, y + 1, z));
case 2:
return this.func_150093_a(world.getBlock(x, y, z + 1));
case 3:
return this.func_150093_a(world.getBlock(x, y, z - 1));
case 4:
return this.func_150093_a(world.getBlock(x + 1, y, z));
case 5:
return this.func_150093_a(world.getBlock(x - 1, y, z));
default:
return false;
}
}
private boolean func_150093_a(Block block) {
return block.renderAsNormalBlock() && block.getMaterial().blocksMovement();
}
private boolean func_150094_e(World world, int x, int y, int z) {
int l = world.getBlockMetadata(x, y, z);
int i1 = l;
if (l > 0) {
for (int j1 = 0; j1 <= 3; ++j1) {
int k1 = 1 << j1;
if ((l & k1) != 0 && !this.func_150093_a(world.getBlock(x + Direction.offsetX[j1], y, z + Direction.offsetZ[j1])) && (world.getBlock(x, y + 1, z) != this || (world.getBlockMetadata(x, y + 1, z) & k1) == 0)) {
i1 &= ~k1;
}
}
}
if (i1 == 0 && !this.func_150093_a(world.getBlock(x, y + 1, z))) {
return false;
} else {
if (i1 != l) {
world.setBlockMetadataWithNotify(x, y, z, i1, 2);
}
return true;
}
}
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
if (!world.isRemote && !this.func_150094_e(world, x, y, z)) {
this.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
world.setBlockToAir(x, y, z);
}
}
public void onBlockAdded(World world, int x, int y, int z) {
if (!world.isRemote) {
Block east = world.getBlock(x + 1, y, z);
Block west = world.getBlock(x - 1, y, z);
Block south = world.getBlock(x, y, z + 1);
Block north = world.getBlock(x, y, z - 1);
if (!this.func_150093_a(east) && !this.func_150093_a(west) && !this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 1, 3);
} else
if (!this.func_150093_a(east) && this.func_150093_a(west) && !this.func_150093_a(north) && !this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 2, 3);
} else
if (!this.func_150093_a(east) && this.func_150093_a(west) && !this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 3, 3);
} else
if (!this.func_150093_a(east) && !this.func_150093_a(west) && this.func_150093_a(north) && !this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 4, 3);
} else
if (!this.func_150093_a(east) && !this.func_150093_a(west) && this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 5, 3);
} else
if (!this.func_150093_a(east) && this.func_150093_a(west) && this.func_150093_a(north) && !this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 6, 3);
} else
if (!this.func_150093_a(east) && this.func_150093_a(west) && this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 7, 3);
} else
if (this.func_150093_a(east) && !this.func_150093_a(west) && !this.func_150093_a(north) && !this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 8, 3);
} else
if (this.func_150093_a(east) && !this.func_150093_a(west) && !this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 9, 3);
} else
if (this.func_150093_a(east) && this.func_150093_a(west) && !this.func_150093_a(north) && !this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 10, 3);
} else
if (this.func_150093_a(east) && this.func_150093_a(west) && !this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 11, 3);
} else
if (this.func_150093_a(east) && !this.func_150093_a(west) && this.func_150093_a(north) && !this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 12, 3);
} else
if (this.func_150093_a(east) && !this.func_150093_a(west) && this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 13, 3);
} else
if (this.func_150093_a(east) && this.func_150093_a(west) && this.func_150093_a(north) && !this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 14, 3);
} else
if (this.func_150093_a(east) && this.func_150093_a(west) && this.func_150093_a(north) && this.func_150093_a(south)) {
world.setBlock(x, y, z, RegistrationsList.ghostVines, 15, 3);
}
}
}
public void updateTick(World world, int x, int y, int z, Random p_149674_5_) {
if (!world.isRemote && world.rand.nextInt(4) == 0) {
byte b0 = 4;
int l = 5;
boolean flag = false;
int i1;
int j1;
int k1;
label134:
for (i1 = x - b0; i1 <= x + b0; ++i1) {
for (j1 = z - b0; j1 <= z + b0; ++j1) {
for (k1 = y - 1; k1 <= y + 1; ++k1) {
if (world.getBlock(i1, k1, j1) == this) {
--l;
if (l <= 0) {
flag = true;
break label134;
}
}
}
}
}
i1 = world.getBlockMetadata(x, y, z);
j1 = world.rand.nextInt(6);
k1 = Direction.facingToDirection[j1];
int l1;
if (j1 == 1 && y < 255 && world.isAirBlock(x, y + 1, z)) {
if (flag) {
return;
}
int j2 = world.rand.nextInt(16) & i1;
if (j2 > 0) {
for (l1 = 0; l1 <= 3; ++l1) {
if (!this.func_150093_a(world.getBlock(x + Direction.offsetX[l1],
y + 1, z + Direction.offsetZ[l1]))) {
j2 &= ~(1 << l1);
}
}
if (j2 > 0) {
world.setBlock(x, y + 1, z, this, j2, 2);
}
}
} else {
Block block;
int i2;
if (j1 >= 2 && j1 <= 5 && (i1 & 1 << k1) == 0) {
if (flag) {
return;
}
block = world.getBlock(x + Direction.offsetX[k1], y, z + Direction.offsetZ[k1]);
if (block.getMaterial() == Material.air) {
l1 = k1 + 1 & 3;
i2 = k1 + 3 & 3;
if ((i1 & 1 << l1) != 0 && this.func_150093_a(world.getBlock(x + Direction.offsetX[k1] + Direction.offsetX[l1], y, z + Direction.offsetZ[k1] + Direction.offsetZ[l1]))) {
world.setBlock(x + Direction.offsetX[k1], y, z + Direction.offsetZ[k1], this, 1 << l1, 2);
} else if ((i1 & 1 << i2) != 0 && this.func_150093_a(world.getBlock(x + Direction.offsetX[k1] + Direction.offsetX[i2], y, z + Direction.offsetZ[k1] + Direction.offsetZ[i2]))) {
world.setBlock(x + Direction.offsetX[k1], y, z + Direction.offsetZ[k1], this, 1 << i2, 2);
} else if ((i1 & 1 << l1) != 0 && world.isAirBlock(x + Direction.offsetX[k1] + Direction.offsetX[l1], y, z + Direction.offsetZ[k1] + Direction.offsetZ[l1]) && this.func_150093_a(world.getBlock(x + Direction.offsetX[l1], y, z + Direction.offsetZ[l1]))) {
world.setBlock(x + Direction.offsetX[k1] + Direction.offsetX[l1], y, z + Direction.offsetZ[k1] + Direction.offsetZ[l1], this, 1 << (k1 + 2 & 3), 2);
} else if ((i1 & 1 << i2) != 0 && world.isAirBlock(x + Direction.offsetX[k1] + Direction.offsetX[i2], y, z + Direction.offsetZ[k1] + Direction.offsetZ[i2]) && this.func_150093_a(world.getBlock(x + Direction.offsetX[i2], y, z + Direction.offsetZ[i2]))) {
world.setBlock(x + Direction.offsetX[k1] + Direction.offsetX[i2], y, z + Direction.offsetZ[k1] + Direction.offsetZ[i2], this, 1 << (k1 + 2 & 3), 2);
} else if (this.func_150093_a(world.getBlock(x + Direction.offsetX[k1], y + 1, z + Direction.offsetZ[k1]))) {
world.setBlock(x + Direction.offsetX[k1], y, z + Direction.offsetZ[k1], this, 0, 2);
}
} else if (block.getMaterial().isOpaque() && block.renderAsNormalBlock()) {
world.setBlockMetadataWithNotify(x, y, z, i1 | 1 << k1, 2);
}
} else if (y > 1) {
block = world.getBlock(x, y - 1, z);
if (block.getMaterial() == Material.air) {
l1 = world.rand.nextInt(16) & i1;
if (l1 > 0) {
world.setBlock(x, y - 1, z, this, l1, 2);
}
} else if (block == this) {
l1 = world.rand.nextInt(16) & i1;
i2 = world.getBlockMetadata(x, y - 1, z);
if (i2 != (i2 | l1)) {
world.setBlockMetadataWithNotify(x, y - 1, z, i2 | l1, 2);
}
}
}
}
}
}
public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int meta) {
byte b0 = 0;
switch (side) {
case 2:
b0 = 1;
break;
case 3:
b0 = 4;
break;
case 4:
b0 = 8;
break;
case 5:
b0 = 2;
}
return b0 != 0 ? b0 : meta;
}
public Item getItemDropped(int id, Random random, int meta) {
return null;
}
public int quantityDropped(Random random) {
return 0;
}
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
super.harvestBlock(world, player, x, y, z, meta);
}
@Override
public boolean isShearable(ItemStack item, IBlockAccess world, int x, int y, int z) {
return true;
}
@Override
public ArrayList<ItemStack> onSheared(ItemStack item, IBlockAccess world, int x, int y, int z, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
ret.add(new ItemStack(this, 1));
return ret;
}
@Override
public boolean isLadder(IBlockAccess world, int x, int y, int z, EntityLivingBase entity) {
return true;
}
}
Рендер:
Код:
import org.lwjgl.opengl.GL11;
import alexsocol.osm.blocks.GhostVines;
import alexsocol.osm.proxy.ClientProxy;
import alexsocol.osm.utils.RegistrationsList;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
public class GhostVinesISBRH implements ISimpleBlockRenderingHandler {
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) { }
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
Tessellator tessellator = Tessellator.instance;
IIcon c = RegistrationsList.ghostVines.getIcon(0, 0);
float u = c.getMinU();
float v = c.getMinV();
float U = c.getMaxU();
float V = c.getMaxV();
Block top = world.getBlock(x, y + 1, z);
int meta = world.getBlockMetadata(x, y, z);
tessellator.addTranslation(x, y, z);
if (top.renderAsNormalBlock() && top.isOpaqueCube() && top != Blocks.air) {
tessellator.addVertexWithUV(0.001D, 0.999D, 0.999D, u, v);
tessellator.addVertexWithUV(0.999D, 0.999D, 0.999D, u, V);
tessellator.addVertexWithUV(0.999D, 0.999D, 0.001D, U, V);
tessellator.addVertexWithUV(0.001D, 0.999D, 0.001D, U, v);
}
if (meta == 8 || meta == 9 || meta == 10 || meta == 11 || meta == 12 || meta == 13 || meta == 14 || meta == 15) {
tessellator.addVertexWithUV(0.999D, 0.001D, 0.999D, u, V);
tessellator.addVertexWithUV(0.999D, 0.001D, 0.001D, U, V);
tessellator.addVertexWithUV(0.999D, 0.999D, 0.001D, U, v);
tessellator.addVertexWithUV(0.999D, 0.999D, 0.999D, u, v);
}
if (meta == 2 || meta == 3 || meta == 6 || meta == 7 || meta == 10 || meta == 11 || meta == 14 || meta == 15) {
tessellator.addVertexWithUV(0.001D, 0.001D, 0.001D, u, V);
tessellator.addVertexWithUV(0.001D, 0.001D, 0.999D, U, V);
tessellator.addVertexWithUV(0.001D, 0.999D, 0.999D, U, v);
tessellator.addVertexWithUV(0.001D, 0.999D, 0.001D, u, v);
}
if (meta == 1 || meta == 3 || meta == 5 || meta == 7 || meta == 9 || meta == 11 || meta == 13 || meta == 15) {
tessellator.addVertexWithUV(0.001D, 0.001D, 0.999D, u, V);
tessellator.addVertexWithUV(0.999D, 0.001D, 0.999D, U, V);
tessellator.addVertexWithUV(0.999D, 0.999D, 0.999D, U, v);
tessellator.addVertexWithUV(0.001D, 0.999D, 0.999D, u, v);
}
if (meta == 4 || meta == 5 || meta == 6 || meta == 7 || meta == 12 || meta == 13 || meta == 14 || meta == 15) {
tessellator.addVertexWithUV(0.999D, 0.001D, 0.001D, u, V);
tessellator.addVertexWithUV(0.001D, 0.001D, 0.001D, U, V);
tessellator.addVertexWithUV(0.001D, 0.999D, 0.001D, U, v);
tessellator.addVertexWithUV(0.999D, 0.999D, 0.001D, u, v);
}
tessellator.addTranslation(-x, -y, -z);
return true;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return false;
}
@Override
public int getRenderId() {
return ClientProxy.ghostVinesRenderID;
}
}