net.minecraft.world.explosion.Explosion Java Examples
The following examples show how to use
net.minecraft.world.explosion.Explosion.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KaboomHack.java From Wurst7 with GNU General Public License v3.0 | 6 votes |
@Override public void onUpdate() { // check fly-kick if(!MC.player.abilities.creativeMode && !MC.player.isOnGround()) return; // do explosion particles new Explosion(MC.world, MC.player, MC.player.getX(), MC.player.getY(), MC.player.getZ(), 6F, false, Explosion.DestructionType.NONE) .affectWorld(true); // get valid blocks ArrayList<BlockPos> blocks = getBlocksByDistanceReversed(6); // break all blocks for(int i = 0; i < power.getValueI(); i++) BlockBreaker.breakBlocksWithPacketSpam(blocks); // disable setEnabled(false); }
Example #2
Source File: ExplosionMixin.java From fabric-carpet with MIT License | 6 votes |
@Inject(method = "affectWorld", at = @At("HEAD"), cancellable = true) private void onExplosionB(boolean spawnParticles, CallbackInfo ci) { if (eLogger != null) { eLogger.setAffectBlocks( ! affectedBlocks.isEmpty()); eLogger.onExplosionDone(this.world.getTime()); } if (CarpetSettings.explosionNoBlockDamage) { affectedBlocks.clear(); } if (CarpetSettings.optimizedTNT) { OptimizedExplosion.doExplosionB((Explosion) (Object) this, spawnParticles); ci.cancel(); } }
Example #3
Source File: OptimizedExplosion.java From fabric-carpet with MIT License | 6 votes |
private static void getAffectedPositionsOnPlaneZ(Explosion e, int z, int xStart, int xEnd, int yStart, int yEnd) { if (!rayCalcDone) { final double zRel = (double) z / 15.0D * 2.0D - 1.0D; for (int x = xStart; x <= xEnd; ++x) { double xRel = (double) x / 15.0D * 2.0D - 1.0D; for (int y = yStart; y <= yEnd; ++y) { double yRel = (double) y / 15.0D * 2.0D - 1.0D; if (checkAffectedPosition(e, xRel, yRel, zRel)) { return; } } } } }
Example #4
Source File: OptimizedExplosion.java From fabric-carpet with MIT License | 6 votes |
private static void getAffectedPositionsOnPlaneY(Explosion e, int y, int xStart, int xEnd, int zStart, int zEnd) { if (!rayCalcDone) { final double yRel = (double) y / 15.0D * 2.0D - 1.0D; for (int z = zStart; z <= zEnd; ++z) { double zRel = (double) z / 15.0D * 2.0D - 1.0D; for (int x = xStart; x <= xEnd; ++x) { double xRel = (double) x / 15.0D * 2.0D - 1.0D; if (checkAffectedPosition(e, xRel, yRel, zRel)) { return; } } } } }
Example #5
Source File: OptimizedExplosion.java From fabric-carpet with MIT License | 6 votes |
private static void getAffectedPositionsOnPlaneX(Explosion e, int x, int yStart, int yEnd, int zStart, int zEnd) { if (!rayCalcDone) { final double xRel = (double) x / 15.0D * 2.0D - 1.0D; for (int z = zStart; z <= zEnd; ++z) { double zRel = (double) z / 15.0D * 2.0D - 1.0D; for (int y = yStart; y <= yEnd; ++y) { double yRel = (double) y / 15.0D * 2.0D - 1.0D; if (checkAffectedPosition(e, xRel, yRel, zRel)) { return; } } } } }
Example #6
Source File: ExplosionLogHelper.java From fabric-carpet with MIT License | 5 votes |
public ExplosionLogHelper(Entity entity, double x, double y, double z, float power, boolean createFire, Explosion.DestructionType blockDestructionType) { this.entity = entity; this.power = power; this.pos = new Vec3d(x,y,z); this.createFire = createFire; this.blockDestructionType = blockDestructionType; }
Example #7
Source File: ExplosionMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "collectBlocksAndDamageEntities", at = @At("HEAD"), cancellable = true) private void onExplosionA(CallbackInfo ci) { if (CarpetSettings.optimizedTNT) { OptimizedExplosion.doExplosionA((Explosion) (Object) this, eLogger); ci.cancel(); } }
Example #8
Source File: ExplosionMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "<init>(Lnet/minecraft/world/World;Lnet/minecraft/entity/Entity;DDDFZLnet/minecraft/world/explosion/Explosion$DestructionType;)V", at = @At(value = "RETURN")) private void onExplosionCreated(World world, Entity entity, double x, double y, double z, float power, boolean createFire, Explosion.DestructionType blockDestructionType, CallbackInfo ci) { if (LoggerRegistry.__explosions && ! world.isClient) { eLogger = new ExplosionLogHelper(entity, x, y, z, power, createFire, blockDestructionType); } }
Example #9
Source File: TntEntityMixin.java From fabric-carpet with MIT License | 5 votes |
@Inject(method = "explode", at = @At(value = "HEAD")) private void onExplode(CallbackInfo ci) { if (LoggerRegistry.__tnt && logHelper != null) logHelper.onExploded(getX(), getY(), getZ(), this.world.getTime()); if (mergedTNT > 1) for (int i = 0; i < mergedTNT - 1; i++) this.world.createExplosion(this, this.getX(), this.getY() + (double)(this.getHeight() / 16.0F), this.getZ(), 4.0F, Explosion.DestructionType.BREAK); }
Example #10
Source File: IForgeBlock.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
/** * Determines if this block should drop loot when exploded. */ default boolean canDropFromExplosion(BlockState state, BlockView world, BlockPos pos, Explosion explosion) { return state.getBlock().shouldDropItemsOnExplosion(explosion); }
Example #11
Source File: OptimizedExplosion.java From fabric-carpet with MIT License | 4 votes |
private static void rayCalcs(Explosion e) { ExplosionAccessor eAccess = (ExplosionAccessor) e; boolean first = true; for (int j = 0; j < 16; ++j) { for (int k = 0; k < 16; ++k) { for (int l = 0; l < 16; ++l) { if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) { double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F); double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F); double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F); double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); d0 = d0 / d3; d1 = d1 / d3; d2 = d2 / d3; float rand = eAccess.getWorld().random.nextFloat(); if (CarpetSettings.tntRandomRange >= 0) { rand = (float) CarpetSettings.tntRandomRange; } float f = eAccess.getPower() * (0.7F + rand * 0.6F); double d4 = eAccess.getX(); double d6 = eAccess.getY(); double d8 = eAccess.getZ(); for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) { BlockPos blockpos = new BlockPos(d4, d6, d8); BlockState state = eAccess.getWorld().getBlockState(blockpos); FluidState fluidState = eAccess.getWorld().getFluidState(blockpos); if (state.getMaterial() != Material.AIR) { float f2 = Math.max(state.getBlock().getBlastResistance(), fluidState.getBlastResistance()); if (eAccess.getEntity() != null) f2 = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), blockpos, state, fluidState, f2); f -= (f2 + 0.3F) * 0.3F; } if (f > 0.0F && (eAccess.getEntity() == null || eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), blockpos, state, f))) { affectedBlockPositionsSet.add(blockpos); } else if (first) { return; } first = false; d4 += d0 * 0.30000001192092896D; d6 += d1 * 0.30000001192092896D; d8 += d2 * 0.30000001192092896D; } } } } } }
Example #12
Source File: IForgeBlockState.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
/** * Determines if this block should drop loot when exploded. */ default boolean canDropFromExplosion(BlockView world, BlockPos pos, Explosion explosion) { return patchwork$getForgeBlock().canDropFromExplosion(getBlockState(), world, pos, explosion); }
Example #13
Source File: OptimizedExplosion.java From fabric-carpet with MIT License | 4 votes |
private static boolean checkAffectedPosition(Explosion e, double xRel, double yRel, double zRel) { ExplosionAccessor eAccess = (ExplosionAccessor) e; double len = Math.sqrt(xRel * xRel + yRel * yRel + zRel * zRel); double xInc = (xRel / len) * 0.3; double yInc = (yRel / len) * 0.3; double zInc = (zRel / len) * 0.3; float rand = eAccess.getWorld().random.nextFloat(); float sizeRand = (CarpetSettings.tntRandomRange >= 0 ? (float) CarpetSettings.tntRandomRange : rand); float size = eAccess.getPower() * (0.7F + sizeRand * 0.6F); double posX = eAccess.getX(); double posY = eAccess.getY(); double posZ = eAccess.getZ(); for (float f1 = 0.3F; size > 0.0F; size -= 0.22500001F) { posMutable.set(posX, posY, posZ); // Don't query already cached positions again from the world BlockState state = stateCache.get(posMutable); FluidState fluid = fluidCache.get(posMutable); BlockPos posImmutable = null; if (state == null) { posImmutable = posMutable.toImmutable(); state = eAccess.getWorld().getBlockState(posImmutable); stateCache.put(posImmutable, state); fluid = eAccess.getWorld().getFluidState(posImmutable); fluidCache.put(posImmutable, fluid); } if (state.getMaterial() != Material.AIR) { float resistance = Math.max(state.getBlock().getBlastResistance(), fluid.getBlastResistance()); if (eAccess.getEntity() != null) { resistance = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), posMutable, state, fluid, resistance); } size -= (resistance + 0.3F) * 0.3F; } if (size > 0.0F && (eAccess.getEntity() == null || eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), posMutable, state, size))) { affectedBlockPositionsSet.add(posImmutable != null ? posImmutable : posMutable.toImmutable()); } else if (firstRay) { rayCalcDone = true; return true; } firstRay = false; posX += xInc; posY += yInc; posZ += zInc; } return false; }
Example #14
Source File: OptimizedExplosion.java From fabric-carpet with MIT License | 4 votes |
private static void blastCalc(Explosion e){ ExplosionAccessor eAccess = (ExplosionAccessor) e; if(blastChanceLocation == null || blastChanceLocation.getSquaredDistance(eAccess.getX(), eAccess.getY(), eAccess.getZ(), false) > 200) return; chances.clear(); for (int j = 0; j < 16; ++j) { for (int k = 0; k < 16; ++k) { for (int l = 0; l < 16; ++l) { if (j == 0 || j == 15 || k == 0 || k == 15 || l == 0 || l == 15) { double d0 = (double) ((float) j / 15.0F * 2.0F - 1.0F); double d1 = (double) ((float) k / 15.0F * 2.0F - 1.0F); double d2 = (double) ((float) l / 15.0F * 2.0F - 1.0F); double d3 = Math.sqrt(d0 * d0 + d1 * d1 + d2 * d2); d0 = d0 / d3; d1 = d1 / d3; d2 = d2 / d3; float f = eAccess.getPower() * (0.7F + 0.6F); double d4 = eAccess.getX(); double d6 = eAccess.getY(); double d8 = eAccess.getZ(); boolean found = false; for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) { BlockPos blockpos = new BlockPos(d4, d6, d8); BlockState state = eAccess.getWorld().getBlockState(blockpos); FluidState fluidState = eAccess.getWorld().getFluidState(blockpos); if (state.getMaterial() != Material.AIR) { float f2 = Math.max(state.getBlock().getBlastResistance(), fluidState.getBlastResistance()); if (eAccess.getEntity() != null) f2 = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), blockpos, state, fluidState, f2); f -= (f2 + 0.3F) * 0.3F; } if (f > 0.0F && (eAccess.getEntity() == null || eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), blockpos, state, f))) { if(!found && blockpos.equals(blastChanceLocation)){ chances.add(f); found = true; } } d4 += d0 * 0.30000001192092896D; d6 += d1 * 0.30000001192092896D; d8 += d2 * 0.30000001192092896D; } } } } } showTNTblastChance(e); }
Example #15
Source File: OptimizedExplosion.java From fabric-carpet with MIT License | 4 votes |
private static void showTNTblastChance(Explosion e){ ExplosionAccessor eAccess = (ExplosionAccessor) e; double randMax = 0.6F * eAccess.getPower(); double total = 0; boolean fullyBlownUp = false; boolean first = true; int rays = 0; for(float f3 : chances){ rays++; double calc = f3 - randMax; if(calc > 0) fullyBlownUp = true; double chancePerRay = (Math.abs(calc) / randMax); if(!fullyBlownUp){ if(first){ first = false; total = chancePerRay; }else { total = total * chancePerRay; } } } if(fullyBlownUp) total = 0; double chance = 1 - total; NumberFormat nf = NumberFormat.getNumberInstance(); nf.setRoundingMode (RoundingMode.DOWN); nf.setMaximumFractionDigits(2); for(PlayerEntity player : eAccess.getWorld().getPlayers()){ Messenger.m(player,"w Pop: ", "c " + nf.format(chance) + " ", "^w Chance for the block to be destroyed by the blast: " + chance, "?" + chance, "w Remain: ", String.format("c %.2f ", total), "^w Chance the block survives the blast: " + total, "?" + total, "w Rays: ", String.format("c %d ", rays), "^w TNT blast rays going through the block", "?" + rays, "w Size: ", String.format("c %.1f ", eAccess.getPower()), "^w TNT blast size", "?" + eAccess.getPower(), "w @: ", String.format("c [%.1f %.1f %.1f] ", eAccess.getX(), eAccess.getY(), eAccess.getZ()), "^w TNT blast location X:" + eAccess.getX() + " Y:" + eAccess.getY() + " Z:" + eAccess.getZ(), "?" + eAccess.getX() + " " + eAccess.getY() + " " + eAccess.getZ() ); } }
Example #16
Source File: PumpcownEntity.java From the-hallow with MIT License | 4 votes |
@Override public boolean interactMob(PlayerEntity player, Hand hand) { ItemStack stack = player.getStackInHand(hand); if (stack.getItem() == Items.SHEARS && this.getBreedingAge() >= 0) { this.world.addParticle(ParticleTypes.EXPLOSION, this.getX(), this.getY() + (double) (this.getHeight() / 2.0F), this.getZ(), 0.0D, 0.0D, 0.0D); if (!this.world.isClient) { this.remove(); if (this.world.getDimension().getType() == HallowedDimensions.THE_HALLOW) { this.world.createExplosion(this, this.getX(), this.getY(), this.getZ(), 3.0F, Explosion.DestructionType.BREAK); } else { CowEntity cow = EntityType.COW.create(this.world); cow.updatePositionAndAngles(this.getX(), this.getY(), this.getZ(), this.yaw, this.pitch); cow.setHealth(this.getHealth()); cow.bodyYaw = this.bodyYaw; if (this.hasCustomName()) { cow.setCustomName(this.getCustomName()); } this.world.spawnEntity(cow); } for (int i = 0; i < 5; ++i) { this.world.spawnEntity(new ItemEntity(this.world, this.getX(), this.getY() + (double) this.getHeight(), this.getZ(), new ItemStack(STEM_FEATURE.getBlock()))); } stack.damage(1, player, ((player_1) -> { player_1.sendToolBreakStatus(hand); })); this.playSound(SoundEvents.ENTITY_MOOSHROOM_SHEAR, 1.0F, 1.0F); } return true; } else if (stack.getItem() == Items.BOWL && this.getBreedingAge() >= 0 && !player.abilities.creativeMode) { stack.decrement(1); ItemStack stew = new ItemStack(HallowedItems.PUMPKIN_STEW); if (stack.isEmpty()) { player.setStackInHand(hand, stew); } else if (!player.inventory.insertStack(stew)) { player.dropItem(stew, false); } this.playSound(SoundEvents.ENTITY_MOOSHROOM_MILK, 1.0F, 1.0F); return true; } else { return super.interactMob(player, hand); } }
Example #17
Source File: ExplosionAccessor.java From fabric-carpet with MIT License | 4 votes |
@Accessor Explosion.DestructionType getBlockDestructionType();
Example #18
Source File: IForgeBlock.java From patchwork-api with GNU Lesser General Public License v2.1 | 2 votes |
/** * Location sensitive version of getExplosionResistance. * * @param state The current state * @param world The current world * @param pos Block position in world * @param exploder The entity that caused the explosion, can be null * @param explosion The explosion * @return The amount of the explosion absorbed. */ default float getExplosionResistance(BlockState state, CollisionView world, BlockPos pos, @Nullable Entity exploder, Explosion explosion) { return this.getBlock().getBlastResistance(); }
Example #19
Source File: IForgeBlock.java From patchwork-api with GNU Lesser General Public License v2.1 | 2 votes |
/** * Called when the block is destroyed by an explosion. * Useful for allowing the block to take into account block entities, * state, etc. when exploded, before it is removed. * * @param world The current world * @param pos Block position in world * @param explosion The explosion instance affecting the block */ default void onBlockExploded(BlockState state, World world, BlockPos pos, Explosion explosion) { world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3); getBlock().onDestroyedByExplosion(world, pos, explosion); }
Example #20
Source File: IForgeBlockState.java From patchwork-api with GNU Lesser General Public License v2.1 | 2 votes |
/** * Called when the block is destroyed by an explosion. * Useful for allowing the block to take into account tile entities, * state, etc. when exploded, before it is removed. * * @param world The current world * @param pos Block position in world * @param explosion The explosion instance affecting the block */ default void onBlockExploded(World world, BlockPos pos, Explosion explosion) { patchwork$getForgeBlock().onBlockExploded(getBlockState(), world, pos, explosion); }
Example #21
Source File: IForgeBlockState.java From patchwork-api with GNU Lesser General Public License v2.1 | 2 votes |
/** * Location sensitive version of getExplosionResistance. * * @param world The current world * @param pos Block position in world * @param exploder The entity that caused the explosion, can be null * @param explosion The explosion * @return The amount of the explosion absorbed. */ default float getExplosionResistance(CollisionView world, BlockPos pos, @Nullable Entity exploder, Explosion explosion) { return patchwork$getForgeBlock().getExplosionResistance(getBlockState(), world, pos, exploder, explosion); }