Search in sources :

Example 6 with EntityFallingBlock

use of net.minecraft.entity.item.EntityFallingBlock in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class VSWorldEventListener method onEntityAdded.

// TODO: Fix conflicts with EventsCommon.onEntityJoinWorldEvent()
@Override
public void onEntityAdded(Entity entity) {
    // This is really only here because Sponge doesn't call the entity join event for some reason :/
    // So I basically just copied the event code here as well.
    World world = worldObj;
    BlockPos posAt = new BlockPos(entity);
    Optional<PhysicsObject> physicsObject = ValkyrienUtils.getPhysoManagingBlock(world, posAt);
    if (!worldObj.isRemote && physicsObject.isPresent() && !(entity instanceof EntityFallingBlock)) {
        if (entity instanceof EntityArmorStand || entity instanceof EntityPig || entity instanceof EntityBoat) {
            EntityMountable entityMountable = new EntityMountable(world, entity.getPositionVector(), CoordinateSpaceType.SUBSPACE_COORDINATES, posAt);
            world.spawnEntity(entityMountable);
            entity.startRiding(entityMountable);
        }
        world.getChunk(entity.getPosition().getX() >> 4, entity.getPosition().getZ() >> 4).removeEntity(entity);
        physicsObject.get().getShipTransformationManager().getCurrentTickTransform().transform(entity, TransformType.SUBSPACE_TO_GLOBAL, false);
        world.getChunk(entity.getPosition().getX() >> 4, entity.getPosition().getZ() >> 4).addEntity(entity);
    }
}
Also used : EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityPig(net.minecraft.entity.passive.EntityPig) EntityBoat(net.minecraft.entity.item.EntityBoat) EntityMountable(org.valkyrienskies.mod.common.entity.EntityMountable) BlockPos(net.minecraft.util.math.BlockPos) EntityArmorStand(net.minecraft.entity.item.EntityArmorStand) World(net.minecraft.world.World)

Example 7 with EntityFallingBlock

use of net.minecraft.entity.item.EntityFallingBlock in project BetterWithAddons by DaedalusGame.

the class BlockChandelier method checkAndDrop.

public void checkAndDrop(World worldIn, BlockPos pos) {
    if (!worldIn.isRemote && !canBlockStay(worldIn, pos) && worldIn.isAreaLoaded(pos.add(-32, -32, -32), pos.add(32, 32, 32))) {
        EntityFallingBlock entityfallingblock = new EntityFallingBlock(worldIn, (double) pos.getX() + 0.5D, (double) pos.getY(), (double) pos.getZ() + 0.5D, worldIn.getBlockState(pos));
        entityfallingblock.shouldDropItem = true;
        entityfallingblock.setHurtEntities(true);
        worldIn.spawnEntity(entityfallingblock);
    }
}
Also used : EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock)

Example 8 with EntityFallingBlock

use of net.minecraft.entity.item.EntityFallingBlock in project BetterWithAddons by DaedalusGame.

the class FallingPlatformHandler method dropPlatform.

private void dropPlatform(World world, BlockPos pos) {
    BlockPos anchorpos = pos.down();
    IBlockState blockstate = world.getBlockState(anchorpos);
    Block block = blockstate.getBlock();
    if (!world.isRemote && block == BWMBlocks.ANCHOR && !isAnchorSupported(world, anchorpos)) {
        EnumFacing facing = blockstate.getValue(DirUtils.FACING);
        HashSet<BlockPos> platformBlocks = new HashSet<>();
        boolean success = findPlatformPart(world, anchorpos, platformBlocks);
        if (success)
            for (BlockPos plat : platformBlocks) {
                EntityFallingBlock entityfallingblock = new EntityFallingBlock(world, (double) plat.getX() + 0.5D, (double) plat.getY(), (double) plat.getZ() + 0.5D, world.getBlockState(plat));
                entityfallingblock.setHurtEntities(true);
                world.spawnEntity(entityfallingblock);
            }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EnumFacing(net.minecraft.util.EnumFacing) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 9 with EntityFallingBlock

use of net.minecraft.entity.item.EntityFallingBlock in project MorePlanets by SteveKunG.

the class EntityBlackHole method spawnFallingBlock.

private void spawnFallingBlock() {
    int blockPosX = MathHelper.floor(this.posX);
    int blockPosY = MathHelper.floor(this.posY);
    int blockPosZ = MathHelper.floor(this.posZ);
    int radius = 1 + this.spawnBlockRadiusTick;
    for (int x = -radius; x < radius; x++) {
        for (int y = -radius; y < radius; y++) {
            for (int z = -radius; z < radius; z++) {
                double dist = MathHelper.sqrt(x * x + y * y + z * z);
                if (dist <= radius) {
                    BlockPos pos = new BlockPos(blockPosX + x, blockPosY + y, blockPosZ + z);
                    IBlockState state = this.world.getBlockState(pos);
                    Block block = state.getBlock();
                    if (!block.isAir(state, this.world, pos)) {
                        this.world.setBlockToAir(pos);
                        EntityFallingBlock fallingBlock = new EntityFallingBlock(this.world, blockPosX + x, blockPosY + y, blockPosZ + z, state);
                        fallingBlock.fallTime = 1;
                        fallingBlock.shouldDropItem = false;
                        fallingBlock.motionY += 0.5D;
                        fallingBlock.setLocationAndAngles(blockPosX + x + 0.5D, blockPosY + y, blockPosZ + z + 0.5D, 0.0F, 0.0F);
                        this.world.spawnEntity(fallingBlock);
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 10 with EntityFallingBlock

use of net.minecraft.entity.item.EntityFallingBlock in project Galacticraft by micdoodle8.

the class FreefallHandler method tickFreefallEntity.

/**
 * Call this on every freefalling non-player entity in a dimension
 * either at the end of the world tick (ideal) or else during the
 * start of the next world tick (e.g. during updateWeather())
 *
 * May require iteration through the world's loadedEntityList
 * See SpinManager.updateSpin() for an example
 * @param e
 */
public static void tickFreefallEntity(Entity e) {
    if (e.world.provider instanceof IZeroGDimension)
        ((IZeroGDimension) e.world.provider).setInFreefall(e);
    // Undo deceleration applied at the end of the previous tick
    boolean warnLog = false;
    if (e instanceof EntityLivingBase) {
        ZeroGravityEvent zeroGEvent = new ZeroGravityEvent.InFreefall((EntityLivingBase) e);
        MinecraftForge.EVENT_BUS.post(zeroGEvent);
        if (!zeroGEvent.isCanceled()) {
            // 0.91F;
            e.motionX /= (double) 0.91F;
            // 0.91F;
            e.motionZ /= (double) 0.91F;
            e.motionY /= (e instanceof EntityFlying) ? 0.91F : 0.9800000190734863D;
            if (e.motionX > 10D) {
                warnLog = true;
                e.motionX = 10D;
            } else if (e.motionX < -10D) {
                warnLog = true;
                e.motionX = -10D;
            }
            if (e.motionY > 10D) {
                warnLog = true;
                e.motionY = 10D;
            } else if (e.motionY < -10D) {
                warnLog = true;
                e.motionY = -10D;
            }
            if (e.motionZ > 10D) {
                warnLog = true;
                e.motionZ = 10D;
            } else if (e.motionZ < -10D) {
                warnLog = true;
                e.motionZ = -10D;
            }
        }
    } else if (e instanceof EntityFallingBlock) {
        e.motionY /= 0.9800000190734863D;
        // e.lastTickPosY += 0.03999999910593033D;
        if (e.motionY > 10D) {
            warnLog = true;
            e.motionY = 10D;
        } else if (e.motionY < -10D) {
            warnLog = true;
            e.motionY = -10D;
        }
    } else {
        e.motionX /= 0.9800000190734863D;
        e.motionY /= 0.9800000190734863D;
        e.motionZ /= 0.9800000190734863D;
        if (e.motionX > 10D) {
            warnLog = true;
            e.motionX = 10D;
        } else if (e.motionX < -10D) {
            warnLog = true;
            e.motionX = -10D;
        }
        if (e.motionY > 10D) {
            warnLog = true;
            e.motionY = 10D;
        } else if (e.motionY < -10D) {
            warnLog = true;
            e.motionY = -10D;
        }
        if (e.motionZ > 10D) {
            warnLog = true;
            e.motionZ = 10D;
        } else if (e.motionZ < -10D) {
            warnLog = true;
            e.motionZ = -10D;
        }
    }
    if (warnLog)
        GCLog.debug(e.getName() + " moving too fast");
}
Also used : ZeroGravityEvent(micdoodle8.mods.galacticraft.api.event.ZeroGravityEvent) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityFlying(net.minecraft.entity.EntityFlying) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IZeroGDimension(micdoodle8.mods.galacticraft.api.world.IZeroGDimension)

Aggregations

EntityFallingBlock (net.minecraft.entity.item.EntityFallingBlock)17 BlockPos (net.minecraft.util.math.BlockPos)8 Block (net.minecraft.block.Block)4 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)4 IBlockState (net.minecraft.block.state.IBlockState)3 Entity (net.minecraft.entity.Entity)3 EntityBoat (net.minecraft.entity.item.EntityBoat)3 EntityPig (net.minecraft.entity.passive.EntityPig)3 World (net.minecraft.world.World)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityItem (net.minecraft.entity.item.EntityItem)2 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)2 Entity (org.spongepowered.api.entity.Entity)2 IMixinTileEntity (org.spongepowered.common.interfaces.block.tile.IMixinTileEntity)2 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)2 EntityMountable (org.valkyrienskies.mod.common.entity.EntityMountable)2 Vector (ValkyrienWarfareBase.API.Vector)1 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)1 EntityMountingWeaponBase (ValkyrienWarfareCombat.Entity.EntityMountingWeaponBase)1