Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED][1.12.2]Double-part flat block(like beds) gives no texture
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
LorenzoPapi

[SOLVED][1.12.2]Double-part flat block(like beds) gives no texture

By LorenzoPapi, November 12 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

LorenzoPapi    0

LorenzoPapi

LorenzoPapi    0

  • Tree Puncher
  • LorenzoPapi
  • Members
  • 0
  • 24 posts
Posted November 12

Basically, I've created a 2x1 block, using pieces of code from the BlockBed class. The problem is that when I use the item to place the block, the blocks are both without texture and, if I select them and press F3, I can see that the block is "minecraft:air". A strange fact is that, if I place the block with /setblock command, it gives texture and model. So, what may be the issue?

When I use the item:

2019-11-12_16_58_57.png.aebe73f97af82a7f87681cee94f1171b.png

When I do /setblock

2019-11-12_16_59_15.png.d584b96433be60c3072a87d407219086.png

2019-11-12_16_59_21.png.e70c92df24fba51d990d34f302cb2385.png

The model of my block:

block_afp.jsonblock_afp_top.json

The class of my block:

package com.lorenzopapi.portalgun.common.block;

import java.util.Random;

import com.lorenzopapi.portalgun.common.init.ModItems;
import com.lorenzopapi.portalgun.common.tileentity.TileEntityAFP;
import com.lorenzopapi.portalgun.common.util.AABB;

import net.minecraft.block.Block;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.EnumPushReaction;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockFaceShape;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockAFP extends BlockHorizontal implements ITileEntityProvider {

	public static final PropertyEnum<BlockAFP.EnumPartType> PART = PropertyEnum.<BlockAFP.EnumPartType>create("part", BlockAFP.EnumPartType.class);
	protected static final AABB AFP_X_AABB = new AABB(0, 0, 2, 16, 1, 14);
	protected static final AABB AFP_Z_AABB = new AABB(2, 0, 0, 14, 1, 16);
	
	public BlockAFP() {
		super(Material.CIRCUITS);
		this.setDefaultState(this.getBlockState().getBaseState().withProperty(PART, BlockAFP.EnumPartType.TOP).withProperty(FACING, EnumFacing.NORTH));
		this.hasTileEntity = true;
	}
	
	@Override
	public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
        BlockPos blockpos = pos;
        if (state.getValue(PART) == BlockAFP.EnumPartType.TOP) {
            blockpos = pos.offset((EnumFacing)state.getValue(FACING));
        }
        TileEntity tileentity = worldIn.getTileEntity(blockpos);
        return new ItemStack(Items.BED, 1);
    }
	
	@Override
    public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) {
        if (player.capabilities.isCreativeMode && state.getValue(PART) == BlockAFP.EnumPartType.TOP) {
            BlockPos blockpos = pos.offset((EnumFacing)state.getValue(FACING));
            if (worldIn.getBlockState(blockpos).getBlock() == this) {
                worldIn.setBlockToAir(blockpos);
            }
        }
    }
	
	@Override
	public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
		EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
		if (state.getValue(PART) == BlockAFP.EnumPartType.TOP) {
            if (worldIn.getBlockState(pos.offset(enumfacing)).getBlock() != this) {
                worldIn.setBlockToAir(pos);
            }
        }
        else if (worldIn.getBlockState(pos.offset(enumfacing.getOpposite())).getBlock() != this) {
            if (!worldIn.isRemote) {
                this.dropBlockAsItem(worldIn, pos, state, 0);
            }
            worldIn.setBlockToAir(pos);
        }
	}
	
	@Override
	public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, TileEntity te, ItemStack stack) {
		if (state.getValue(PART) == BlockAFP.EnumPartType.DOWN && te instanceof TileEntityAFP) {
            TileEntityAFP tileentityafp = (TileEntityAFP)te;
            ItemStack itemstack = tileentityafp.getItemStack();
            spawnAsEntity(worldIn, pos, itemstack);
        }
        else {
            super.harvestBlock(worldIn, player, pos, state, (TileEntity)null, stack);
        }
	}
	
	@Override
	public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
		EnumFacing enumfacing = state.getValue(FACING);
        return enumfacing.getAxis() == EnumFacing.Axis.X ? AFP_X_AABB.toAABB() : AFP_Z_AABB.toAABB();
	}
	
	@Override
	public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
        EnumFacing enumfacing = placer.getHorizontalFacing();
        return super.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, meta, placer, hand).withProperty(FACING, enumfacing);
    }
	
	@Override
	public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
		return new ItemStack(ModItems.itemAFP, 1);
	}
		
	@Override
	public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos) {
		if (world.getBlockState(pos.down()).getBlock() != Blocks.AIR) {
            return world.getBlockState(pos.down()).getBlock().getLightValue(state, world, pos.down());
        }
        return 0;
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta) {
		EnumFacing enumfacing = EnumFacing.getHorizontal(meta);
		return (meta & 4) > 0 ? this.getDefaultState().withProperty(PART, BlockAFP.EnumPartType.DOWN).withProperty(FACING, enumfacing) : this.getDefaultState().withProperty(PART, BlockAFP.EnumPartType.TOP).withProperty(FACING, enumfacing);
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		int i = 0;
        i = i | (state.getValue(FACING)).getHorizontalIndex();
        if (state.getValue(PART) == BlockAFP.EnumPartType.DOWN) { i |= 4; }
        return i;
    }

	@Override
	public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
        super.breakBlock(worldIn, pos, state);
        worldIn.removeTileEntity(pos);
    }
	
	@Override
	protected BlockStateContainer createBlockState() {
        return new BlockStateContainer(this, new IProperty[] { FACING, PART });
    }
	
	@Override
	public IBlockState withRotation(IBlockState state, Rotation rot) {
		return state.withProperty(FACING, rot.rotate(state.getValue(FACING)));
	}
	
	@Override
	public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return state.getValue(PART) == BlockAFP.EnumPartType.TOP ? Items.AIR : ModItems.itemAFP;
    }
	
	public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, IBlockState state, BlockPos pos, EnumFacing face) {
        return BlockFaceShape.UNDEFINED;
    }
	
	@Override
	public boolean hasTileEntity(IBlockState state) { return true; }
	
	@Override
	public boolean isOpaqueCube(IBlockState state) { return false; }
	
	@Override
	public boolean isFullCube(IBlockState state) { return false; }
	
	@Override
	public EnumPushReaction getMobilityFlag(IBlockState state) { return EnumPushReaction.DESTROY; }
	
	@Override
	public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityAFP(); }
	
	/*@Override
	public IBlockState getStateFromMeta(int meta) {
		return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta & 3));
	}
	
	@Override
	public int getMetaFromState(IBlockState state) {
		int i = 0;
        i = i | state.getValue(FACING).getHorizontalIndex();
        return i;
	}*/
	
	public static enum EnumPartType implements IStringSerializable {
		DOWN("down"),
		TOP("top");
		
		private final String name;

        private EnumPartType(String name) { this.name = name; }

        public String toString() { return this.name; }

        public String getName() { return this.name; }
	}
}

And also, do you know why, even if my textures are transparent, there isn't transparency?

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 12

You already know the problem is with your item class.

What on earth brought you to the idea that that class is not important enough to post it here?

  • Quote

Share this post


Link to post
Share on other sites

LorenzoPapi    0

LorenzoPapi

LorenzoPapi    0

  • Tree Puncher
  • LorenzoPapi
  • Members
  • 0
  • 24 posts
Posted November 12

Oops, I totally forgot about that  😓.

Here is the item class:

package com.lorenzopapi.portalgun.common.item;

import com.lorenzopapi.portalgun.common.PortalGun;
import com.lorenzopapi.portalgun.common.block.BlockAFP;
import com.lorenzopapi.portalgun.common.init.ModBlocks;
import com.lorenzopapi.portalgun.common.util.Reference;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;

public class ItemAFP extends ItemBlock {
	
	public ItemAFP(Block block) {
		super(block);
		this.setMaxStackSize(1);
		this.setMaxDamage(0);
		this.setRegistryName(Reference.MOD_ID, "item_aerial_faith_plate");
		this.setCreativeTab(PortalGun.CREATIVE_TAB);
	}
	
	@Override
	public CreativeTabs getCreativeTab() {
		return PortalGun.CREATIVE_TAB;
	}

	@Override
	public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		if (worldIn.isRemote)
        {
            return EnumActionResult.SUCCESS;
        }
        else if (facing != EnumFacing.UP)
        {
            return EnumActionResult.FAIL;
        }
        else
        {
            IBlockState iblockstate = worldIn.getBlockState(pos);
            Block block = iblockstate.getBlock();
            boolean flag = block.isReplaceable(worldIn, pos);

            if (!flag)
            {
                pos = pos.up();
            }

            int i = MathHelper.floor((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
            EnumFacing enumfacing = EnumFacing.getHorizontal(i);
            BlockPos blockpos = pos.offset(enumfacing);
            ItemStack itemstack = player.getHeldItem(hand);

            if (player.canPlayerEdit(pos, facing, itemstack) && player.canPlayerEdit(blockpos, facing, itemstack))
            {
                IBlockState iblockstate1 = worldIn.getBlockState(blockpos);
                boolean flag1 = iblockstate1.getBlock().isReplaceable(worldIn, blockpos);
                boolean flag2 = flag || worldIn.isAirBlock(pos);
                boolean flag3 = flag1 || worldIn.isAirBlock(blockpos);

                if (flag2 && flag3 && worldIn.getBlockState(pos.down()).isTopSolid() && worldIn.getBlockState(blockpos.down()).isTopSolid())
                {
                    IBlockState iblockstate2 = ModBlocks.blockAfp.getDefaultState().withProperty(BlockAFP.FACING, enumfacing).withProperty(BlockAFP.PART, BlockAFP.EnumPartType.TOP);
                    worldIn.setBlockState(pos, iblockstate2, 10);
                    worldIn.setBlockState(blockpos, iblockstate2.withProperty(BlockAFP.PART, BlockAFP.EnumPartType.DOWN), 10);
                    //SoundType soundtype = iblockstate2.getBlock().getSoundType(iblockstate2, worldIn, pos, player);
                    //worldIn.playSound((EntityPlayer)null, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                    TileEntity tileentity = worldIn.getTileEntity(blockpos);

                    worldIn.notifyNeighborsRespectDebug(pos, block, false);
                    worldIn.notifyNeighborsRespectDebug(blockpos, iblockstate1.getBlock(), false);

                    itemstack.shrink(1);
                    return EnumActionResult.SUCCESS;
                }
                else
                {
                    return EnumActionResult.FAIL;
                }
            }
            else
            {
                return EnumActionResult.FAIL;
            }
        }
    }
}

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 12

Stuff like this is really hard to debug by just staring at the code, looking at it I don't see anything obvious.

Please post a working Git repository of your mod so I can test this locally.

  • Quote

Share this post


Link to post
Share on other sites

LorenzoPapi    0

LorenzoPapi

LorenzoPapi    0

  • Tree Puncher
  • LorenzoPapi
  • Members
  • 0
  • 24 posts
Posted November 12

Here is the repo: https://github.com/LorenzoMontanoPecoraro/MyMod

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 12
3 hours ago, LorenzoPapi said:

Here is the repo: https://github.com/LorenzoMontanoPecoraro/MyMod

https://github.com/LorenzoMontanoPecoraro/MyMod/blob/b0bcbf6ee36668243bd9f8db37193e2500a30ad5/src/main/java/com/lorenzopapi/portalgun/common/core/EventHandlerServer.java#L236

You never register this block instance. And overwriting this field here makes no sense.

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2093

Draco18s

Draco18s    2093

  • Reality Controller
  • Draco18s
  • Members
  • 2093
  • 14027 posts
Posted November 13

Also, you should definitely use @ObjectHolder annotations, it will prevent stuff like that.

  • Quote

Share this post


Link to post
Share on other sites

LorenzoPapi    0

LorenzoPapi

LorenzoPapi    0

  • Tree Puncher
  • LorenzoPapi
  • Members
  • 0
  • 24 posts
Posted November 13

Okay, thanks for help! I'll try the @ObjectHolder when I'll be back to my pc.

Still, Thanks.😀😀

  • Quote

Share this post


Link to post
Share on other sites

LorenzoPapi    0

LorenzoPapi

LorenzoPapi    0

  • Tree Puncher
  • LorenzoPapi
  • Members
  • 0
  • 24 posts
Posted November 15

Okay so, I'm switching to @ObjectHolder, but there is one problem with this. I've got to do a custom ModelResourceLocation and, when I pass the item, it crashes with NullPointerException. I've updated the repo. The error is here:

https://github.com/LorenzoMontanoPecoraro/MyMod/blob/e4d2f97fdd316c20fa5c92fa20963042a00583ee/src/main/java/com/lorenzopapi/portalgun/common/init/ModItems.java#L92

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    6684

diesieben07

diesieben07    6684

  • Reality Controller
  • diesieben07
  • Forum Team
  • 6684
  • 45696 posts
Posted November 15

All your items have registry names like "portalgun:portalgunitem_potatos", because your call to setRegistryName in ItemBase is broken.

In general something like ItemBase is bad coding practice, do not abuse inheritance for code-reuse.

  • Quote

Share this post


Link to post
Share on other sites

LorenzoPapi    0

LorenzoPapi

LorenzoPapi    0

  • Tree Puncher
  • LorenzoPapi
  • Members
  • 0
  • 24 posts
Posted November 15

Oh, I didn't know it. I'll change it right now. Thanks for helping me so quicly!

  • Quote

Share this post


Link to post
Share on other sites

LorenzoPapi    0

LorenzoPapi

LorenzoPapi    0

  • Tree Puncher
  • LorenzoPapi
  • Members
  • 0
  • 24 posts
Posted November 15

Ok, now the block works! Thank you so much @diesieben07 for helping me with little things and @Draco18s for suggesting me to use @ObjectHolders.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • EmerProd
      Forge 1.12.2 Crash

      By EmerProd · Posted 13 minutes ago

      It worked by removing the 1.7.10 and 1.8.9 Optifine from mods folder, thank you.
    • J3sq
      Minecraft v1.15 - Supported by Forge?

      By J3sq · Posted 14 minutes ago

      I have just re-installed Minecraft Java Edition onto a new Windows 10 PC, after a while of not playing. I haven't had many issues with modding (that I couldn't solve through reading) in the past, however this time I can't seem to get Forge to recognise any mods. I'm fairly sure my issue is that I'm running version 1.15 of Minecraft and version 1.14.4 of Forge - I have searched and searched for Forge 1.15 and have found a couple of dodgy links (which I did not click), however as Forge version 1.15 is not on the official site I was wondering if anyone can advise me on what to do? Is there a current fix for this or do I just wait for a compatible version?   debug.log: https://pastebin.com/6HzEwf0K    
    • bandofbros20
      1.12.2 Forge isnt working, are these the logs you need?

      By bandofbros20 · Posted 33 minutes ago

      [1211/164737.130:WARNING:angle_platform_impl.cc(41)] rx::HLSLCompiler::compileToBinary(224):  C:\fakepath(37,8-56): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them C:\fakepath(43,8-26): warning X3571: pow(f, e) will not work for negative f, use abs(f) or conditionally handle negative values if you expect them
    • Draco18s
      Distinguish singleplayer vs. multiplayer

      By Draco18s · Posted 57 minutes ago

      Items are not proxies. Proxies are proxies, Items are Items. The Item is supposed to call a method in the proxy, it is not the proxy itself.
    • vMystic
      [1.12.2] plugin with id 'net.minecraftforge.gradle.forge' not found

      By vMystic · Posted 1 hour ago

      Ive tried googling for a long time and i cant find anything on this, Whenever I try to run gradlew setupDecompWorkspace I get the error plugin with id 'net.minecraftforge.gradle.forge' not found ive talked with someone and they said the people here can help me with this issue. Any suggestions?
  • Topics

    • EmerProd
      4
      Forge 1.12.2 Crash

      By EmerProd
      Started Sunday at 06:23 PM

    • J3sq
      0
      Minecraft v1.15 - Supported by Forge?

      By J3sq
      Started 14 minutes ago

    • bandofbros20
      0
      1.12.2 Forge isnt working, are these the logs you need?

      By bandofbros20
      Started 33 minutes ago

    • solitone
      15
      Distinguish singleplayer vs. multiplayer

      By solitone
      Started December 5

    • vMystic
      0
      [1.12.2] plugin with id 'net.minecraftforge.gradle.forge' not found

      By vMystic
      Started 1 hour ago

  • Who's Online (See full list)

    • J3sq
    • plugsmustard
    • Ommina
    • coolsim
    • Ellis,Hunter
    • ComputerCraft32
    • Darren Hayden
    • EmerProd
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [SOLVED][1.12.2]Double-part flat block(like beds) gives no texture
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community