Jump to content

Recommended Posts

Posted

I remember creating a bit of code before that worked for my campfire block - I tried to recreate that code from memory and it seems to not work. Am I missing something?

 

 

package gameslayar.practice.common.blocks;

import java.util.Random;

import gameslayar.practice.common.PracticeMain;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.BlockPos;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockCampfire extends Block {

private final String name = "campfireBlock";

//Basic Properties
public BlockCampfire() {
	super(Material.wood);
	setUnlocalizedName(PracticeMain.MODID + "_" + name);
	setCreativeTab(CreativeTabs.tabMisc);
	setHarvestLevel("axe", 0);
	setHardness(2);
	setLightLevel(4);
	setBlockBounds(0F, 0F, 0F, 1F, 0.59375F, 1F);
	System.out.println("SET!");

	GameRegistry.registerBlock(this, name);

}

//***


//Makes sure that all the blocks around are rendered as well because 
//this isn't a full 1x1x1 block
@Override
public boolean isOpaqueCube() {
	return false;
}
//Corrects lighting around the block
@Override
public boolean isFullCube() {
	return false;
}

//Particle effects. Fancy fire & smoke.
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, BlockPos pos, Random random) {
	System.out.println("Attempting..");
	float f1 = (float)(pos.getX()+0.5F);
	float f2 = (float)(pos.getY()+0.7F);
	float f3 = (float)(pos.getZ()+0.5F);
	float f4 = random.nextFloat() * 0.1F;
	float f5 = random.nextFloat() * -0.1F;

	world.spawnParticle(
			EnumParticleTypes.FLAME,
			(float)(f1+f4),
			(float)(f2),
			(float)(f3+f5),
			0.0D,
			0.0D,
			0.0D,
			new int[0]);
	System.out.println("Attempt finished.");
}


//***

public String getName() {
	return name;
}
}

 

 

PS - The console shows no sign of the

[i]System.out[/i]

messages I put in, it's like

randomDisplayTick

isn't being run at all

GameSlayar

Forgive my noobiness!

Posted

Aha!

I was missing

IBlockState state,

!

 

Thanks so much, I was stressing so much over those silly particles :P

 

EDIT: For anyone else having a similar problem, the code should have been:

 

 

@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, BlockPos pos, IBlockState state, Random random) {

 

GameSlayar

Forgive my noobiness!

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

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