126 lines
4.7 KiB
Java
126 lines
4.7 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.core.particles.ParticleOptions;
|
|
import net.minecraft.core.particles.BlockParticleOption;
|
|
import net.minecraft.core.particles.ParticleTypes;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.minecraft.advancements.CriteriaTriggers;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.sounds.SoundEvents;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.phys.shapes.CollisionContext;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.entity.vehicle.Boat;
|
|
import net.minecraft.world.entity.item.PrimedTnt;
|
|
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
|
import net.minecraft.world.entity.LivingEntity;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.phys.shapes.VoxelShape;
|
|
|
|
public class HoneyBlock extends HalfTransparentBlock {
|
|
protected static final VoxelShape SHAPE;
|
|
|
|
public HoneyBlock(final Properties c) {
|
|
super(c);
|
|
}
|
|
|
|
private static boolean doesEntityDoHoneyBlockSlideEffects(final Entity akn) {
|
|
return akn instanceof LivingEntity || akn instanceof AbstractMinecart || akn instanceof PrimedTnt || akn instanceof Boat;
|
|
}
|
|
|
|
@Override
|
|
public VoxelShape getCollisionShape(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final CollisionContext cvn) {
|
|
return HoneyBlock.SHAPE;
|
|
}
|
|
|
|
@Override
|
|
public void fallOn(final Level bjt, final BlockPos fk, final Entity akn, final float float4) {
|
|
akn.playSound(SoundEvents.HONEY_BLOCK_SLIDE, 1.0f, 1.0f);
|
|
if (!bjt.isClientSide) {
|
|
bjt.broadcastEntityEvent(akn, (byte)54);
|
|
}
|
|
if (akn.causeFallDamage(float4, 0.2f)) {
|
|
akn.playSound(this.soundType.getFallSound(), this.soundType.getVolume() * 0.5f, this.soundType.getPitch() * 0.75f);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void entityInside(final BlockState byg, final Level bjt, final BlockPos fk, final Entity akn) {
|
|
if (this.isSlidingDown(fk, akn)) {
|
|
this.maybeDoSlideAchievement(akn, fk);
|
|
this.doSlideMovement(akn);
|
|
this.maybeDoSlideEffects(bjt, akn);
|
|
}
|
|
super.entityInside(byg, bjt, fk, akn);
|
|
}
|
|
|
|
private boolean isSlidingDown(final BlockPos fk, final Entity akn) {
|
|
if (akn.onGround) {
|
|
return false;
|
|
}
|
|
if (akn.getY() > fk.getY() + 0.9375 - 1.0E-7) {
|
|
return false;
|
|
}
|
|
if (akn.getDeltaMovement().y >= -0.08) {
|
|
return false;
|
|
}
|
|
final double double4 = Math.abs(fk.getX() + 0.5 - akn.getX());
|
|
final double double5 = Math.abs(fk.getZ() + 0.5 - akn.getZ());
|
|
final double double6 = 0.4375 + akn.getBbWidth() / 2.0f;
|
|
return double4 + 1.0E-7 > double6 || double5 + 1.0E-7 > double6;
|
|
}
|
|
|
|
private void maybeDoSlideAchievement(final Entity akn, final BlockPos fk) {
|
|
if (akn instanceof ServerPlayer && akn.level.getGameTime() % 20L == 0L) {
|
|
CriteriaTriggers.HONEY_BLOCK_SLIDE.trigger((ServerPlayer)akn, akn.level.getBlockState(fk));
|
|
}
|
|
}
|
|
|
|
private void doSlideMovement(final Entity akn) {
|
|
final Vec3 cvi3 = akn.getDeltaMovement();
|
|
if (cvi3.y < -0.13) {
|
|
final double double4 = -0.05 / cvi3.y;
|
|
akn.setDeltaMovement(new Vec3(cvi3.x * double4, -0.05, cvi3.z * double4));
|
|
}
|
|
else {
|
|
akn.setDeltaMovement(new Vec3(cvi3.x, -0.05, cvi3.z));
|
|
}
|
|
akn.fallDistance = 0.0f;
|
|
}
|
|
|
|
private void maybeDoSlideEffects(final Level bjt, final Entity akn) {
|
|
if (doesEntityDoHoneyBlockSlideEffects(akn)) {
|
|
if (bjt.random.nextInt(5) == 0) {
|
|
akn.playSound(SoundEvents.HONEY_BLOCK_SLIDE, 1.0f, 1.0f);
|
|
}
|
|
if (!bjt.isClientSide && bjt.random.nextInt(5) == 0) {
|
|
bjt.broadcastEntityEvent(akn, (byte)53);
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void showSlideParticles(final Entity akn) {
|
|
showParticles(akn, 5);
|
|
}
|
|
|
|
public static void showJumpParticles(final Entity akn) {
|
|
showParticles(akn, 10);
|
|
}
|
|
|
|
private static void showParticles(final Entity akn, final int integer) {
|
|
if (!akn.level.isClientSide) {
|
|
return;
|
|
}
|
|
final BlockState byg3 = Blocks.HONEY_BLOCK.defaultBlockState();
|
|
for (int integer2 = 0; integer2 < integer; ++integer2) {
|
|
akn.level.addParticle(new BlockParticleOption(ParticleTypes.BLOCK, byg3), akn.getX(), akn.getY(), akn.getZ(), 0.0, 0.0, 0.0);
|
|
}
|
|
}
|
|
|
|
static {
|
|
SHAPE = Block.box(1.0, 0.0, 1.0, 15.0, 15.0, 15.0);
|
|
}
|
|
}
|