下面列出了怎么用net.minecraft.util.EnumParticleTypes的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Handler for {@link World#setEntityState}
*/
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id) {
if (id == 0) {
int i = this.getColor();
if (i != -1) {
double d0 = (double) (i >> 16 & 255) / 255.0D;
double d1 = (double) (i >> 8 & 255) / 255.0D;
double d2 = (double) (i >> 0 & 255) / 255.0D;
for (int j = 0; j < 20; ++j) {
this.world.spawnParticle(EnumParticleTypes.SPELL_MOB, this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.width, this.posY + this.rand.nextDouble() * (double) this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.width, d0, d1, d2);
}
}
} else {
super.handleStatusUpdate(id);
}
}
/**
* Called when this EntityThrowable hits a block or entity.
*/
@Override
protected void onImpact(RayTraceResult par1MovingObjectPosition) {
Entity entityHit = par1MovingObjectPosition.entityHit;
if (entityHit == this.ignoreEntity && this.age < 5) {
return;
}
if (par1MovingObjectPosition.entityHit != null) {
double d = this.getDamage();
d *= this.isCrit ? 2.5D : 1.0D;
entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float) d);
if (entityHit instanceof EntityLivingBase) {
EntityLivingBase entityLivivng = (EntityLivingBase) entityHit;
entityLivivng.hurtResistantTime = entityLivivng.maxHurtResistantTime / 2;
}
for (int i = 0; i < 3; ++i) {
this.world.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
}
if (!this.world.isRemote) {
this.setDead();
}
}
@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if (isUnderWeight(worldIn, pos)) {
if (canFerm(stateIn)) {
if (rand.nextInt(5) == 0) {
double d4 = rand.nextBoolean() ? 0.8 : -0.8;
double d0 = ((float) pos.getX() + 0.5 + (rand.nextFloat() * d4));
double d1 = (double) ((float) pos.getY() + rand.nextFloat());
double d2 = ((float) pos.getZ() + 0.5 + rand.nextFloat() * d4);
worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
}
}
@SideOnly(Side.CLIENT)
@Override
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if (isUnderWeight(worldIn, pos)) {
if (canFerm(stateIn)) {
if (rand.nextInt(5) == 0) {
double d4 = rand.nextBoolean() ? 0.8 : -0.8;
double d0 = ((float) pos.getX() + 0.5 + (rand.nextFloat() * d4));
double d1 = (double) ((float) pos.getY() + rand.nextFloat());
double d2 = ((float) pos.getZ() + 0.5 + rand.nextFloat() * d4);
worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
}
}
@Override
protected void onImpact(RayTraceResult impact) {
if (impact.entityHit != null) {
impact.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), 0.0F);
}
if (!world.isRemote && rand.nextInt(8) == 0) {
EntityOwl entitychicken = new EntityOwl(world);
entitychicken.setGrowingAge(-24000);
entitychicken.setLocationAndAngles(posX, posY, posZ, rotationYaw, 0.0F);
world.spawnEntity(entitychicken);
}
for (int i = 0; i < 8; ++i) {
world.spawnParticle(EnumParticleTypes.ITEM_CRACK, posX, posY, posZ, (rand.nextFloat() - 0.5D) * 0.08D,
(rand.nextFloat() - 0.5D) * 0.08D, (rand.nextFloat() - 0.5D) * 0.08D, new int[] { Item.getIdFromItem(EnderZoo.itemOwlEgg) });
}
if (!world.isRemote) {
setDead();
}
}
@Override
public void onLivingUpdate() {
super.onLivingUpdate();
for (int side = 0; side < 4; ++side) {
int x = MathHelper.floor(posX + (double) ((float) (side % 2 * 2 - 1) * 0.25F));
int y = MathHelper.floor(posY);
int z = MathHelper.floor(posZ + (double) ((float) (side / 2 % 2 * 2 - 1) * 0.25F));
BlockPos pos = new BlockPos(x, y, z);
if (world.getBlockState(pos).getBlock() == Blocks.AIR
&& world.getBiome(pos).getTemperature(pos) < 2F
&& Blocks.SNOW_LAYER.canPlaceBlockAt(world, pos)) {
double randX = (double) ((float) posX + rand.nextFloat());
double randY = (double) ((float) posY + rand.nextFloat());
double randZ = (double) ((float) posZ + rand.nextFloat());
world.spawnParticle(EnumParticleTypes.SNOWBALL, randX, randY, randZ, 0.0D, 0.0D, 0.0D);
world.setBlockState(pos, Blocks.SNOW_LAYER.getDefaultState());
}
}
}
public static void spawnParticlesAround(World world, EnumParticleTypes type, BlockPos pos, int count, Random rand)
{
for (int i = 0; i < count; ++i)
{
int i1 = rand.nextInt(2) * 2 - 1;
int j1 = rand.nextInt(2) * 2 - 1;
double x1 = (double)pos.getX() + 0.5D + 0.25D * (double)i1;
double y1 = (double)((float)pos.getY() + rand.nextFloat());
double z1 = (double)pos.getZ() + 0.5D + 0.25D * (double)j1;
double vx = (double)(rand.nextFloat() * 1.0F * (float)i1);
double vy = ((double)rand.nextFloat() - 0.5D) * 0.125D;
double vz = (double)(rand.nextFloat() * 1.0F * (float)j1);
world.spawnParticle(type, x1, y1, z1, vx, vy, vz);
}
}
@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand)
{
TileEntityEnderFurnace te = getTileEntitySafely(world, pos, TileEntityEnderFurnace.class);
if (te != null && te.isBurningLast)
{
Effects.spawnParticlesAround(world, EnumParticleTypes.PORTAL, pos, 2, rand);
if (rand.nextDouble() < 0.1D)
{
world.playSound((double)pos.getX() + 0.5D, (double)pos.getY(), (double)pos.getZ() + 0.5D,
SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1.0F, 1.0F, false);
}
}
}
@Override
protected boolean spawnCustomParticles() {
int i = this.getSlimeSize();
for (int j = 0; j < i * 8; ++j) {
float f = this.rand.nextFloat() * ((float) Math.PI * 2F);
float f1 = this.rand.nextFloat() * 0.5F + 0.5F;
float f2 = MathHelper.sin(f) * (float) i * 0.5F * f1;
float f3 = MathHelper.cos(f) * (float) i * 0.5F * f1;
World world = this.world;
EnumParticleTypes enumparticletypes = this.getParticleType();
double d0 = this.posX + (double) f2;
double d1 = this.posZ + (double) f3;
world.spawnParticle(enumparticletypes, d0, this.getEntityBoundingBox().minY, d1, 0.0D, 0.0D, 0.0D, Block.getStateId(Blocks.DIRT.getDefaultState()));
}
return true;
}
private void ensureCompiled() {
if (!this.codeChanged) return;
FMLLog.fine("Eval my code: %s", this.code);
// now execute the code
try {
PythonEngine.eval(this.code, this.context);
if (!world.isRemote) {
((WorldServer)world).spawnParticle(EnumParticleTypes.CRIT,
pos.getX() + .5, pos.getY() + 1, pos.getZ() + .5,
20, 0, 0, 0, .5, new int[0]);
}
} catch (ScriptException e) {
failz0r(world, pos, "Error running code, traceback:\n%s", stackTraceToString(e));
}
this.codeChanged = false;
}
@SideOnly(Side.CLIENT)
@Override
public void randomTickDisplay(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if (this.isActive) {
if (rand.nextInt(16) == 0) {
worldIn.playSound((double) ((float) pos.getX() + 0.5F), (double) ((float) pos.getY()
+ 0.5F), (double) ((float) pos.getZ()
+ 0.5F), SoundEvents.BLOCK_FIRE_AMBIENT, SoundCategory.BLOCKS, 1.0F
+ rand.nextFloat(), rand.nextFloat() * 0.7F + 0.3F, false);
}
for (int i = 0; i < 3; ++i) {
double d0 = (double) pos.getX() + rand.nextDouble();
double d1 = (double) pos.getY() + rand.nextDouble() * 0.5D + 0.5D;
double d2 = (double) pos.getZ() + rand.nextDouble();
worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
}
@Override
protected void onImpact(RayTraceResult result)
{
if (result.entityHit != null)
{
result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, getThrower()), (int) (Math.random() * (4.0F / 3.0F)));
}
else if (!world.isRemote)
{
setDead();
if(stack != null)
{
world.spawnEntity(new EntityItem(world, posX, posY, posZ, stack));
}
}
for (int j = 0; j < 8; ++j)
{
world.spawnParticle(EnumParticleTypes.BLOCK_CRACK, posX, posY, posZ, 0.0D, 0.0D, 0.0D, new int[] { Block.getStateId(Blocks.STONE.getDefaultState()) });
}
}
public boolean isCartApplicable(World world, EntityMinecart cart, Pattern destinationRegex){
for(EnumFacing dir : EnumFacing.VALUES) {
BlockPos neighborPos = getPos().getPos().offset(dir);
if(world.isBlockLoaded(neighborPos)) {
TileEntity te = world.getTileEntity(neighborPos);
if(te != null) {
CapabilityDestinationProvider cap = te.getCapability(CapabilityDestinationProvider.INSTANCE, null);
if(cap != null && cap.isCartApplicable(te, cart, destinationRegex)) {
for(int i = 0; i < 10; i++) {
double x = getPos().getPos().getX() + world.rand.nextDouble();
double z = getPos().getPos().getZ() + world.rand.nextDouble();
NetworkHandler.sendToAllAround(new PacketSpawnParticle(EnumParticleTypes.ENCHANTMENT_TABLE, x, getPos().getPos().getY() + 1, z, dir.getFrontOffsetX(), dir.getFrontOffsetY(), dir.getFrontOffsetZ()), world);
}
return true;
}
}
}
}
return false;
}
@Override
public void updateTask() {
super.updateTask();
--this.shottick;
if (this.shottick == 60 || this.shottick == 80) {
EntityTofuGandlem.this.playSound(SoundEvents.BLOCK_IRON_TRAPDOOR_OPEN, 2.0F, 1.4F);
((WorldServer) EntityTofuGandlem.this.world).spawnParticle(EnumParticleTypes.CRIT, EntityTofuGandlem.this.posX, EntityTofuGandlem.this.posY, EntityTofuGandlem.this.posZ, 15, 0.2D, 0.2D, 0.2D, 0.0D);
}
if (this.shottick <= 20) {
if (EntityTofuGandlem.this.ticksExisted % 5 == 0) {
for (int i = 0; i < 6; i++) {
EntityThrowable projectile = new EntityFukumame(EntityTofuGandlem.this.world, EntityTofuGandlem.this);
Vec3d vec3d = EntityTofuGandlem.this.getLook(1.0F);
playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 3.0F, 1.0F / (EntityTofuGandlem.this.getRNG().nextFloat() * 0.4F + 0.8F));
projectile.setLocationAndAngles(EntityTofuGandlem.this.posX + vec3d.x * 1.3D, EntityTofuGandlem.this.posY + (EntityTofuGandlem.this.getEyeHeight() / 2), EntityTofuGandlem.this.posZ + vec3d.z * 1.2D, EntityTofuGandlem.this.rotationYaw, EntityTofuGandlem.this.rotationPitch);
float d0 = (EntityTofuGandlem.this.rand.nextFloat() * 12.0F) - 6.0F;
projectile.shoot(EntityTofuGandlem.this, EntityTofuGandlem.this.rotationPitch, EntityTofuGandlem.this.rotationYaw + d0, 0.0F, 1.5f, 0.8F);
EntityTofuGandlem.this.world.spawnEntity(projectile);
}
}
}
}
@SideOnly(Side.CLIENT)
public void handleStatusUpdate(byte id) {
if (id == 12) {
this.spawnParticles(EnumParticleTypes.HEART);
} else if (id == 13) {
this.spawnParticles(EnumParticleTypes.VILLAGER_ANGRY);
} else if (id == 14) {
this.spawnParticles(EnumParticleTypes.VILLAGER_HAPPY);
} else {
super.handleStatusUpdate(id);
}
}
private void spawnPotionParticles(int particleCount) {
int i = this.getColor();
if (i != -1 && particleCount > 0) {
double d0 = (double) (i >> 16 & 255) / 255.0D;
double d1 = (double) (i >> 8 & 255) / 255.0D;
double d2 = (double) (i >> 0 & 255) / 255.0D;
for (int j = 0; j < particleCount; ++j) {
this.world.spawnParticle(EnumParticleTypes.SPELL_MOB, this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.width, this.posY + this.rand.nextDouble() * (double) this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.width, d0, d1, d2);
}
}
}
/**
* Called to update the entity's position/logic.
*/
public void onUpdate() {
super.onUpdate();
if (this.world.isRemote && !this.inGround) {
this.world.spawnParticle(EnumParticleTypes.SPELL_INSTANT, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
}
}
@Override
public void onUpdate() {
super.onUpdate();
++this.age;
if (!this.inGround && this.isCrit) {
for (int l = 0; l < 2; ++l) {
this.world.spawnParticle(EnumParticleTypes.CRIT, this.posX + this.motionX * l / 2.0D, this.posY + this.motionY * l / 2.0D, this.posZ + this.motionZ * l / 2.0D, -this.motionX, -this.motionY + 0.2D, -this.motionZ);
}
}
}
@Override
@SideOnly(Side.CLIENT)
public void preInit(FMLPreInitializationEvent evt) {
/**
* Backward register all particle effects
*/
//Look up for particle factory and pass it into BWEntityFX
for (EnumParticleTypes type : EnumParticleTypes.values()) {
Game.entities().register(Game.info().name + ":" + type.getParticleName(), () -> new BWEntityFX(type.getParticleID()));
}
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
double d0 = pos.getX() + 0.5D;
double d1 = pos.getY() + 0.5D;
double d2 = pos.getZ() + 0.5D;
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
worldIn.spawnParticle(EnumParticleTypes.FLAME, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos,
EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if (worldIn.getBlockState(pos).getBlock() == Blocks.ICE && worldIn.isBlockModifiable(player, pos))
{
if (worldIn.isRemote == false)
{
int num = 8;
float velocity = 0.2f;
// The Super variant (meta = 1) doesn't cause a block update
int flag = player.getHeldItem(hand).getMetadata() == 1 ? 2 : 3;
if (worldIn.provider.doesWaterVaporize() == false)
{
worldIn.setBlockState(pos, Blocks.WATER.getDefaultState(), flag);
}
else
{
worldIn.setBlockToAir(pos);
num = 32;
velocity = 0.4f;
}
Effects.spawnParticlesFromServer(worldIn.provider.getDimension(), pos.up(), EnumParticleTypes.SMOKE_LARGE, num, 0.5f, velocity);
worldIn.playSound(null, player.getPosition(), SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.MASTER, 0.8f, 1.0f);
}
return EnumActionResult.SUCCESS;
}
return EnumActionResult.PASS;
}
public static void quickStackToInventories(World world, EntityPlayer player, long enabledSlotsMask,
List<BlockPosDistance> positions, FilterSettings filter)
{
IItemHandler playerInv = player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
boolean movedSome = false;
for (BlockPosDistance posDist : positions)
{
TileEntity te = world.getTileEntity(posDist.pos);
if (te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP))
{
IItemHandler inv = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP);
if (inv != null)
{
Result result = quickStackItems(playerInv, inv, enabledSlotsMask, player.isSneaking() == false, filter);
if (result != Result.MOVED_NONE)
{
Effects.spawnParticlesFromServer(world.provider.getDimension(), posDist.pos, EnumParticleTypes.VILLAGER_HAPPY);
movedSome = true;
}
if (result == Result.MOVED_ALL)
{
break;
}
}
}
}
if (movedSome)
{
world.playSound(null, player.getPosition(), SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.MASTER, 0.5f, 1.8f);
}
}
public void destroyNetwork(boolean isLeaking, boolean isBurning) {
World world = worldData.getWorld();
((WorldFluidPipeNet) (Object) worldData).removePipeNet(this);
for (BlockPos nodePos : getAllNodes().keySet()) {
TileEntity tileEntity = world.getTileEntity(nodePos);
if (tileEntity instanceof TileEntityFluidPipe) {
if (isBurning) {
world.setBlockState(nodePos, Blocks.FIRE.getDefaultState());
} else {
world.setBlockToAir(nodePos);
}
} else if (GTValues.isModLoaded(GTValues.MODID_FMP)) {
removeMultipartPipePartFromTile(tileEntity);
}
Random random = world.rand;
if (isBurning) {
TileEntityFluidPipe.spawnParticles(world, nodePos, EnumFacing.UP,
EnumParticleTypes.FLAME, 3 + random.nextInt(2), random);
if (random.nextInt(4) == 0) {
TileEntityFluidPipe.setNeighboursToFire(world, nodePos);
}
}
if (isLeaking) {
if (world.rand.nextInt(isBurning ? 3 : 7) == 0) {
world.createExplosion(null,
nodePos.getX() + 0.5, nodePos.getY() + 0.5, nodePos.getZ() + 0.5,
1.0f + world.rand.nextFloat(), false);
}
}
}
}
public TaskPositionDebug(World world, List<BlockPos> positions, IBlockState blockState, int blocksPerTick,
boolean placeBlocks, boolean useParticles, EnumParticleTypes particle)
{
this.dimension = world.provider.getDimension();
this.positions = positions;
this.blockState = blockState;
this.blocksPerTick = blocksPerTick;
this.placeBlocks = placeBlocks;
this.useParticles = useParticles;
this.particle = particle;
this.listIndex = 0;
this.count = 0;
}
@Override
@SideOnly(Side.CLIENT)
public void randomTickDisplay(IBlockState stateIn, World worldIn, BlockPos pos, Random rand) {
if (this.isActive) {
for (int i = 0; i < 3; ++i) {
double d0 = (double) pos.getX() + rand.nextDouble();
double d1 = (double) pos.getY() + .5D + rand.nextDouble() * 0.5D + 0.5D;
double d2 = (double) pos.getZ() + rand.nextDouble();
worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
}
@Override
public void onUpdate() {
if (this.world.isRemote || this.world.isBlockLoaded(new BlockPos(this))) {
super.onUpdate();
++this.ticksInAir;
RayTraceResult raytraceresult = ProjectileHelper.forwardsRaycast(this, true, this.ticksInAir >= 25, this.shootingEntity);
if (raytraceresult != null && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, raytraceresult)) {
this.onImpact(raytraceresult);
}
this.posX += this.motionX;
this.posY += this.motionY;
this.posZ += this.motionZ;
ProjectileHelper.rotateTowardsMovement(this, 0.2F);
float f = this.getMotionFactor();
if (this.isInWater()) {
for (int i = 0; i < 4; ++i) {
this.world.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX - this.motionX * 0.25D, this.posY - this.motionY * 0.25D, this.posZ - this.motionZ * 0.25D, this.motionX, this.motionY, this.motionZ);
}
f = 0.8F;
}
this.motionX += this.accelerationX;
this.motionY += this.accelerationY;
this.motionZ += this.accelerationZ;
this.motionX *= f;
this.motionY *= f;
this.motionZ *= f;
this.setPosition(this.posX, this.posY, this.posZ);
} else {
this.setDead();
}
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
{
if ((worldIn.isRainingAt(pos.up())) && (!worldIn.getBlockState(pos.down()).isFullyOpaque()) && (rand.nextInt(15) == 1))
{
double d0 = pos.getX() + rand.nextFloat();
double d1 = pos.getY() - 0.05D;
double d2 = pos.getZ() + rand.nextFloat();
worldIn.spawnParticle(EnumParticleTypes.DRIP_WATER, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
}
}
private void spawnParticles(double xSpeed, double ySpeed, double zSpeed) {
if (this.world.isRemote) {
for (int i = 0; i < 32; ++i) {
world.spawnParticle(EnumParticleTypes.PORTAL, posX, posY, posZ, xSpeed, ySpeed, zSpeed, new int[0]);
}
} else {
this.world.setEntityState(this, (byte) 42);
}
}
@SideOnly(Side.CLIENT)
protected void spawnWitchParticles() {
for (int i = 0; i < this.rand.nextInt(35) + 10; ++i) {
this.world.spawnParticle(EnumParticleTypes.SPELL_WITCH, this.posX + this.rand.nextGaussian() * 0.12999999523162842D,
this.getEntityBoundingBox().maxY + 0.5D + this.rand.nextGaussian() * 0.12999999523162842D,
this.posZ + this.rand.nextGaussian() * 0.12999999523162842D, 0.0D, 0.0D, 0.0D, new int[0]);
}
}
private void spawnParticles(double xSpeed, double ySpeed, double zSpeed) {
// TODO figure out how to spawn particles
if (this.world.isRemote) {
for (int i = 0; i < 32; ++i) {
world.spawnParticle(EnumParticleTypes.PORTAL, posX, posY, posZ, xSpeed, ySpeed, zSpeed, new int[0]);
}
} else {
this.world.setEntityState(this, (byte) 42);
}
}