Jump to content

setBlock Neighbour Texture


NoobminecraftModder

Recommended Posts

Hello everyone

 

I want a block, that assumes the texture from the neighbour block...

I think I can do it in the Method

public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)

. But how can I get the block? I only know

world.getBlockId(x, y, z)

and

world.getBlockMetadata(x, y, z)

but with that I cant get the texture from the block. I know that I can get the block texture by

planks.getBlockTextureFromSide(1);

. But for that I must get first a instance of the neighbour block!

How can I do that.

If something isn't clear ask me..

Thanks in advance for every kind of help :)

 

Link to comment
Share on other sites

yknow minecraft is on a 3d grid right ?

 

so the surrounding blocks are:

x+1, y, z

x-1, y, z

x, y+1, z

x, y-1, z

x, y, z+1

x, y, z-1

 

and once you get the id of surrounding blocks you can do

Block.blocksList[blockid] which will return a block that you can use like this

block.getBlockTextureFromSide(1);

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

yeah because there is only 1 instance of each block, so if you change one you change all, either use ISBRH or TESR to have each block renderered individually

 

then use world.markBlockForUpdate in your onNeighbourBlockChange because this will ask minecraft to re-render that specific block

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

TESR= TileEntitySpecialRenderer

ISBRH=ISpecialBlockRenderHelper

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

I have an other idea...

I set the texture with a variable and the variable is stored in a TileEntity.

But i have a TileEntity:

package Cerebrum.Basis;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class TileEntityHiddenTrapDoor extends TileEntity{
   
public int texture = 1;

@Override
public void writeToNBT(NBTTagCompound par1)
{
   super.writeToNBT(par1);
}

@Override
public void readFromNBT(NBTTagCompound par1)
{
   super.readFromNBT(par1);
}
}

@Override
    public TileEntity createTileEntity(World world, int metadata)
    {
    	System.out.println("TileEntity registriert");
    	return new TileEntityHiddenTrapDoor();
    }

And I want to create the TileEntity with this Code in my Block file.

But if I print out SSystem.out.println(this.hasTileEntity()); it's always false...

And yes I have connected the tileEntity in de MainClass File.

 

GameRegistry.registerTileEntity(TileEntityHiddenTrapDoor.class, "TileEntityHiddenTrapDoor");

Link to comment
Share on other sites

Cant you just use the getBlockTexture method?

 

In your case you would just do something like this:

 

@Override
    public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side)
    {
        int meta = world.getBlockMetadata(x, y-1, z)
        int bottomId = world.getBlockId(x, y-1, z)

        switch(side)
        {
             case 0:
                    Block.blocksList[bottomId].getIcon(0, meta)
             case 1:
                    Block.blocksList[bottomId].getIcon(1, meta)
             case 2:
                    Block.blocksList[bottomId].getIcon(2, meta)
             case 3:
                    Block.blocksList[bottomId].getIcon(3, meta)
             case 4:
                    Block.blocksList[bottomId].getIcon(4, meta)
             case 5:
                    Block.blocksList[bottomId].getIcon(5, meta)
        }
    }

 

 

That would totally copy the blocks texture underneath, to change that, play a little bit with the bottomId.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Yes I tried it my self

what exactly did you do.

 

because registering a ISimpleBlockRenderingHandler isnt particularelly hard, unless you lack the basic java knowledge to naviguate the code :\

 

did you create the new class ?

did you try to register it ?

did you debug a little to see where it could fail ?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

ahh, ok, well thats a good starting point, now whats the content of this class ? because if theres nothing well .. no this its going to be all invisible xD

 

also did you look on the wiki for the tessellator tutorial ? and the ISimpleBlockRenderingHandler tutorial ?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

ok... well not to be mean but you are kinda taking this code

 

public static void doStuff(){
//tottally empty
}

 

and expecting it to print "hello world"

 

of course if you dont ask it anything it wont do anything, its a computer, its completelly void of any intelligence, it will do exactly what you ask it to (and if its nothign well nothign will happen)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

No you're not mean...you're honest ;D

So my block is a custom trap door.

I looked in to the trap door class and the renderType is "0".

So I looked in to the RenderBlock class and copied the method for rendering type 0.

My class now looks so:

package Cerebrum.Basis;


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.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;

public class HiddenTrapDoorRender extends Render 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) {
        int l = block.colorMultiplier(world, x, y, z);
        float f = (float)(l >> 16 & 255) / 255.0F;
        float f1 = (float)(l >> 8 & 255) / 255.0F;
        float f2 = (float)(l & 255) / 255.0F;

        if (EntityRenderer.anaglyphEnable)
        {
            float f3 = (f * 30.0F + f1 * 59.0F + f2 * 11.0F) / 100.0F;
            float f4 = (f * 30.0F + f1 * 70.0F) / 100.0F;
            float f5 = (f * 30.0F + f2 * 70.0F) / 100.0F;
            f = f3;
            f1 = f4;
            f2 = f5;
        }
return false;
}

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

@Override
public int getRenderId() {
	return 400;
}

@Override
public void doRender(Entity entity, double d0, double d1, double d2,
		float f, float f1) {

}

}

But it don't seems to work...the trap door is invisible.

And with the tutorial http://www.minecraftforge.net/wiki/ISimpleBlockRenderingHandler the block render not correctly. So I thought I can copy from the RenderBlock renderType "0".

 

Link to comment
Share on other sites

yeah thats my tutorial, i dont do the "100% correct beautiful working code" i just research on how it should work and why it works, so you can expect code from my tutorials to NOT work...

 

But it don't seems to work...the trap door is invisible.

yeah, basicly the copy you copy pasta does nothing, look at the Tessellator tutorial to see how to render a face, then you should be able to figure which face you want to render

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

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

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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