Jump to content

[1.12.2] Canceling item placement when rightclicking on a block and rendering issues


Whompy

Recommended Posts

I tried using this to summon an item when rightclicking it with another item, however it isn't doing anything

 

BlockTileEntity.spawnAsEntity(worldIn, pos,itemstack);

 

I think this may be due to the fact that i have been unable to register my tileentity class called BlockTileEntity. How do I go about this?

Edited by Whompy
mistake
Link to comment
Share on other sites

50 minutes ago, Whompy said:

the fact that i have been unable to register my tileentity

I...am not sure what kind of trouble you're having. Maybe you should post your code, even if its something you tried, but didn't work.

51 minutes ago, Whompy said:

BlockTileEntity.spawnAsEntity(worldIn, pos,glass2);

This is not a vanilla or Forge supplied method.

 

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.

Link to comment
Share on other sites

Well here is my block code

 

public class BlockFocus extends Block implements IHasModel{

	public static AxisAlignedBB BASIC_FOCUS_AABB = new AxisAlignedBB(0D, 0, 0D, 1D, 0.375D, 1D);
	
	public BlockFocus(String name, Material materialIn) {
		super(materialIn);
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
		ModBlocks.BLOCKS.add(this);
		ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
		setSoundType(SoundType.WOOD);
		setHardness(25);
		setResistance(3000);
		setHarvestLevel("pickaxe", 0);
		setLightLevel(0F);
	}

	@Override
	public void registerModels() {
		Main.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
	}
	@Override
	public boolean isOpaqueCube(IBlockState state) {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public boolean isFullCube(IBlockState state) {
		// TODO Auto-generated method stub
		return false;
	}
	
	@Override
	public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
		return BASIC_FOCUS_AABB;
	}
	
	Item glass = Item.getItemFromBlock(Blocks.GLASS);
	ItemStack glass2 = new ItemStack(glass);
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		// TODO Auto-generated method stub
		if(pos.down() == ModBlocks.MAGIC_BLOCK.getDefaultState()) {
			if(playerIn.inventory.getCurrentItem().getItem() == glass) {
				BlockTileEntity.spawnAsEntity(worldIn, pos,glass2);
				return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
			}
			
		}
		return enableStats;
	}
	
	@Override
	public boolean hasTileEntity(IBlockState state) {
		// TODO Auto-generated method stub
		
		return super.hasTileEntity(state);
	}
	
	@Override
	public TileEntity createTileEntity(World world, IBlockState state) {
		// TODO Auto-generated method stub
		return super.createTileEntity(world, state);
	}
	
	
}

	

 

I planned to then make the item unpickupable and not despawn. Then create an if statement checking if the player is holding shift when right clicking the block to remove the item.

 

BlockTileEntity is another bit of code I wrote.

I used autocomplete to find that method, and it does not create any errors in eclispe.

According to its description it: "spawns the given ItemStack as an EntityItem into the World at the given position" It doesn't appear to work however

 

 

public abstract class BlockTileEntity<TE extends TileEntity> extends BlockFocus {

	public BlockTileEntity(Material material, String name) {
		super(name, material);
	}
	
	public abstract Class<TE> getTileEntityClass();
	
	public TE getTileEntity(IBlockAccess world, BlockPos pos) {
		return (TE)world.getTileEntity(pos);
	}
	
	@Override
	public boolean hasTileEntity(IBlockState state) {
		return true;
	}
	
	@Nullable
	@Override
	public abstract TE createTileEntity(World world, IBlockState state);
	
	@Override
	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
			EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
		// TODO Auto-generated method stub
		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
	}

}

 

 

for clarification purposes, I am having trouble rendering an item on top of my special block which in the code is made using the class BlockFocus. I would like to make said item act as if it is on a pedestal and for the most part uninterruptible unless someone shift right clicks on the BlockFocus which would remove said item from the pedistal allowing it to despawn and behave like a normal item. Earlier I said I was having right click issues causing the placement of the block to trigger, however I somehow managed to fix that issue. Still need help summoning/rendering an item of choice after the block is right clicked.

Edited by Whompy
clarification
Link to comment
Share on other sites

Code Style #3, but that's the least of the problems.

Why are you overriding onBlockActivated in BlockTileEntity if you do nothing with it?

And what's with all the floating abstract methods?

 

This:

	@Override
	public boolean hasTileEntity(IBlockState state) {
		// TODO Auto-generated method stub
		
		return super.hasTileEntity(state);
	}
	
	@Override
	public TileEntity createTileEntity(World world, IBlockState state) {
		// TODO Auto-generated method stub
		return super.createTileEntity(world, state);
	}

does nothing. Block#hasTileEntity() returns false by default, unless you're using ITileEntityProvider. Block#createTileEntity() returns null unless you're using ITileEntityProvider. That said, you shouldn't use ITileEntityProvider. Just return something useful from those two methods instead.

As a result,

	public TE getTileEntity(IBlockAccess world, BlockPos pos) {
		return (TE)world.getTileEntity(pos);
	}

will return null on the position of the Block, because no TileEntity will ever be created, so it doesn't matter whether you've successfully registered the TileEntity or not.

 

In this:

		if(pos.down() == ModBlocks.MAGIC_BLOCK.getDefaultState()) {
			if(playerIn.inventory.getCurrentItem().getItem() == glass) {
				BlockTileEntity.spawnAsEntity(worldIn, pos,glass2);
				return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
			}
			
		}

pos.down(), which returns a BlockPos, is never going to == an IBlockState. It's a small wonder, then, that the code inside that check never runs. In addition, Block#spawnAsEntity() is not what you're looking for to spawn a visual item. It'll spawn a normal item that players can pick up, will be moved by water, etc. You should create your own EntityItem, set it's properties to fit your needs, and then use World#spawnEntity(). Alternatively, you could set up a TileEntitySpecialRenderer if you need something more customized.

 

As an aside, can you get rid of all the auto-generated comments?

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

Link to comment
Share on other sites

Sorry for having messy code, a good portion of the tile entity related stuff is from earlier testing when I was attempting to store the item on the BlockFocus block in a tlieentity. It didn't quite work out so I left some framework if I managed to figure out how to do it in the future. thx for the advice I will give it another shot

Link to comment
Share on other sites

So I attempted to replace that faulty if statement by attempting to get the blockstate of the block I was trying to refer to.

 

        if(state.getActualState(worldIn, pos.down()) == ModBlocks.MAGIC_BLOCK.getDefaultState()) {...
}


that if statement now looks like this

 

However it still doesn't quite get past the if statement

 

I am trying to check if the block bellow the BlockFocus is another specific modded block from my mod any suggestions for how I should go about this?

 

 

Edited by Whompy
Link to comment
Share on other sites

39 minutes ago, Whompy said:

However it still doesn't quite get past the if statement

If only you would show more of your code, use the debugger or logging statements to figure out what these values are.

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.

Link to comment
Share on other sites

1 hour ago, Whompy said:

if(state.getActualState(worldIn, pos.down()) == ModBlocks.MAGIC_BLOCK.getDefaultState())

I think you need to use World#getBlockState() instead of IBlockState#getActualState() in this context. To understand the difference, take a look at the documentation on this topic.

Edited by SerpentDagger

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

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



×
×
  • Create New...

Important Information

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