Fix #887 Particles are wrong when breaking wood items

This commit is contained in:
mezz committed 2015-10-14 12:20:42 -07:00
1 parent e6bb939f7f
commit 140643bec3
6 files changed
+125 -71

No files matched your search

@@ -18,6 +18,7 @@ import net.minecraft.block.BlockFence;
import net.minecraft.block.BlockFenceGate;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@@ -41,10 +42,12 @@ import forestry.api.core.Tabs;
import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.render.IconProviderWood;
import forestry.arboriculture.tiles.TileWood;
import forestry.core.render.ParticleHelper;
import forestry.plugins.PluginArboriculture;
public class BlockArbFence extends BlockFence implements IWoodTyped, ITileEntityProvider {
private final ParticleHelper.Callback particleCallback;
private final boolean fireproof;
public BlockArbFence(boolean fireproof) {
@@ -57,6 +60,8 @@ public class BlockArbFence extends BlockFence implements IWoodTyped, ITileEntity
setHarvestLevel("axe", 0);
setStepSound(soundTypeWood);
setCreativeTab(Tabs.tabArboriculture);
this.particleCallback = new ParticleHelper.DefaultCallback(this);
}
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -174,4 +179,17 @@ public class BlockArbFence extends BlockFence implements IWoodTyped, ITileEntity
public boolean isFireproof() {
return fireproof;
}
/* Particles */
@SideOnly(Side.CLIENT)
@Override
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
return ParticleHelper.addHitEffects(worldObj, this, target, effectRenderer, particleCallback);
}
@SideOnly(Side.CLIENT)
@Override
public boolean addDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
return ParticleHelper.addDestroyEffects(worldObj, this, x, y, z, meta, effectRenderer, particleCallback);
}
}
@@ -16,6 +16,7 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@@ -37,9 +38,11 @@ import forestry.api.core.Tabs;
import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.render.IconProviderWood;
import forestry.arboriculture.tiles.TileWood;
import forestry.core.render.ParticleHelper;
public class BlockArbStairs extends BlockStairs implements IWoodTyped, ITileEntityProvider {
private final ParticleHelper.Callback particleCallback;
private final boolean fireproof;
public BlockArbStairs(Block par2Block, boolean fireproof) {
@@ -51,6 +54,8 @@ public class BlockArbStairs extends BlockStairs implements IWoodTyped, ITileEnti
setHardness(2.0F);
setResistance(5.0F);
setHarvestLevel("axe", 0);
this.particleCallback = new ParticleHelper.DefaultCallback(this);
}
@SuppressWarnings({"rawtypes", "unchecked"})
@@ -126,4 +131,17 @@ public class BlockArbStairs extends BlockStairs implements IWoodTyped, ITileEnti
public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) {
return new TileWood();
}
/* Particles */
@SideOnly(Side.CLIENT)
@Override
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
return ParticleHelper.addHitEffects(worldObj, this, target, effectRenderer, particleCallback);
}
@SideOnly(Side.CLIENT)
@Override
public boolean addDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
return ParticleHelper.addDestroyEffects(worldObj, this, x, y, z, meta, effectRenderer, particleCallback);
}
}
@@ -17,6 +17,7 @@ import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
@@ -41,9 +42,11 @@ import forestry.api.core.Tabs;
import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.render.IconProviderWood;
import forestry.arboriculture.tiles.TileWood;
import forestry.core.render.ParticleHelper;
public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyped, ITileEntityProvider {
private final ParticleHelper.Callback particleCallback;
private final boolean fireproof;
public BlockSlab(boolean fireproof) {
@@ -57,6 +60,8 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
setResistance(5.0F);
setStepSound(soundTypeWood);
setHarvestLevel("axe", 0);
this.particleCallback = new ParticleHelper.DefaultCallback(this);
}
@Override
@@ -183,4 +188,17 @@ public class BlockSlab extends net.minecraft.block.BlockSlab implements IWoodTyp
public Item getItem(World world, int x, int y, int z) {
return Item.getItemFromBlock(this);
}
/* Particles */
@SideOnly(Side.CLIENT)
@Override
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
return ParticleHelper.addHitEffects(worldObj, this, target, effectRenderer, particleCallback);
}
@SideOnly(Side.CLIENT)
@Override
public boolean addDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
return ParticleHelper.addDestroyEffects(worldObj, this, x, y, z, meta, effectRenderer, particleCallback);
}
}
@@ -15,6 +15,7 @@ import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -35,10 +36,12 @@ import forestry.api.core.Tabs;
import forestry.arboriculture.IWoodTyped;
import forestry.arboriculture.render.IconProviderWood;
import forestry.arboriculture.tiles.TileWood;
import forestry.core.render.ParticleHelper;
import forestry.core.tiles.TileUtil;
public abstract class BlockWood extends Block implements ITileEntityProvider, IWoodTyped {
private final ParticleHelper.Callback particleCallback;
private final String blockKind;
private final boolean fireproof;
@@ -49,6 +52,8 @@ public abstract class BlockWood extends Block implements ITileEntityProvider, IW
setStepSound(soundTypeWood);
setCreativeTab(Tabs.tabArboriculture);
particleCallback = new ParticleHelper.DefaultCallback(this);
}
@Override
@@ -138,4 +143,16 @@ public abstract class BlockWood extends Block implements ITileEntityProvider, IW
@SideOnly(Side.CLIENT)
public abstract IIcon getIcon(IBlockAccess world, int x, int y, int z, int side);
/* Particles */
@SideOnly(Side.CLIENT)
@Override
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
return ParticleHelper.addHitEffects(worldObj, this, target, effectRenderer, particleCallback);
}
@SideOnly(Side.CLIENT)
@Override
public boolean addDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
return ParticleHelper.addDestroyEffects(worldObj, this, x, y, z, meta, effectRenderer, particleCallback);
}
}
@@ -49,35 +49,20 @@ public class ParticleHelper {
if (sideHit == 0) {
py = (double) y + block.getBlockBoundsMinY() - (double) b;
}
if (sideHit == 1) {
} else if (sideHit == 1) {
py = (double) y + block.getBlockBoundsMaxY() + (double) b;
}
if (sideHit == 2) {
} else if (sideHit == 2) {
pz = (double) z + block.getBlockBoundsMinZ() - (double) b;
}
if (sideHit == 3) {
} else if (sideHit == 3) {
pz = (double) z + block.getBlockBoundsMaxZ() + (double) b;
}
if (sideHit == 4) {
} else if (sideHit == 4) {
px = (double) x + block.getBlockBoundsMinX() - (double) b;
}
if (sideHit == 5) {
} else if (sideHit == 5) {
px = (double) x + block.getBlockBoundsMaxX() + (double) b;
}
EntityDiggingFX fx = new EntityDiggingFX(world, px, py, pz, 0.0D, 0.0D, 0.0D, block, sideHit, meta);
fx.setParticleIcon(block.getIcon(world, x, y, z, 0));
if (callback != null) {
callback.addHitEffects(fx, world, x, y, z, meta);
}
callback.addHitEffects(fx, world, x, y, z, meta, sideHit);
effectRenderer.addEffect(fx.applyColourMultiplier(x, y, z).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
return true;
@@ -90,7 +75,6 @@ public class ParticleHelper {
* the location is this block.
*
* @param world The current world
* @param block
* @param x X position to spawn the particle
* @param y Y position to spawn the particle
* @param z Z position to spawn the particle
@@ -115,12 +99,7 @@ public class ParticleHelper {
int random = rand.nextInt(6);
EntityDiggingFX fx = new EntityDiggingFX(world, px, py, pz, px - x - 0.5D, py - y - 0.5D, pz - z - 0.5D, block, random, meta);
fx.setParticleIcon(block.getIcon(world, x, y, z, 0));
if (callback != null) {
callback.addDestroyEffects(fx, world, x, y, z, meta);
}
callback.addDestroyEffects(fx, world, x, y, z, meta);
effectRenderer.addEffect(fx.applyColourMultiplier(x, y, z));
}
}
@@ -132,9 +111,35 @@ public class ParticleHelper {
public interface Callback {
@SideOnly(Side.CLIENT)
void addHitEffects(EntityDiggingFX fx, World world, int x, int y, int z, int meta);
void addHitEffects(EntityDiggingFX fx, World world, int x, int y, int z, int meta, int side);
@SideOnly(Side.CLIENT)
void addDestroyEffects(EntityDiggingFX fx, World world, int x, int y, int z, int meta);
}
public static class DefaultCallback implements ParticleHelper.Callback {
private final Block block;
public DefaultCallback(Block block) {
this.block = block;
}
@Override
@SideOnly(Side.CLIENT)
public void addHitEffects(EntityDiggingFX fx, World world, int x, int y, int z, int meta, int side) {
setTexture(fx, world, x, y, z, side);
}
@Override
@SideOnly(Side.CLIENT)
public void addDestroyEffects(EntityDiggingFX fx, World world, int x, int y, int z, int meta) {
setTexture(fx, world, x, y, z, 0);
}
@SideOnly(Side.CLIENT)
private void setTexture(EntityDiggingFX fx, World world, int x, int y, int z, int side) {
fx.setParticleIcon(block.getIcon(world, x, y, z, side));
}
}
}
@@ -16,7 +16,6 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EffectRenderer;
import net.minecraft.client.particle.EntityDiggingFX;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
@@ -47,12 +46,12 @@ import forestry.plugins.PluginFarming;
public class BlockFarm extends BlockStructure {
private static BlockFarm instance;
private final ParticleHelper.Callback particleCallback;
public BlockFarm() {
super(Material.rock);
setHardness(1.0f);
instance = this;
this.particleCallback = new ParticleHelper.DefaultCallback(this);
}
@Override
@@ -162,40 +161,6 @@ public class BlockFarm extends BlockStructure {
EnumFarmBlockTexture.registerIcons(register);
}
private static class ParticleCallback implements ParticleHelper.Callback {
@Override
@SideOnly(Side.CLIENT)
public void addHitEffects(EntityDiggingFX fx, World world, int x, int y, int z, int meta) {
setTexture(fx, world, x, y, z);
}
@Override
@SideOnly(Side.CLIENT)
public void addDestroyEffects(EntityDiggingFX fx, World world, int x, int y, int z, int meta) {
setTexture(fx, world, x, y, z);
}
@SideOnly(Side.CLIENT)
private static void setTexture(EntityDiggingFX fx, World world, int x, int y, int z) {
fx.setParticleIcon(instance.getIcon(world, x, y, z, 0));
}
}
private static final ParticleHelper.Callback callback = new ParticleCallback();
@SideOnly(Side.CLIENT)
@Override
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
return ParticleHelper.addHitEffects(worldObj, instance, target, effectRenderer, callback);
}
@SideOnly(Side.CLIENT)
@Override
public boolean addDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
return ParticleHelper.addDestroyEffects(worldObj, instance, x, y, z, meta, effectRenderer, callback);
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int metadata) {
@@ -237,11 +202,6 @@ public class BlockFarm extends BlockStructure {
}
}
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return world.getBlockMetadata(x, y, z) == 5;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
@@ -260,4 +220,22 @@ public class BlockFarm extends BlockStructure {
return block.getIcon(side, base.getItemDamage());
}
/* Particles */
@SideOnly(Side.CLIENT)
@Override
public boolean addHitEffects(World worldObj, MovingObjectPosition target, EffectRenderer effectRenderer) {
return ParticleHelper.addHitEffects(worldObj, this, target, effectRenderer, particleCallback);
}
@SideOnly(Side.CLIENT)
@Override
public boolean addDestroyEffects(World worldObj, int x, int y, int z, int meta, EffectRenderer effectRenderer) {
return ParticleHelper.addDestroyEffects(worldObj, this, x, y, z, meta, effectRenderer, particleCallback);
}
@Override
public boolean canConnectRedstone(IBlockAccess world, int x, int y, int z, int side) {
return world.getBlockMetadata(x, y, z) == 5;
}
}