Jump to content

[RESOLVED][1.12.2] Put fire in a block


gnosticChemist

Recommended Posts

I'm trying to do an late game item for my magic mod, it's basically an infinite fuel called Sun Piece. I want to add a feature that when a Sun piece is dropped it set the block on fire, I managed to make the fire appears but there's some weird bugs, it was creating floating fires, also the doesn't burn out and can't hurt mobs. I think that I'm doing something wrong, but since this is my first mod (Not first java) I have no idea. How would I do it properly?
Here's Sun Piece class:

public class SunPiece extends Item {

	public SunPiece(){
		super();
		setUnlocalizedName("sunpiece");
		setRegistryName("sunpiece");
		setCreativeTab(CreativeTabs.MISC);
		setMaxStackSize(1);
		setContainerItem(this);
	}
	
	@Override
	public int getItemBurnTime(ItemStack itemStack) {
		return 12800;
	}
	
	@Override
	public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
		if(!entityIn.isBurning()) {
			entityIn.setFire(10);
		}
	}
	
	@Override
	public boolean hasCustomEntity(ItemStack stack) {
		return true;
	}
	
	@Override
	public Entity createEntity(World world, Entity location, ItemStack itemstack){
		EntityItem item = new EntityItem(world, location.posX, location.posY, location.posZ, itemstack) {
			@Override
			public boolean isEntityInvulnerable(DamageSource source) {
				if(source.isFireDamage())return true;
				return super.isEntityInvulnerable(source);
			}
		};
		item.motionX = location.motionX;
		item.motionY = location.motionY;
		item.motionZ = location.motionZ;
		item.isAirBorne = true;
		item.setDefaultPickupDelay();
        return item;
    }
	
	@Override
	public boolean onEntityItemUpdate(EntityItem entityItem) {
		World world = entityItem.world;
		if(world.getBlockState(entityItem.getPosition()) == Blocks.AIR.getDefaultState()) {
			if(world.getBlockState(entityItem.getPosition().down()) != Blocks.AIR.getDefaultState())
			if(entityItem.motionZ == 0 && world.getBlockState(entityItem.getPosition()) != Blocks.FIRE.getDefaultState())
				world.setBlockState(entityItem.getPosition(), Blocks.FIRE.getDefaultState());		
		}	
		return bFull3D;
	}
}

I'm doing the fire set on metod onEntityItemUpdate()

Edited by gnosticChemist
Problem resolved
Link to comment
Share on other sites

8 hours ago, mirk said:

I'm not sure if you're supposed to compare BlockStates.

 

Have you taken a look at how Flint & Steel spawns its fires?

Thanks, it solved. When I see how Flint & Steel put fire I realized that my code doesn't give the flags that the fire need. I still have to verify if the item isn't flying because if is it creates flying fires that sometimes doesn't burn out, but is't work perfectly. Here's the code if anyone is having the same problem:

 

@Override
	public boolean onEntityItemUpdate(EntityItem entityItem) {
		BlockPos pos = entityItem.getPosition();
		World world = entityItem.world;
		if(world.isAirBlock(pos) && !world.isAirBlock(pos.down())) {
			world.setBlockState(entityItem.getPosition(), Blocks.FIRE.getDefaultState(),11);	
			//This line /\ set the fire with the properly flags
		}	
		return bFull3D;
	}

 

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.