THIS WORKS NOW! WHOOT!
I'm working on my mod, and I'd like to add a "Lightning Creator" block. I have the spawning of lightning working, including redstone and right-click behavior, but apparently Minecraft's code is terrible and the redstone method doesn't actually have clients render the lightning. From the way this block is set up, I *think* that this is because the redstone method is never passed a player object, while the right-click method is passed a player object. The odd thing about that, though, is that the right-click method doesn't use the player object; it isn't used in any variable or anything. I'm not actively asking for help on this (yet), but it'd be nice to have some advice. Does anyone remember which mods add stuff that does lightning properly? Open source mods or mods where the author would respond quickly to questions about the lightning code?
For the curious, here's the code I'm using:
Here's github for the entire project: https://github.com/type1ninja/ExtraFeatures
(I haven't got a .gitignore, so it's a bit messy with all my eclipse settings. Can anyone tell me how a .gitignore works? My one programmer friend is terrible at explaining it)
EDIT: SOLVED! Not sure if it works server side yet; I'll test later.
I'm working on my mod, and I'd like to add a "Lightning Creator" block. I have the spawning of lightning working, including redstone and right-click behavior, but apparently Minecraft's code is terrible and the redstone method doesn't actually have clients render the lightning. From the way this block is set up, I *think* that this is because the redstone method is never passed a player object, while the right-click method is passed a player object. The odd thing about that, though, is that the right-click method doesn't use the player object; it isn't used in any variable or anything. I'm not actively asking for help on this (yet), but it'd be nice to have some advice. Does anyone remember which mods add stuff that does lightning properly? Open source mods or mods where the author would respond quickly to questions about the lightning code?
For the curious, here's the code I'm using:
Code:
public class BlockLightningCreator extends BlockXF {
public static int[] metas = {0, 1};
public static double lightningYOffset = 5.0D;
public BlockLightningCreator(String unlocalizedName) {
super(unlocalizedName);
}
//Create Lightning
//TODO - works, but lightning isn't rendered. -_-
public void spawnLightning(World world, int x, int y, int z) {
EntityLightningBolt lightning = new EntityLightningBolt(world, x, y + lightningYOffset, z);
world.spawnEntityInWorld(lightning);
//Make the Minecraft client spawn the lightning as well
forceClientSpawnLightning(lightning);
}
//Create lightning if right-clicked
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
spawnLightning(world, x, y, z);
return true;
}
//Create lightning if powered by redstone
public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) {
if (!world.isRemote) {
if (world.isBlockIndirectlyGettingPowered(x, y, z)) {
//The way this check works:
if (world.getBlockMetadata(x, y, z) == metas[0]) {
spawnLightning(world, x, y, z);
world.setBlockMetadataWithNotify(x, y, z, metas[1], 3);
}
} else {
//If it ISN'T powered, set whether it's been powered recently to false
world.setBlockMetadataWithNotify(x, y, z, metas[0], 3);
}
}
}
//Get the minecraft client and make that spawn lightning as well
@SideOnly(Side.CLIENT)
public void forceClientSpawnLightning(EntityLightningBolt lightning) {
Minecraft.getMinecraft().theWorld.spawnEntityInWorld(lightning);
}
}
Here's github for the entire project: https://github.com/type1ninja/ExtraFeatures
(I haven't got a .gitignore, so it's a bit messy with all my eclipse settings. Can anyone tell me how a .gitignore works? My one programmer friend is terrible at explaining it)
EDIT: SOLVED! Not sure if it works server side yet; I'll test later.
Last edited: