use of com.aether.blocks.FloatingBlock in project Paradise-Lost by devs-immortal.
the class FloatingBlockEntity method postTickEntities.
/**
* Because this entity moves other entities, including the player, this entity has
* to tick after the all other entities have ticked to prevent them phasing though this
*/
public void postTickEntities() {
if (this.blockState.isAir()) {
this.remove();
} else {
Block block = this.blockState.getBlock();
BlockPos blockPos;
if (this.floatTime++ == 0) {
blockPos = this.getBlockPos();
if (this.world.getBlockState(blockPos).isOf(block)) {
this.world.removeBlock(blockPos, false);
} else if (!this.world.isClient) {
this.remove();
return;
}
}
boolean isFastFloater = (this.blockState.getBlock() == AetherBlocks.GRAVITITE_ORE || this.blockState.getBlock() == AetherBlocks.GRAVITITE_LEVITATOR || this.blockState.getBlock() == AetherBlocks.BLOCK_OF_GRAVITITE);
if (!this.hasNoGravity()) {
if (isFastFloater) {
this.setVelocity(this.getVelocity().add(0.0D, 0.05D, 0.0D));
} else {
this.setVelocity(this.getVelocity().add(0.0D, 0.03D, 0.0D));
}
}
Box oldBox = getBoundingBox();
this.move(MovementType.SELF, this.getVelocity());
if (!FallingBlock.canFallThrough(this.blockState)) {
Box newBox = getBoundingBox();
List<Entity> otherEntities = this.world.getOtherEntities(this, oldBox.union(newBox));
for (Entity entity : otherEntities) {
if (!(entity instanceof FloatingBlockEntity) && !entity.noClip) {
if (entity.getY() < newBox.maxY) {
entity.updatePosition(entity.getPos().x, newBox.maxY, entity.getPos().z);
}
}
}
}
if (!this.world.isClient) {
blockPos = this.getBlockPos();
boolean isConcrete = this.blockState.getBlock() instanceof ConcretePowderBlock;
boolean shouldSolidify = isConcrete && this.world.getFluidState(blockPos).isIn(FluidTags.WATER);
double speed = this.getVelocity().lengthSquared();
if (isConcrete && speed > 1.0D) {
BlockHitResult blockHitResult = this.world.raycast(new RaycastContext(new Vec3d(this.prevX, this.prevY, this.prevZ), new Vec3d(this.getX(), this.getY(), this.getZ()), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.SOURCE_ONLY, this));
if (blockHitResult.getType() != HitResult.Type.MISS && this.world.getFluidState(blockHitResult.getBlockPos()).isIn(FluidTags.WATER)) {
blockPos = blockHitResult.getBlockPos();
shouldSolidify = true;
}
}
if (!this.verticalCollision && !shouldSolidify) {
if (!this.world.isClient) {
if (this.floatTime > 100 && blockPos.getY() > this.world.getHeight() + 64) {
if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS) && this.world.isPlayerInRange(blockPos.getX(), blockPos.getY(), blockPos.getZ(), 4)) {
this.dropItem(block);
}
this.remove();
}
}
} else {
BlockState blockState = this.world.getBlockState(blockPos);
this.setVelocity(this.getVelocity().multiply(0.7, 0.5, 0.7));
if (blockState.getBlock() != Blocks.MOVING_PISTON) {
this.remove();
if (!this.destroyedOnLanding) {
boolean canReplace = blockState.canReplace(new AutomaticItemPlacementContext(this.world, blockPos, Direction.DOWN, ItemStack.EMPTY, Direction.UP));
if (!canReplace) {
canReplace = blockState.canReplace(new AutomaticItemPlacementContext(this.world, blockPos, Direction.UP, ItemStack.EMPTY, Direction.DOWN));
}
boolean canPlace = this.blockState.canPlaceAt(this.world, blockPos);
if (canReplace && canPlace) {
if (this.blockState.contains(Properties.WATERLOGGED) && this.world.getFluidState(blockPos).getFluid() == Fluids.WATER)
this.blockState = this.blockState.with(Properties.WATERLOGGED, true);
if (this.world.setBlockState(blockPos, this.blockState, 3)) {
if (block instanceof FloatingBlock)
((FloatingBlock) block).onEndFloating(this.world, blockPos, this.blockState, blockState);
if (this.blockEntityData != null && this.blockState.getBlock().hasBlockEntity()) {
BlockEntity blockEntity = this.world.getBlockEntity(blockPos);
if (blockEntity != null) {
CompoundTag compoundTag = blockEntity.toTag(new CompoundTag());
for (String keyName : this.blockEntityData.getKeys()) {
Tag tag = this.blockEntityData.get(keyName);
if (tag != null && !"x".equals(keyName) && !"y".equals(keyName) && !"z".equals(keyName)) {
compoundTag.put(keyName, tag.copy());
}
}
blockEntity.fromTag(this.blockState, compoundTag);
blockEntity.markDirty();
}
}
} else if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
this.dropItem(block);
}
} else if (this.dropItem && this.world.getGameRules().getBoolean(GameRules.DO_ENTITY_DROPS)) {
this.dropItem(block);
}
} else if (block instanceof FloatingBlock) {
((FloatingBlock) block).onBroken(this.world, blockPos);
}
}
}
}
this.setVelocity(this.getVelocity().multiply(0.98D));
}
}
Aggregations