Jump to content

[1.5.2] How to make a block show the texture of the block it's touching?


Recommended Posts

Posted

  I'm trying to make a block that blends in with it's surroundings, like a Ars Magica Illusion Block or a secret Rooms Mod Camo Block.  I have absolutely no idea how to go about this.  Any help would be appreciated.

 

update:  I think it might have something to do with the getBlockTexture method in the Block class.

Posted

Hi.

 

I would suggest writing some custom rendering code for your block that looks to see what the adjacent block is and either copies its texture, or calls the rendering code for that block directly. 

 

A couple of keywords to search for:

ISimpleBlockRenderingHandler and

RenderBlocks.renderBlockByRenderType and

Block.getIcon

 

This link might help to understand how block rendering works:

 

http://greyminecraftcoder.blogspot.com.au/2013/07/block-rendering.html

 

with more detail:

 

http://greyminecraftcoder.blogspot.com.au/p/list-of-topics.html

 

Cheers  TGG

Posted

Even simpler, you could create a TileEntity when the block is placed and simply store the Icon of the block next to it. Then override getBlockTexture() and return the icon stored in the TileEntity.

 

Hint:

 

        int ID = world.getBlockId(x, y+1, z); // change this as needed, maybe x+1, y-1, etc.
        int meta = world.getBlockMetadata(x, y+1, z); // change this as needed, maybe x+1, y-1, etc.
        int side = 0; // change this as needed
        
        // Icon ico = Block.blocksList[iD].getIcon(side, meta); // Use for blocks in hand / Creative tab
        Icon ico = Block.blocksList[iD].getBlockTexture(IBlockAccess, x, y, z, side); // Use for blocks placed in world

 

Edit:

 

modified example to include getBlockTexture()

Posted

Thank you.  What I'm going to try is to create a tileEntity and make a method in the tileEntity class to find the block i want to model.  In the block class I'll make the texture of the block be the getIcon of the block I'm going to model.

Posted

another update:  I have a method to get the block i wand to model, but am not sure what to do from there.  Is there a way to get and use the texture of a whole block (getIcon uses sides)?

Posted

another update:  I have a method to get the block i wand to model, but am not sure what to do from there.  Is there a way to get and use the texture of a whole block (getIcon uses sides)?

 

getIcon() and getBlockTexture() use sides because of the multi-texture capability of blocks. You can get around this pretty simply though by incrementing the side and storing the result in an array.

 

Note: In your case you really want getBlockTexture() which is called for blocks in the world, getIcon() is called for blocks in your inventory and Creative tabs.

 

Here's some rough code:

 

Icon blockTextures[6];    // All blocks have 6 sides
int blockID = 0;  // you will need to get this by adapting my hint above

for (int side = 0; side < blockTextures.length; side++)
{
    blockTextures[side] = Block.blocksList[blockID].getBlockTexture(IBlockAccess, x, y, z, side);
}

 

Then when you override getBlockTexture() for your block you can return an array element based on the side the function is requesting.

 

If you don't want to mess with arrays, you could concievably just return the Icon from the block next to yours by using the opposite side. If the game is asking for (side=1) of your block then it would be (side=0) of the neighboring block that is touching your block so return its Icon instead.

Posted

I think I have the texture code working but when I try to place an Illusion Block I get a ClassCastException.

Code:

 

 

Main Class:

--------------------------------------------------------------------------------------------------------------------------------------------------------

package RickyRyan.mod.SmokeAndMirrors.common;

 

 

 

import RickyRyan.mod.SmokeAndMirrors.Block.BlockIllusionBlock;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.Init;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.network.NetworkMod;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

 

 

 

@Mod(modid = "SmokeAndMirrors", name = "SmokeAndMirrors", version = "pre 1.0")

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class SmokeAndMirrors {

 

 

public static Block IllusionBlock;

 

 

 

 

 

 

 

 

 

@Init

public void load(FMLInitializationEvent event) {

 

IllusionBlock = new BlockIllusionBlock(3000, Material.rock).setUnlocalizedName("IllusionBlock").setCreativeTab(CreativeTabs.tabBlock).setHardness(10.0F).setResistance(1000.0F);

 

 

GameRegistry.registerTileEntity(RickyRyan.mod.SmokeAndMirrors.TileEntity.TileEntityIllusionBlock.class, "stringID");

 

MinecraftForge.setBlockHarvestLevel(IllusionBlock, "pickaxe", 2);

 

 

GameRegistry.registerBlock(IllusionBlock);

 

 

LanguageRegistry.addName(IllusionBlock, "Illusion Block");

 

}

}

 

--------------------------------------------------------------------------------------------------------------------------------------------------------

Block (IllusionBlock):

--------------------------------------------------------------------------------------------------------------------------------------------------------

package RickyRyan.mod.SmokeAndMirrors.Block;

 

import RickyRyan.mod.SmokeAndMirrors.TileEntity.TileEntityIllusionBlock;

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.Icon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

 

public class BlockIllusionBlock extends Block {

 

public BlockIllusionBlock(int par1, Material par2Material) {

super(par1, par2Material);

setBlockBounds(0F, 0F, 0F, 1F, 1F, 1F);

}

 

public TileEntity createTileEntity(World world, int metadata)

{

  return new TileEntityIllusionBlock();

}

 

@Override

public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {

 

TileEntity tile = createTileEntity((World)par1IBlockAccess, 1);

if(tile != null) {

Icon[] IconArray = ((TileEntityIllusionBlock) tile).getTextureToModel(par2, par3, par4);

 

return IconArray[par5];

 

} else {

return null;

}

 

 

}

 

 

 

 

 

 

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)

    {

            return null;

    }

 

public boolean isOpaqueCube()

    {

        return false;

    }

 

//look into getBlockTexture in Block

 

 

 

 

 

public boolean renderAsNormalBlock()

    {

        return false;

    }

 

public int getRenderType()

    {

        return 0;

    }

 

}

--------------------------------------------------------------------------------------------------------------------------------------------------------

TileEntity:

--------------------------------------------------------------------------------------------------------------------------------------------------------

package RickyRyan.mod.SmokeAndMirrors.TileEntity;

 

import java.math.*;

import java.util.ArrayList;

 

import net.minecraft.block.Block;

import net.minecraft.client.renderer.texture.Texture;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.Icon;

 

public class TileEntityIllusionBlock extends TileEntity{

 

private int x = this.xCoord;

private int y = this.yCoord;

private int z = this.zCoord;

 

@Override

  public void writeToNBT(NBTTagCompound par1)

  {

      super.writeToNBT(par1);

      //par1.setInteger("customField", customField);

      par1.setInteger("xCord", x);

      par1.setInteger("yCord", y);

      par1.setInteger("zCord", z);

  }

 

  @Override

  public void readFromNBT(NBTTagCompound par1)

  {

      super.readFromNBT(par1);

      //this.customField = par1.getInteger("customField");

      this.x = par1.getInteger("xCord");

      this.y = par1.getInteger("yCord");

      this.z = par1.getInteger("zCord");

  }

 

 

public Icon[] getTextureToModel(int x, int y, int z) {

 

Block blockToModel = null;

Icon side1 = null;

Icon side2 = null;

Icon side3 = null;

Icon side4 = null;

Icon side5 = null;

Icon side6 = null;

 

if (!worldObj.isAirBlock((int)(x + 1), (int)(y), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x + 1), (int)(y), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 6);

 

} else if (!worldObj.isAirBlock((int)(x - 1), (int)(y), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x - 1), (int)(y), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 6);

 

}  else if (!worldObj.isAirBlock((int)(x), (int)(y + 1), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y + 1), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 6);

 

} else if (!worldObj.isAirBlock((int)(x), (int)(y - 1), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y - 1), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 6);

 

}  else if (!worldObj.isAirBlock((int)(x), (int)(y), (int)(z + 1))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y), (int)(z + 1));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 6);

 

}  else if (!worldObj.isAirBlock((int)(x), (int)(y), (int)(z - 1))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y), (int)(z - 1));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 6);

 

} else {

 

int xToCheck = x + 1;

int yToCheck = y;

int zToCheck = z + 0;

 

 

do {

xToCheck = x + 1;

yToCheck = y;

zToCheck = z + 0;

 

 

if (!worldObj.isAirBlock((int)(xToCheck), (int)(yToCheck), (int)(zToCheck))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y), (int)(z - 1));

 

blockToModel = Block.blocksList[blockId];

 

side1 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 1);

side2 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 2);

side3 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 3);

side4 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 4);

side5 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 5);

side6 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 6);

}

 

 

} while (!worldObj.isAirBlock((int)(xToCheck), (int)(yToCheck), (int)(zToCheck)));

 

 

 

 

}

 

 

Icon[] IconArray = {side1, side2, side3, side4, side5, side6};

 

return IconArray;

 

 

 

 

 

}

 

 

 

 

 

 

 

 

 

}

 

--------------------------------------------------------------------------------------------------------------------------------------------------------

Forge Error Log:

--------------------------------------------------------------------------------------------------------------------------------------------------------

 

---- Minecraft Crash Report ----

// Sorry :(

 

Time: 9/14/13 8:04 PM

Description: Unexpected error

 

java.lang.ClassCastException: net.minecraft.world.ChunkCache cannot be cast to net.minecraft.world.World

at RickyRyan.mod.SmokeAndMirrors.Block.BlockIllusionBlock.getBlockTexture(BlockIllusionBlock.java:28)

at net.minecraft.client.renderer.RenderBlocks.getBlockIcon(RenderBlocks.java:8141)

at net.minecraft.client.renderer.RenderBlocks.renderStandardBlockWithAmbientOcclusion(RenderBlocks.java:4468)

at net.minecraft.client.renderer.RenderBlocks.renderStandardBlock(RenderBlocks.java:4163)

at net.minecraft.client.renderer.RenderBlocks.renderBlockByRenderType(RenderBlocks.java:445)

at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:226)

at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1535)

at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1119)

at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:991)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:871)

at net.minecraft.client.Minecraft.run(Minecraft.java:760)

at java.lang.Thread.run(Unknown Source)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at RickyRyan.mod.SmokeAndMirrors.Block.BlockIllusionBlock.getBlockTexture(BlockIllusionBlock.java:28)

at net.minecraft.client.renderer.RenderBlocks.getBlockIcon(RenderBlocks.java:8141)

at net.minecraft.client.renderer.RenderBlocks.renderStandardBlockWithAmbientOcclusion(RenderBlocks.java:4468)

at net.minecraft.client.renderer.RenderBlocks.renderStandardBlock(RenderBlocks.java:4163)

at net.minecraft.client.renderer.RenderBlocks.renderBlockByRenderType(RenderBlocks.java:445)

at net.minecraft.client.renderer.WorldRenderer.updateRenderer(WorldRenderer.java:226)

at net.minecraft.client.renderer.RenderGlobal.updateRenderers(RenderGlobal.java:1535)

at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1119)

 

-- Affected level --

Details:

Level name: MpServer

All players: 1 total; [EntityClientPlayerMP['Player871'/166, l='MpServer', x=135.12, y=70.62, z=179.91]]

Chunk stats: MultiplayerChunkCache: 441

Level seed: 0

Level generator: ID 00 - default, ver 1. Features enabled: false

Level generator options:

Level spawn location: World: (132,64,188), Chunk: (at 4,4,12 in 8,11; contains blocks 128,0,176 to 143,255,191), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)

Level time: 552 game time, 552 day time

Level dimension: 0

Level storage version: 0x00000 - Unknown?

Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false

Forced entities: 85 total; [EntityPig['Pig'/55, l='MpServer', x=61.50, y=63.00, z=154.50], EntityPig['Pig'/54, l='MpServer', x=61.66, y=63.00, z=156.31], EntityPig['Pig'/53, l='MpServer', x=54.94, y=63.00, z=154.97], EntityPig['Pig'/52, l='MpServer', x=66.50, y=63.00, z=156.50], EntityPig['Pig'/59, l='MpServer', x=75.75, y=65.00, z=105.41], EntityPig['Pig'/58, l='MpServer', x=70.50, y=66.00, z=106.81], EntityPig['Pig'/57, l='MpServer', x=74.50, y=65.00, z=104.50], EntityCow['Cow'/63, l='MpServer', x=81.31, y=67.00, z=229.66], EntityCow['Cow'/62, l='MpServer', x=78.72, y=68.00, z=228.50], EntityCow['Cow'/61, l='MpServer', x=83.50, y=67.00, z=231.50], EntityPig['Pig'/60, l='MpServer', x=68.09, y=66.00, z=103.88], EntityCow['Cow'/68, l='MpServer', x=78.50, y=68.00, z=232.50], EntityCow['Cow'/64, l='MpServer', x=77.47, y=68.00, z=228.50], EntityCow['Cow'/65, l='MpServer', x=76.50, y=67.00, z=235.50], EntityCow['Cow'/66, l='MpServer', x=71.19, y=63.00, z=244.56], EntityCow['Cow'/67, l='MpServer', x=80.50, y=67.00, z=234.19], EntityPig['Pig'/76, l='MpServer', x=108.50, y=64.00, z=131.50], EntityPig['Pig'/73, l='MpServer', x=105.50, y=64.00, z=124.22], EntityPig['Pig'/74, l='MpServer', x=105.50, y=64.00, z=125.81], EntityPig['Pig'/75, l='MpServer', x=111.78, y=64.00, z=128.44], EntityPig['Pig'/85, l='MpServer', x=136.76, y=66.00, z=192.38], EntityPig['Pig'/84, l='MpServer', x=129.75, y=66.00, z=189.50], EntityPig['Pig'/87, l='MpServer', x=125.03, y=65.00, z=189.84], EntityPig['Pig'/86, l='MpServer', x=133.44, y=65.00, z=193.31], EntityPig['Pig'/81, l='MpServer', x=132.50, y=64.00, z=124.84], EntityPig['Pig'/80, l='MpServer', x=139.91, y=63.00, z=117.16], EntityPig['Pig'/83, l='MpServer', x=135.50, y=61.29, z=114.50], EntityPig['Pig'/82, l='MpServer', x=132.19, y=63.00, z=116.38], EntityCow['Cow'/95, l='MpServer', x=155.50, y=69.00, z=237.50], EntityCow['Cow'/94, l='MpServer', x=156.50, y=69.00, z=234.50], EntityCow['Cow'/96, l='MpServer', x=156.50, y=69.00, z=239.50], EntityCow['Cow'/97, l='MpServer', x=153.50, y=69.00, z=240.50], EntitySquid['Squid'/208, l='MpServer', x=75.16, y=61.00, z=195.03], EntitySquid['Squid'/209, l='MpServer', x=79.28, y=61.00, z=190.72], EntitySquid['Squid'/210, l='MpServer', x=90.22, y=62.00, z=198.50], EntitySquid['Squid'/211, l='MpServer', x=85.41, y=61.34, z=192.69], EntityBat['Bat'/270, l='MpServer', x=61.07, y=19.00, z=184.01], EntityBat['Bat'/268, l='MpServer', x=57.75, y=19.10, z=187.75], EntityBat['Bat'/269, l='MpServer', x=61.55, y=18.05, z=184.61], EntityBat['Bat'/333, l='MpServer', x=91.52, y=16.88, z=170.25], EntityZombie['Zombie'/403, l='MpServer', x=102.50, y=44.00, z=178.50], EntityZombie['Zombie'/404, l='MpServer', x=101.97, y=45.00, z=171.50], EntityZombie['Zombie'/405, l='MpServer', x=103.44, y=44.00, z=180.50], EntityBat['Bat'/457, l='MpServer', x=59.50, y=28.58, z=177.52], EntityItem['item.tile.sapling.oak'/4337, l='MpServer', x=87.00, y=73.13, z=122.22], EntitySpider['Spider'/565, l='MpServer', x=57.13, y=27.00, z=180.72], EntityZombie['Zombie'/515, l='MpServer', x=128.50, y=38.00, z=148.50], EntityBat['Bat'/532, l='MpServer', x=102.76, y=53.29, z=139.80], EntityCreeper['Creeper'/610, l='MpServer', x=55.50, y=21.00, z=200.50], EntityBat['Bat'/617, l='MpServer', x=73.60, y=43.17, z=170.34], EntityBat['Bat'/578, l='MpServer', x=67.48, y=25.73, z=193.82], EntitySpider['Spider'/683, l='MpServer', x=102.56, y=37.00, z=155.28], EntitySkeleton['Skeleton'/767, l='MpServer', x=94.50, y=59.00, z=160.50], EntitySkeleton['Skeleton'/755, l='MpServer', x=96.50, y=16.00, z=199.50], EntityCreeper['Creeper'/756, l='MpServer', x=99.91, y=15.00, z=200.25], EntitySkeleton['Skeleton'/715, l='MpServer', x=104.50, y=20.00, z=183.47], EntityZombie['Zombie'/714, l='MpServer', x=101.50, y=21.00, z=182.50], EntitySkeleton['Skeleton'/725, l='MpServer', x=105.50, y=29.00, z=136.50], EntitySkeleton['Skeleton'/831, l='MpServer', x=95.56, y=51.00, z=209.06], EntityZombie['Zombie'/826, l='MpServer', x=169.50, y=34.00, z=134.50], EntityZombie['Zombie'/890, l='MpServer', x=191.50, y=43.00, z=124.50], EntitySkeleton['Skeleton'/879, l='MpServer', x=131.50, y=32.00, z=99.50], EntitySpider['Spider'/850, l='MpServer', x=112.50, y=33.00, z=154.50], EntityCreeper['Creeper'/863, l='MpServer', x=59.50, y=32.00, z=201.50], EntityCreeper['Creeper'/862, l='MpServer', x=63.56, y=33.00, z=208.06], EntityCreeper['Creeper'/861, l='MpServer', x=61.31, y=32.00, z=205.06], EntitySpider['Spider'/834, l='MpServer', x=104.63, y=49.00, z=203.97], EntitySkeleton['Skeleton'/832, l='MpServer', x=106.50, y=49.00, z=203.50], EntitySkeleton['Skeleton'/833, l='MpServer', x=103.50, y=49.00, z=202.50], EntityCreeper['Creeper'/956, l='MpServer', x=150.50, y=39.00, z=200.50], EntityCreeper['Creeper'/955, l='MpServer', x=151.50, y=39.00, z=199.50], EntityZombie['Zombie'/914, l='MpServer', x=136.50, y=16.00, z=196.50], EntitySkeleton['Skeleton'/913, l='MpServer', x=141.50, y=16.00, z=194.50], EntitySkeleton['Skeleton'/1018, l='MpServer', x=99.50, y=29.00, z=128.50], EntitySkeleton['Skeleton'/1019, l='MpServer', x=98.50, y=29.00, z=130.50], EntityZombie['Zombie'/1020, l='MpServer', x=139.00, y=35.00, z=110.56], EntityClientPlayerMP['Player871'/166, l='MpServer', x=135.12, y=70.62, z=179.91], EntityZombie['Zombie'/1079, l='MpServer', x=194.50, y=51.00, z=151.50], EntityCreeper['Creeper'/9486, l='MpServer', x=113.50, y=51.00, z=200.50], EntityZombie['Zombie'/9487, l='MpServer', x=106.13, y=49.00, z=202.64], EntityItem['item.item.sulphur'/9504, l='MpServer', x=78.65, y=35.46, z=191.36], EntityCreeper['Creeper'/9548, l='MpServer', x=64.50, y=25.00, z=204.50], EntityCreeper['Creeper'/9549, l='MpServer', x=67.50, y=25.00, z=206.50], EntitySkeleton['Skeleton'/9571, l='MpServer', x=112.50, y=37.00, z=159.50], EntityItem['item.tile.sapling.oak'/7386, l='MpServer', x=79.19, y=69.13, z=144.78]]

Retry entities: 0 total; []

Stacktrace:

at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:441)

at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2414)

at net.minecraft.client.Minecraft.run(Minecraft.java:783)

at java.lang.Thread.run(Unknown Source)

 

-- System Details --

Details:

Minecraft Version: 1.5.2

Operating System: Windows 7 (x86) version 6.1

Java Version: 1.7.0_25, Oracle Corporation

Java VM Version: Java HotSpot Client VM (mixed mode), Oracle Corporation

Memory: 790166544 bytes (753 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 39218 (2196208 bytes; 2 MB) allocated, 3373 (188888 bytes; 0 MB) used

Suspicious classes: FML and Forge are installed

IntCache: cache: 0, tcache: 0, allocated: 3, tallocated: 63

FML: MCP v7.51 FML v5.2.23.737 Minecraft Forge 7.8.1.737 4 mods loaded, 4 mods active

mcp{7.51} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{5.2.23.737} [Forge Mod Loader] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{7.8.1.737} [Minecraft Forge] (coremods) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

SmokeAndMirrors{pre 1.0} [smokeAndMirrors] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

LWJGL: 2.4.2

OpenGL: Intel® HD Graphics Family GL version 3.0.0 - Build 8.15.10.2353, Intel

Is Modded: Definitely; Client brand changed to 'fml,forge'

Type: Client (map_client.txt)

Texture Pack: Default

Profiler Position: N/A (disabled)

Vec3 Pool Size: 5557 (311192 bytes; 0 MB) allocated, 1331 (74536 bytes; 0 MB) used

 

--------------------------------------------------------------------------------------------------------------------------------------------------------

[spoiler/]

Some of the code is rather messy, but I think it should work.  If you see an error please tell me. (I can give you the .java files if I have to) (the extra code is to make it so I can walk through the block)

Posted

Hi

 

A couple of comments

1) If you're using the approach with the TileEntity, you need to create the entity when you place the block, not each time it's rendered.  eg Block.createTileEntity  - see also code in BlockSign.  To be honest I think you haven't really understood what Lycanus was suggesting.  Although using TileEntities has some advantages, you might be better off forgetting about TileEntities for now.

2) I would suggest that you practice with a couple of simpler tutorials first, on custom block rendering, that should help make some of the concepts a bit clearer. Wuppy has some good ones, for example http://wuppy29.blogspot.com/2013/08/wuppys-minecraft-forge-modding_14.html

 

-TGG

 

 

 

Posted

Thank you.  Know the block is working but when I place it it just shows it's normal texture (dosn't camoflauge).  Do I need to override onBlockPlace?

Code:

 

 

Illusion Block Tile Entity:

--------------------------------------------------------------------------------------------------------------------------------------------------------package RickyRyan.mod.SmokeAndMirrors.TileEntity;

 

import java.math.*;

import java.util.ArrayList;

 

import RickyRyan.mod.SmokeAndMirrors.Block.BlockIllusionBlock;

import RickyRyan.mod.SmokeAndMirrors.Block.BlockInfo;

import RickyRyan.mod.SmokeAndMirrors.Block.Blocks;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.Texture;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.Icon;

 

public class TileEntityIllusionBlock extends TileEntity{

 

private int x = this.xCoord;

private int y = this.yCoord;

private int z = this.zCoord;

 

@Override

  public void writeToNBT(NBTTagCompound par1)

  {

      super.writeToNBT(par1);

      //par1.setInteger("customField", customField);

      par1.setInteger("xCord", x);

      par1.setInteger("yCord", y);

      par1.setInteger("zCord", z);

  }

 

  @Override

  public void readFromNBT(NBTTagCompound par1)

  {

      super.readFromNBT(par1);

      //this.customField = par1.getInteger("customField");

      this.x = par1.getInteger("xCord");

      this.y = par1.getInteger("yCord");

      this.z = par1.getInteger("zCord");

  }

 

 

public Icon[] getTextureToModel(int x, int y, int z) {

if(this.getWorldObj() != null) {

 

Block blockToModel = null;

Icon side1 = null;

Icon side2 = null;

Icon side3 = null;

Icon side4 = null;

Icon side5 = null;

Icon side6 = null;

 

if (!worldObj.isAirBlock((int)(x + 1), (int)(y), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x + 1), (int)(y), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x + 1, y, z, 6);

 

} else if (!worldObj.isAirBlock((int)(x - 1), (int)(y), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x - 1), (int)(y), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x - 1, y, z, 6);

 

}  else if (!worldObj.isAirBlock((int)(x), (int)(y + 1), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y + 1), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y + 1, z, 6);

 

} else if (!worldObj.isAirBlock((int)(x), (int)(y - 1), (int)(z))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y - 1), (int)(z));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y - 1, z, 6);

 

}  else if (!worldObj.isAirBlock((int)(x), (int)(y), (int)(z + 1))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y), (int)(z + 1));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y, z + 1, 6);

 

}  else if (!worldObj.isAirBlock((int)(x), (int)(y), (int)(z - 1))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y), (int)(z - 1));

 

blockToModel = Block.blocksList[blockId];

side1 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 1);

side2 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 2);

side3 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 3);

side4 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 4);

side5 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 5);

side6 = blockToModel.getBlockTexture(worldObj, x, y, z - 1, 6);

 

} else {

 

int xToCheck = x + 1;

int yToCheck = y;

int zToCheck = z + 0;

 

 

do {

xToCheck = x + 1;

yToCheck = y;

zToCheck = z + 0;

 

 

if (!worldObj.isAirBlock((int)(xToCheck), (int)(yToCheck), (int)(zToCheck))) {

int blockId = worldObj.getBlockId((int)(x), (int)(y), (int)(z - 1));

 

blockToModel = Block.blocksList[blockId];

 

side1 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 1);

side2 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 2);

side3 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 3);

side4 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 4);

side5 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 5);

side6 = blockToModel.getBlockTexture(worldObj, xToCheck, yToCheck, zToCheck, 6);

}

 

 

} while (!worldObj.isAirBlock((int)(xToCheck), (int)(yToCheck), (int)(zToCheck)));

 

 

 

 

}

 

 

Icon[] IconArray = {side1, side2, side3, side4, side5, side6};

 

return IconArray;

 

 

} else {

Block IllusionBlock = Blocks.IllusionBlock;

Icon[] IconArray = {IllusionBlock.getIcon(BlockInfo.IllusionBlockId, 0), IllusionBlock.getIcon(BlockInfo.IllusionBlockId, 0), IllusionBlock.getIcon(BlockInfo.IllusionBlockId, 0), IllusionBlock.getIcon(BlockInfo.IllusionBlockId, 0), IllusionBlock.getIcon(BlockInfo.IllusionBlockId, 0), IllusionBlock.getIcon(BlockInfo.IllusionBlockId, 0)};

return IconArray;

}

 

 

}

 

 

 

 

 

 

 

 

 

}

 

--------------------------------------------------------------------------------------------------------------------------------------------------------

Illusion Block:

--------------------------------------------------------------------------------------------------------------------------------------------------------

package RickyRyan.mod.SmokeAndMirrors.Block;

 

import RickyRyan.mod.SmokeAndMirrors.TileEntity.TileEntityIllusionBlock;

import net.minecraft.block.Block;

import net.minecraft.block.BlockContainer;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.Icon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

 

public class BlockIllusionBlock extends BlockContainer {

 

public BlockIllusionBlock(int par1, Material par2Material) {

super(par1, par2Material);

setBlockBounds(0F, 0F, 0F, 1F, 1F, 1F);

}

 

 

 

 

@Override

public void registerIcons(IconRegister register) {

 

blockIcon = register.registerIcon("SmokeAndMirrors:IllusonBlockDefault");

 

}

 

 

@Override

public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {

 

TileEntity tile = createNewTileEntity(par1IBlockAccess);

if(tile != null) {

Icon[] IconArray = ((TileEntityIllusionBlock) tile).getTextureToModel(par2, par3, par4);

if(IconArray != null){

return IconArray[par5];

} else {

return getIcon(BlockInfo.IllusionBlockId, 0);

}

} else {

return getIcon(BlockInfo.IllusionBlockId, 0);

}

 

 

}

 

 

 

 

 

 

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int i, int j, int k)

    {

            return null;

    }

 

public boolean isOpaqueCube()

    {

        return false;

    }

 

//look into getBlockTexture in Block

 

 

 

 

 

public boolean renderAsNormalBlock()

    {

        return false;

    }

 

public int getRenderType()

    {

        return 0;

    }

 

@Override

public TileEntity createNewTileEntity(World world) {

 

return new TileEntityIllusionBlock();

}

 

public TileEntity createNewTileEntity(IBlockAccess par1IBlockAccess) {

 

return new TileEntityIllusionBlock();

}

}

[spoile/r]

Posted

Just out of curiosity. Do you check all the blocks that are in direct contact with the block? Because if you don't... That would be pretty sad to have the block represent what is [ insert side here ] to it. I would suggest doing a check against all the blocks touching the camo-block and then seeing which ID there is the most of, then use that as the texture-getter. If there is say, only one block touching the camp-block, then you just make the texture of the block the texture of that single block.

 

 

 

P.S. USE CODE TAGS!!!!! AND USE SPOILER TAGS!!!!

 

And as a hint, here are the tags for that. ( Note that you NEED to remove the spaces for it to work xD )

[ s p o i l e r ]

[ c o d e ]

The stuff goes here

[ / c o d e ]

[ / s p o i l e r ]

 

This will result in this:

 

 

The stuff goes here

 

 

 

 

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted

Ohsitdude, you don't need custom renderers or TileEntities for this.

 

Here's some code from a block of mine.  It was called CamoPhaseStone (mod thread)

 

 

public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side)
    {
	int mymeta = world.getBlockMetadata(x, y, z);
	if(mymeta == 0) {
        int[] id = {world.getBlockId(x, y-1, z),world.getBlockId(x, y+1, z),world.getBlockId(x-1, y, z),world.getBlockId(x+1, y, z),world.getBlockId(x, y, z-1),world.getBlockId(x, y, z+1)};
        int[] meta = {world.getBlockMetadata(x, y-1, z),world.getBlockMetadata(x, y+1, z),world.getBlockMetadata(x-1, y, z),world.getBlockMetadata(x+1, y, z),world.getBlockMetadata(x, y, z-1),world.getBlockMetadata(x, y, z+1)};
        //.get.getBlockTextureFromSideAndMetadata(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4));
        for(int i = 0; i < id.length; i++) {
        	Block block = Block.blocksList[id[i]];
        	if(block != null) {
        		if(block != this) {
	        		Icon icon = block.getBlockTextureFromSideAndMetadata(side, meta[i]);
	        		if(icon != null) {
	        			return icon;
	        		}
        		}
        		else {
        			Icon icon = Block.grass.getBlockTextureFromSide(1);
        			switch(i) {
        				case 0:
	        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y-1, z, side, 0);
	        				break;
        				case 1:
	        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y+1, z, side, 1);
	        				break;
        				case 2:
	        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x-1, y, z, side, 2);
	        				break;
        				case 3:
	        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x+1, y, z, side, 3);
	        				break;
        				case 4:
	        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y, z-1, side, 4);
	        				break;
        				case 5:
	        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y, z+1, side, 5);
	        				break;
        			}
	        		if(icon != null && icon != Block.grass.getBlockTextureFromSide(1)) {
	        			return icon;
	        		}
        		}
        	}
        }
        return Block.grass.getBlockTextureFromSide(1);
	}
	else {
		return blockIcon;
	}
    }

public Icon getBlockTextureDirectional(IBlockAccess world, int x, int y, int z, int side, int direction) {

	int id = world.getBlockId(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);
	Block block = Block.blocksList[id];
	if(block != null) {
		if(block != this) {
			Icon icon = block.getBlockTextureFromSideAndMetadata(side, meta);
        		if(icon != null) {
        			return icon;
        		}
		}
		else {
			Icon icon = Block.grass.getBlockTextureFromSide(1);
    			switch(direction) {
    				case 0:
        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y-1, z, side, 0);
        				break;
    				case 1:
        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y+1, z, side, 1);
        				break;
    				case 2:
        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x-1, y, z, side, 2);
        				break;
    				case 3:
        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x+1, y, z, side, 3);
        				break;
    				case 4:
        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y, z-1, side, 4);
        				break;
    				case 5:
        				icon = ((CamoPhaseStone)block).getBlockTextureDirectional(world, x, y, z+1, side, 5);
        				break;
    			}
    			return icon;
		}
	}
	return Block.grass.getBlockTextureFromSide(1);
}

 

 

Now, it would only grab textures in an orthogonal line from its position, but this was done to prevent infinite loops where one block would ask another block what it's texture was, and that block would ask the first block.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

This works for the textures but the colors dont show up (grass is gray).  I think I need to override the getRenderColor method in Block but I don't get the world and the cords as arguments.  Also, what does getBlockTextureDirectional do?

Posted

This works for the textures but the colors dont show up (grass is gray).  I think I need to override the getRenderColor method in Block but I don't get the world and the cords as arguments.  Also, what does getBlockTextureDirectional do?

 

Its the same as getBlockTexture, but rather than looping through the directions (up,down,left,right,forward,backward) it is passed the direction to look at.

 

This prevents blockA -> blockB -> blockA -> infinite loop texture requests.

 

And yes, it doesn't work well for grass. :(

Grass is such a pain in the ass to fake, due to using three textures, only one of which (the top) needs to get colored, but the getBlockColor() method takes no parameters!  getRenderColor() is slightly better, but passes only a single integer (side?), not enough to know if the block that is being rendered is a supposed to be mimicking grass or not.  colorMultiplier() is better still, but doesn't distinguish by side.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

This works for the textures but the colors dont show up (grass is gray).  I think I need to override the getRenderColor method in Block

 

Grass has its own functions for determining color:

 

BlockGrass.java

    public int getBlockColor()
    {
        double d0 = 0.5D;
        double d1 = 1.0D;
        return ColorizerGrass.getGrassColor(d0, d1);
    }

 

ColorizerGrass.java

    /**
     * Gets grass color from temperature and humidity. Args: temperature, humidity
     */
    public static int getGrassColor(double par0, double par2)
    {
        par2 *= par0;
        int i = (int)((1.0D - par0) * 255.0D);
        int j = (int)((1.0D - par2) * 255.0D);
        return grassBuffer[j << 8 | i];
    }

 

Try implementing those in your block. If you can get the temp and humidity you should be able to mimic the grass color.

 

Hint:

 

BiomeGenBase.java

        double d0 = (double)MathHelper.clamp_float(this.getFloatTemperature(), 0.0F, 1.0F);
        double d1 = (double)MathHelper.clamp_float(this.getFloatRainfall(), 0.0F, 1.0F);

Posted

I have overridden getBlockColor like this:

 public int getBlockColor()
    {
	 if(blockToCopy != null) {
			return blockToCopy.getBlockColor();
	 }
				return 16777215;
    }

Where blockToCopy is the block whose texture I'm using.

Also: Leaves do the same thing as grass.  Plus it makes Ice opaque and some blocks (tall grass) use the wrong render type.

Posted

I have overridden getBlockColor like this:

 public int getBlockColor()
       {
       if(blockToCopy != null) {
            return blockToCopy.getBlockColor();
       }
               return 16777215;
       }

Where blockToCopy is the block whose texture I'm using.

Also: Leaves do the same thing as grass.  Plus it makes Ice opaque and some blocks (tall grass) use the wrong render type.

 

Did you override or edit the function directly? You shouldn't see any changes to default blocks if you put it in your block class file with the @Override annotation.

Posted

Where blockToCopy is the block whose texture I'm using.

 

blockToCopy is in the wrong scope.  It'll be overwritten by every block in your world every render, so its not guaranteed to be the same block when that function is called.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

I have overridden getBlockColor like this:

 public int getBlockColor()
       {
       if(blockToCopy != null) {
            return blockToCopy.getBlockColor();
       }
               return 16777215;
       }

Where blockToCopy is the block whose texture I'm using.

Also: Leaves do the same thing as grass.  Plus it makes Ice opaque and some blocks (tall grass) use the wrong render type.

 

Did you override or edit the function directly? You shouldn't see any changes to default blocks if you put it in your block class file with the @Override annotation.

 

Sorry.  By Ice and Leaves I mean my block when it tries to copy Ice and Leaves

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
    • Okay, but does the modpack works with 1.12 or just with 1.12.2, because I need the Forge client specifically for Minecraft 1.12, not 1.12.2
    • Version 1.19 - Forge 41.0.63 I want to create a wolf entity that I can ride, so far it seems to be working, but the problem is that when I get on the wolf, I can’t control it. I then discovered that the issue is that the server doesn’t detect that I’m riding the wolf, so I’m struggling with synchronization. However, it seems to not be working properly. As I understand it, the server receives the packet but doesn’t register it correctly. I’m a bit new to Java, and I’ll try to provide all the relevant code and prints *The comments and prints are translated by chatgpt since they were originally in Spanish* Thank you very much in advance No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. No player is mounted, or the passenger is not a player. MountableWolfEntity package com.vals.valscraft.entity; import com.vals.valscraft.network.MountSyncPacket; import com.vals.valscraft.network.NetworkHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.animal.Wolf; import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.Entity; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor; public class MountableWolfEntity extends Wolf { private boolean hasSaddle; private static final EntityDataAccessor<Byte> DATA_ID_FLAGS = SynchedEntityData.defineId(MountableWolfEntity.class, EntityDataSerializers.BYTE); public MountableWolfEntity(EntityType<? extends Wolf> type, Level level) { super(type, level); this.hasSaddle = false; } @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(DATA_ID_FLAGS, (byte)0); } public static AttributeSupplier.Builder createAttributes() { return Wolf.createAttributes() .add(Attributes.MAX_HEALTH, 20.0) .add(Attributes.MOVEMENT_SPEED, 0.3); } @Override public InteractionResult mobInteract(Player player, InteractionHand hand) { ItemStack itemstack = player.getItemInHand(hand); if (itemstack.getItem() == Items.SADDLE && !this.hasSaddle()) { if (!player.isCreative()) { itemstack.shrink(1); } this.setSaddle(true); return InteractionResult.SUCCESS; } else if (!level.isClientSide && this.hasSaddle()) { player.startRiding(this); MountSyncPacket packet = new MountSyncPacket(true); // 'true' means the player is mounted NetworkHandler.CHANNEL.sendToServer(packet); // Ensure the server handles the packet return InteractionResult.SUCCESS; } return InteractionResult.PASS; } @Override public void travel(Vec3 travelVector) { if (this.isVehicle() && this.getControllingPassenger() instanceof Player) { System.out.println("The wolf has a passenger."); System.out.println("The passenger is a player."); Player player = (Player) this.getControllingPassenger(); // Ensure the player is the controller this.setYRot(player.getYRot()); this.yRotO = this.getYRot(); this.setXRot(player.getXRot() * 0.5F); this.setRot(this.getYRot(), this.getXRot()); this.yBodyRot = this.getYRot(); this.yHeadRot = this.yBodyRot; float forward = player.zza; float strafe = player.xxa; if (forward <= 0.0F) { forward *= 0.25F; } this.flyingSpeed = this.getSpeed() * 0.1F; this.setSpeed((float) this.getAttributeValue(Attributes.MOVEMENT_SPEED) * 1.5F); this.setDeltaMovement(new Vec3(strafe, travelVector.y, forward).scale(this.getSpeed())); this.calculateEntityAnimation(this, false); } else { // The wolf does not have a passenger or the passenger is not a player System.out.println("No player is mounted, or the passenger is not a player."); super.travel(travelVector); } } public boolean hasSaddle() { return this.hasSaddle; } public void setSaddle(boolean hasSaddle) { this.hasSaddle = hasSaddle; } @Override protected void dropEquipment() { super.dropEquipment(); if (this.hasSaddle()) { this.spawnAtLocation(Items.SADDLE); this.setSaddle(false); } } @SubscribeEvent public static void onServerTick(TickEvent.ServerTickEvent event) { if (event.phase == TickEvent.Phase.START) { MinecraftServer server = net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer(); if (server != null) { for (ServerPlayer player : server.getPlayerList().getPlayers()) { if (player.isPassenger() && player.getVehicle() instanceof MountableWolfEntity) { MountableWolfEntity wolf = (MountableWolfEntity) player.getVehicle(); System.out.println("Tick: " + player.getName().getString() + " is correctly mounted on " + wolf); } } } } } private boolean lastMountedState = false; @Override public void tick() { super.tick(); if (!this.level.isClientSide) { // Only on the server boolean isMounted = this.isVehicle() && this.getControllingPassenger() instanceof Player; // Only print if the state changed if (isMounted != lastMountedState) { if (isMounted) { Player player = (Player) this.getControllingPassenger(); // Verify the passenger is a player System.out.println("Server: Player " + player.getName().getString() + " is now mounted."); } else { System.out.println("Server: The wolf no longer has a passenger."); } lastMountedState = isMounted; } } } @Override public void addPassenger(Entity passenger) { super.addPassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(true)); } } } @Override public void removePassenger(Entity passenger) { super.removePassenger(passenger); if (passenger instanceof Player) { Player player = (Player) passenger; if (!this.level.isClientSide && player instanceof ServerPlayer) { // Send the packet to the server to indicate the player is no longer mounted NetworkHandler.CHANNEL.send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) player), new MountSyncPacket(false)); } } } @Override public boolean isControlledByLocalInstance() { Entity entity = this.getControllingPassenger(); return entity instanceof Player; } @Override public void positionRider(Entity passenger) { if (this.hasPassenger(passenger)) { double xOffset = Math.cos(Math.toRadians(this.getYRot() + 90)) * 0.4; double zOffset = Math.sin(Math.toRadians(this.getYRot() + 90)) * 0.4; passenger.setPos(this.getX() + xOffset, this.getY() + this.getPassengersRidingOffset() + passenger.getMyRidingOffset(), this.getZ() + zOffset); } } } MountSyncPacket package com.vals.valscraft.network; import com.vals.valscraft.entity.MountableWolfEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class MountSyncPacket { private final boolean isMounted; public MountSyncPacket(boolean isMounted) { this.isMounted = isMounted; } public void encode(FriendlyByteBuf buffer) { buffer.writeBoolean(isMounted); } public static MountSyncPacket decode(FriendlyByteBuf buffer) { return new MountSyncPacket(buffer.readBoolean()); } public void handle(NetworkEvent.Context context) { context.enqueueWork(() -> { ServerPlayer player = context.getSender(); // Get the player from the context if (player != null) { // Verifies if the player has dismounted if (!isMounted) { Entity vehicle = player.getVehicle(); if (vehicle instanceof MountableWolfEntity wolf) { // Logic to remove the player as a passenger wolf.removePassenger(player); System.out.println("Server: Player " + player.getName().getString() + " is no longer mounted."); } } } }); context.setPacketHandled(true); // Marks the packet as handled } } networkHandler package com.vals.valscraft.network; import com.vals.valscraft.valscraft; import net.minecraft.resources.ResourceLocation; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; import net.minecraftforge.network.NetworkEvent; import java.util.function.Supplier; public class NetworkHandler { private static final String PROTOCOL_VERSION = "1"; public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel( new ResourceLocation(valscraft.MODID, "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); public static void init() { int packetId = 0; // Register the mount synchronization packet CHANNEL.registerMessage( packetId++, MountSyncPacket.class, MountSyncPacket::encode, MountSyncPacket::decode, (msg, context) -> msg.handle(context.get()) // Get the context with context.get() ); } }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.