Jump to content

[Solved] A block with different faces? e.g. Furnace


ProgrammerCam

Recommended Posts

Ok cool thanks I've copied the code, it all works smoothly, except for one thing, the furnace faces always a set direction; it never changes. I checked the furnace code and well i have been unsuccessful...

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

@SideOnly(Side.CLIENT)

    private Icon furnaceIconTop;

    @SideOnly(Side.CLIENT)

    private Icon furnaceIconFront;

 

    /**

    * Called whenever the block is added into the world. Args: world, x, y, z

    */

    public void onBlockAdded(World par1World, int par2, int par3, int par4)

    {

        super.onBlockAdded(par1World, par2, par3, par4);

        this.setDefaultDirection(par1World, par2, par3, par4);

    }

 

    /**

    * set a blocks direction

    */

    private void setDefaultDirection(World par1World, int par2, int par3, int par4)

    {

        if (!par1World.isRemote)

        {

            int l = par1World.getBlockId(par2, par3, par4 - 1);

            int i1 = par1World.getBlockId(par2, par3, par4 + 1);

            int j1 = par1World.getBlockId(par2 - 1, par3, par4);

            int k1 = par1World.getBlockId(par2 + 1, par3, par4);

            byte b0 = 3;

 

            if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])

            {

                b0 = 3;

            }

 

            if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])

            {

                b0 = 2;

            }

 

            if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])

            {

                b0 = 5;

            }

 

            if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])

            {

                b0 = 4;

            }

 

            par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);

        }

    }

 

    @SideOnly(Side.CLIENT)

 

    /**

    * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata

    */

    public Icon getIcon(int par1, int par2)

    {

        return par1 == 1 ? this.furnaceIconTop : (par1 == 0 ? this.furnaceIconTop : (par1 != par2 ? this.blockIcon : this.furnaceIconFront));

    }

 

    @SideOnly(Side.CLIENT)

 

    /**

    * When this method is called, your block should register all the icons it needs with the given IconRegister. This

    * is the only chance you get to register icons.

    */

    public void registerIcons(IconRegister par1IconRegister)

    {

        this.blockIcon = par1IconRegister.registerIcon("furnace_side");

        this.furnaceIconFront = par1IconRegister.registerIcon("furnace_front_off");

        this.furnaceIconTop = par1IconRegister.registerIcon("furnace_top");

    }

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

If i could get some help that would be awesome!

For some reason the code thing isn't working....

;) I am new to forge however am experienced in Java! ;)
Link to comment
Share on other sites

Ok cool thanks I've copied the code, it all works smoothly, except for one thing, the furnace faces always a set direction; it never changes. I checked the furnace code and well i have been unsuccessful...

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

So, what you want the face to change sides dynamically when you walk around it?

Link to comment
Share on other sites

You want to copy onBlockPlacedBy(World p_149689_1_, int p_149689_2_, int p_149689_3_, int p_149689_4_, EntityLivingBase p_149689_5_, ItemStack p_149689_6_)

 

That is where the direction is determined and set.

 

Link to comment
Share on other sites

Thank you so much but one more problem.... the block. When you hold a furnace on the right hand side of the icon is the front and on the left side is the side icon. How can i make the icon of my item like that. both the left and right side is the icon for the side.

;) I am new to forge however am experienced in Java! ;)
Link to comment
Share on other sites

The Furnace uses metadata to determine it's placed direction (even when rendering on the hotbar.) The facing when in inventory is due to a trick in RenderBlocks where renderBlockAsItem(Block, meta, color) changes the metadata of the furnace used to lookup icon to 2. So, it forces the furnace to face the proper way to render the item in the hotbar.

You might have to set your own block renderer to overcome that limitation.

A possible workaround I haven't tried is to always create your ItemStack with a furnace with metadata = 2. When it is actually placed it will change accordingly, of course.

Link to comment
Share on other sites

The Furnace uses metadata to determine it's placed direction (even when rendering on the hotbar.) The facing when in inventory is due to a trick in RenderBlocks where renderBlockAsItem(Block, meta, color) changes the metadata of the furnace used to lookup icon to 2. So, it forces the furnace to face the proper way to render the item in the hotbar.

You might have to set your own block renderer to overcome that limitation.

A possible workaround I haven't tried is to always create your ItemStack with a furnace with metadata = 2. When it is actually placed it will change accordingly, of course.

You could also do something way more easy. If the furnace is in the inventory, the metadata is 0, but if it's placed down, the metadata is 2,3,4 or 5. So in your getIcon method, check for a metadata that's 0, and if the side is 2, you need to set the front texture.

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 indeed. I hadn't even considered how the furnace will only ever face one of 4 directions, rather than 6. Good advice!

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

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • 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;     }  
  • Topics

×
×
  • Create New...

Important Information

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