Working Particles

This commit is contained in:
Alexander 2016-03-23 22:51:54 -04:00
parent dcc1c1b50c
commit 1aa5f2e85c
5 changed files with 193 additions and 1 deletions

View File

@ -35,7 +35,7 @@ archivesBaseName = "ironchest"
// Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here // Setup the forge minecraft plugin data. Specify the preferred forge/minecraft version here
minecraft { minecraft {
version = "1.9-12.16.0.1781-1.9" version = "1.9-12.16.0.1802-1.9"
mappings = "snapshot_20160319" mappings = "snapshot_20160319"
runDir = "run" runDir = "run"
} }

View File

@ -16,6 +16,7 @@ import java.util.Random;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import cpw.mods.ironchest.client.IronChestTextureHandler;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.IProperty;
@ -33,11 +34,13 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.Explosion; import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -78,6 +81,12 @@ public class BlockIronChest extends BlockContainer
return false; return false;
} }
@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.ENTITYBLOCK_ANIMATED;
}
@Override @Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState blockState, EntityPlayer player, EnumHand hand, ItemStack heldItem, public boolean onBlockActivated(World world, BlockPos pos, IBlockState blockState, EntityPlayer player, EnumHand hand, ItemStack heldItem,
EnumFacing direction, float hitX, float hitY, float hitZ) EnumFacing direction, float hitX, float hitY, float hitZ)
@ -258,6 +267,22 @@ public class BlockIronChest extends BlockContainer
return super.getExplosionResistance(world, pos, exploder, explosion); return super.getExplosionResistance(world, pos, exploder, explosion);
} }
@Override
@SideOnly(Side.CLIENT)
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, net.minecraft.client.particle.EffectRenderer effectRenderer)
{
IronChestTextureHandler.addHitEffects(worldObj, target.getBlockPos(), target.sideHit);
return true;
}
@Override
@SideOnly(Side.CLIENT)
public boolean addDestroyEffects(World world, BlockPos pos, net.minecraft.client.particle.EffectRenderer effectRenderer)
{
IronChestTextureHandler.addDestroyEffects(world, pos, world.getBlockState(pos));
return true;
}
@Override @Override
public boolean hasComparatorInputOverride(IBlockState state) public boolean hasComparatorInputOverride(IBlockState state)
{ {

View File

@ -10,6 +10,7 @@
******************************************************************************/ ******************************************************************************/
package cpw.mods.ironchest; package cpw.mods.ironchest;
import cpw.mods.ironchest.client.IronChestEventHandler;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
@ -55,5 +56,7 @@ public class IronChest
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
proxy.registerRenderInformation(); proxy.registerRenderInformation();
MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler()); MinecraftForge.EVENT_BUS.register(new OcelotsSitOnChestsHandler());
MinecraftForge.EVENT_BUS.register(IronChestEventHandler.INSTANCE);
} }
} }

View File

@ -0,0 +1,25 @@
package cpw.mods.ironchest.client;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class IronChestEventHandler
{
public static IronChestEventHandler INSTANCE = new IronChestEventHandler();
@SubscribeEvent
public void onPreTextureStiching(TextureStitchEvent.Pre event)
{
if (event.map == FMLClientHandler.instance().getClient().getTextureMapBlocks())
{
event.map.registerSprite(new ResourceLocation("ironchest:blocks/copperbreak"));
event.map.registerSprite(new ResourceLocation("ironchest:blocks/crystalbreak"));
event.map.registerSprite(new ResourceLocation("ironchest:blocks/diamondbreak"));
event.map.registerSprite(new ResourceLocation("ironchest:blocks/goldbreak"));
event.map.registerSprite(new ResourceLocation("ironchest:blocks/ironbreak"));
event.map.registerSprite(new ResourceLocation("ironchest:blocks/silverbreak"));
}
}
}

View File

@ -0,0 +1,139 @@
package cpw.mods.ironchest.client;
import java.util.Map;
import java.util.Random;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
import cpw.mods.ironchest.IronChestType;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.EntityDiggingFX;
import net.minecraft.client.renderer.block.model.ModelManager;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class IronChestTextureHandler
{
private static Map<IronChestType, ResourceLocation> locations;
static
{
Builder<IronChestType, ResourceLocation> builder = ImmutableMap.<IronChestType, ResourceLocation> builder();
for (IronChestType typ : IronChestType.values())
{
if (typ != IronChestType.DIRTCHEST9000 && typ != IronChestType.OBSIDIAN)
builder.put(typ, new ResourceLocation("ironchest", "blocks/" + typ.getModelTexture().replace("chest", "break").replace(".png", "")));
else if (typ == IronChestType.DIRTCHEST9000)
builder.put(typ, new ResourceLocation("minecraft", "blocks/dirt"));
else if (typ == IronChestType.OBSIDIAN)
builder.put(typ, new ResourceLocation("minecraft", "blocks/obsidian"));
}
locations = builder.build();
}
public static void addHitEffects(World world, BlockPos pos, EnumFacing side)
{
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
state = block.getActualState(state, world, pos);
Random rand = new Random();
IronChestType type = IronChestType.values()[IronChestType.validateMeta(block.getMetaFromState(state))];
ModelManager modelmanager = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager();
if (block.getRenderType(state) != EnumBlockRenderType.INVISIBLE)
{
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();
float f = 0.1F;
AxisAlignedBB bb = block.getBoundingBox(state, world, pos);
double d0 = i + rand.nextDouble() * (bb.maxX - bb.minX - f * 2.0F) + f + bb.minX;
double d1 = j + rand.nextDouble() * (bb.maxY - bb.minY - f * 2.0F) + f + bb.minY;
double d2 = k + rand.nextDouble() * (bb.maxZ - bb.minZ - f * 2.0F) + f + bb.minZ;
if (side == EnumFacing.DOWN)
{
d1 = j + bb.minY - f;
}
if (side == EnumFacing.UP)
{
d1 = j + bb.maxY + f;
}
if (side == EnumFacing.NORTH)
{
d2 = k + bb.minZ - f;
}
if (side == EnumFacing.SOUTH)
{
d2 = k + bb.maxZ + f;
}
if (side == EnumFacing.WEST)
{
d0 = i + bb.minX - f;
}
if (side == EnumFacing.EAST)
{
d0 = i + bb.maxX + f;
}
EntityDiggingFX fx = ((EntityDiggingFX) Minecraft.getMinecraft().effectRenderer.spawnEffectParticle(EnumParticleTypes.BLOCK_CRACK.getParticleID(),
d0, d1, d2, 0.0D, 0.0D, 0.0D, Block.getIdFromBlock(state.getBlock())));
fx.setBlockPos(pos);
fx.multiplyVelocity(0.2F);
fx.multipleParticleScaleBy(0.6F);
if (type != IronChestType.DIRTCHEST9000 && type != IronChestType.OBSIDIAN)
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("ironchest:" + locations.get(type).getResourcePath()));
else if (type == IronChestType.DIRTCHEST9000)
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
else if (type == IronChestType.OBSIDIAN)
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
}
}
public static void addDestroyEffects(World world, BlockPos pos, IBlockState state)
{
state = state.getBlock().getActualState(state, world, pos);
int i = 4;
IronChestType type = IronChestType.values()[IronChestType.validateMeta(state.getBlock().getMetaFromState(state))];
ModelManager modelmanager = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager();
for (int j = 0; j < i; ++j)
{
for (int k = 0; k < i; ++k)
{
for (int l = 0; l < i; ++l)
{
double d0 = pos.getX() + (j + 0.5D) / i;
double d1 = pos.getY() + (k + 0.5D) / i;
double d2 = pos.getZ() + (l + 0.5D) / i;
EntityDiggingFX fx = ((EntityDiggingFX) Minecraft.getMinecraft().effectRenderer.spawnEffectParticle(
EnumParticleTypes.BLOCK_CRACK.getParticleID(), d0, d1, d2, d0 - pos.getX() - 0.5D, d1 - pos.getY() - 0.5D, d2 - pos.getZ() - 0.5D,
Block.getIdFromBlock(state.getBlock())));
fx.setBlockPos(pos);
if (type != IronChestType.DIRTCHEST9000 && type != IronChestType.OBSIDIAN)
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("ironchest:" + locations.get(type).getResourcePath()));
else if (type == IronChestType.DIRTCHEST9000)
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
else if (type == IronChestType.OBSIDIAN)
fx.setParticleTexture(modelmanager.getTextureMap().getAtlasSprite("minecraft:" + locations.get(type).getResourcePath()));
}
}
}
}
}