From 79c68d68b5f808a0af91d6f5a96992e802d249c4 Mon Sep 17 00:00:00 2001 From: bconlon Date: Sun, 19 Jul 2020 17:13:51 -0700 Subject: [PATCH] Fixed gravitite blocks, probably didn't break anything else. --- .../aether/blocks/util/BlockFloating.java | 32 ++++++++++++++++--- .../entities/block/EntityFloatingBlock.java | 28 ++++++++++------ 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/legacy/aether/blocks/util/BlockFloating.java b/src/main/java/com/legacy/aether/blocks/util/BlockFloating.java index 7d20741..454a9c6 100644 --- a/src/main/java/com/legacy/aether/blocks/util/BlockFloating.java +++ b/src/main/java/com/legacy/aether/blocks/util/BlockFloating.java @@ -3,6 +3,7 @@ package com.legacy.aether.blocks.util; import java.util.Random; import net.minecraft.block.Block; +import net.minecraft.block.BlockSand; import net.minecraft.block.material.Material; import net.minecraft.init.Blocks; import net.minecraft.world.IBlockAccess; @@ -47,14 +48,35 @@ public class BlockFloating extends Block { } private void floatBlock(World world, int x, int y, int z) { - if (canContinue(world, x, y + 1, z) && y < world.getHeight()) { - EntityFloatingBlock floating = new EntityFloatingBlock(world, x, y, z, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + boolean floatInstantly = BlockSand.fallInstantly; - if (!world.isRemote) { - world.spawnEntityInWorld(floating); + if (canContinue(world, x, y + 1, z) && y >= 0) + { + if (!floatInstantly) + { + if (!world.isRemote) + { + EntityFloatingBlock entity = new EntityFloatingBlock(world, x, y, z, world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + world.setBlockToAir(x, y, z); + world.spawnEntityInWorld(entity); + } } + else + { + world.setBlockToAir(x, y, z); - world.setBlockToAir(x, y, z); + int bottomPos = y - 1; + + while (canContinue(world, x, bottomPos, z) && bottomPos > 0) + { + bottomPos = bottomPos - 1; + } + + if (bottomPos > 0) + { + world.setBlock(x, bottomPos + 1, z, this); + } + } } } diff --git a/src/main/java/com/legacy/aether/entities/block/EntityFloatingBlock.java b/src/main/java/com/legacy/aether/entities/block/EntityFloatingBlock.java index c9f7ffe..388a312 100644 --- a/src/main/java/com/legacy/aether/entities/block/EntityFloatingBlock.java +++ b/src/main/java/com/legacy/aether/entities/block/EntityFloatingBlock.java @@ -24,6 +24,8 @@ public class EntityFloatingBlock extends Entity implements IEntityAdditionalSpaw private int timeFloated = 0; + private boolean hasActivated = false; + public EntityFloatingBlock(World worldIn) { super(worldIn); @@ -84,19 +86,25 @@ public class EntityFloatingBlock extends Entity implements IEntityAdditionalSpaw } } - if (this.isCollidedVertically && !this.onGround) { - this.motionX *= 0.699999988079071D; - this.motionZ *= 0.699999988079071D; - this.motionY *= -0.5D; + if (this.ticksExisted > 200) + { this.setDead(); + } + else + { + if (!BlockFloating.canContinue(this.worldObj, i, j + 1, k)) + { + if (!this.worldObj.isRemote) + { + this.worldObj.setBlock(i, j, k, this.getBlock()); - if (!block.canPlaceBlockAt(this.worldObj, i, j, k) || BlockFloating.canContinue(this.worldObj, i, j + 1, k) || !this.worldObj.setBlock(i, j, k, this.getBlock(), this.getMetadata(), 2)) { - block.dropBlockAsItem(this.worldObj, i, j, k, this.getMetadata(), 0); + this.setDead(); + } + + this.posX = i + 0.5D; + this.posY = j; + this.posZ = k + 0.5D; } - } else if (this.timeFloated > 100) { - block.dropBlockAsItem(this.worldObj, i, j, k, this.getMetadata(), 0); - - this.setDead(); } }