Search in sources :

Example 6 with BlockFluidBase

use of net.minecraftforge.fluids.BlockFluidBase in project Minechem by iopleke.

the class FluidItemRenderingHandler method renderItem.

@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
    Fluid fluid = ((BlockFluidBase) ((ItemBlock) item.getItem()).field_150939_a).getFluid();
    if (fluid instanceof FluidElement) {
        RenderingUtil.setColorForElement(((FluidElement) fluid).element);
    } else if (fluid instanceof FluidMolecule) {
        MoleculeEnum molecule = ((FluidMolecule) fluid).molecule;
        GL11.glColor3f(molecule.red, molecule.green, molecule.blue);
    }
    IIcon icon = ((ItemBlock) item.getItem()).field_150939_a.getBlockTextureFromSide(0);
    switch(type) {
        case INVENTORY:
            RenderingUtil.drawTexturedRectUV(0, 0, 0, 16, 16, icon);
            break;
        case EQUIPPED_FIRST_PERSON:
        case EQUIPPED:
            ItemRenderer.renderItemIn2D(Tessellator.instance, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
            break;
        case ENTITY:
            EntityItem entityItem = (EntityItem) data[1];
            if (entityItem.worldObj == null) {
                float angle = (Minecraft.getSystemTime() % 8000L) / 8000.0F * 360.0F;
                GL11.glPushMatrix();
                GL11.glRotatef(angle, 0.0F, 1.0F, 0.0F);
                GL11.glTranslatef(-0.2F, -0.5F, 0.0F);
                renderItemAsEntity(item, icon);
                GL11.glPopMatrix();
            } else {
                renderItemAsEntity(item, icon);
            }
            break;
        default:
            break;
    }
}
Also used : FluidElement(minechem.fluid.FluidElement) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) IIcon(net.minecraft.util.IIcon) Fluid(net.minecraftforge.fluids.Fluid) MoleculeEnum(minechem.item.molecule.MoleculeEnum) FluidMolecule(minechem.fluid.FluidMolecule) EntityItem(net.minecraft.entity.item.EntityItem)

Example 7 with BlockFluidBase

use of net.minecraftforge.fluids.BlockFluidBase in project ICBM-Classic by BuiltBrokenModding.

the class BlastSonic method doExplode.

@Override
public // TODO Rewrite this entire method
boolean doExplode(// TODO Rewrite this entire method
int callCount) {
    if (callCount <= 0) {
        firstTick();
    }
    // TODO scale off of size & callcout
    final int radius = Math.max(1, this.callCount);
    if (callCount % 4 == 0) {
        if (isThreadCompleted()) {
            if (!getThreadResults().isEmpty()) {
                final Iterator<BlockPos> it = getThreadResults().iterator();
                while (it.hasNext()) {
                    final BlockPos targetPosition = it.next();
                    final double distance = location.distance(targetPosition);
                    // Only act on blocks inside the current radius TODO scale radius separate from ticks so we can control block creation
                    if (distance <= radius) {
                        // Remove
                        it.remove();
                        // Get data
                        final IBlockState blockState = world.getBlockState(targetPosition);
                        final Block block = blockState.getBlock();
                        // Only act on movable blocks
                        if (!block.isAir(blockState, world, targetPosition) && blockState.getBlockHardness(world, targetPosition) >= 0) {
                            // Trigger explosions
                            if (block == BlockReg.blockExplosive) {
                                ((TileEntityExplosive) this.world().getTileEntity(targetPosition)).trigger(false);
                            }
                            // Destroy block
                            this.world().setBlockToAir(targetPosition);
                            // Create floating block
                            if (!(block instanceof BlockFluidBase || block instanceof IFluidBlock) && this.world().rand.nextFloat() < 0.1) {
                                this.world().spawnEntity(new EntityFlyingBlock(this.world(), targetPosition, blockState));
                            }
                        }
                    }
                }
            } else {
                isAlive = false;
                if (ConfigDebug.DEBUG_THREADS) {
                    String msg = String.format("BlastSonic#doPostExplode() -> Thread failed to find blocks to edit. Either thread failed or no valid blocks were found in range." + "\nWorld = %s " + "\nThread = %s" + "\nSize = %s" + "\nPos = %s", world, getThread(), size, location);
                    ICBMClassic.logger().error(msg);
                }
            }
        }
    }
    // TODO scale to radius
    final int entityEffectRadius = 2 * this.callCount;
    final AxisAlignedBB bounds = new AxisAlignedBB(location.x() - entityEffectRadius, location.y() - entityEffectRadius, location.z() - entityEffectRadius, location.x() + entityEffectRadius, location.y() + entityEffectRadius, location.z() + entityEffectRadius);
    final List<Entity> allEntities = this.world().getEntitiesWithinAABB(Entity.class, bounds);
    for (Entity entity : allEntities) {
        if (entity instanceof IMissile) {
            // TODO change from guided to dummy fire
            ((IMissile) entity).destroyMissile(true);
        } else if (!(entity instanceof EntityPlayer) || !((EntityPlayer) entity).isCreative()) {
            // Get difference
            double xDelta = entity.posX - location.x();
            double yDelta = entity.posY - location.y();
            double zDelta = entity.posZ - location.z();
            // Normalize
            float distance = MathHelper.sqrt(xDelta * xDelta + yDelta * yDelta + zDelta * zDelta);
            xDelta = xDelta / (double) distance;
            yDelta = yDelta / (double) distance;
            zDelta = zDelta / (double) distance;
            // Scale
            final double scale = Math.max(0, (1 - (distance / getBlastRadius()))) * 3;
            xDelta *= scale;
            yDelta *= scale;
            zDelta *= scale;
            entity.motionX += xDelta * this.world().rand.nextFloat() * 0.2;
            entity.motionY += Math.abs(yDelta * this.world().rand.nextFloat()) * 1;
            entity.motionZ += zDelta * this.world().rand.nextFloat() * 0.2;
        }
    }
    return this.callCount > this.getBlastRadius();
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) IMissile(icbm.classic.api.caps.IMissile) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityFlyingBlock(icbm.classic.content.entity.EntityFlyingBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) TileEntityExplosive(icbm.classic.content.blocks.explosive.TileEntityExplosive) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 8 with BlockFluidBase

use of net.minecraftforge.fluids.BlockFluidBase in project MorePlanets by SteveKunG.

the class PathNavigateGroundMP method getPathablePosY.

private int getPathablePosY() {
    if (this.entity.isInWater() && this.getCanSwim()) {
        int i = (int) this.entity.getEntityBoundingBox().minY;
        Block block = this.world.getBlockState(new BlockPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ))).getBlock();
        int j = 0;
        while (block == Blocks.FLOWING_WATER || block == Blocks.WATER || block instanceof BlockFluidBase && this.world.getBlockState(new BlockPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ))).getMaterial() == Material.WATER) {
            ++i;
            block = this.world.getBlockState(new BlockPos(MathHelper.floor(this.entity.posX), i, MathHelper.floor(this.entity.posZ))).getBlock();
            ++j;
            if (j > 16) {
                return (int) this.entity.getEntityBoundingBox().minY;
            }
        }
        return i;
    } else {
        return (int) (this.entity.getEntityBoundingBox().minY + 0.5D);
    }
}
Also used : BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 9 with BlockFluidBase

use of net.minecraftforge.fluids.BlockFluidBase in project Gaia-Dimension by Andromander.

the class GDLiquidBismuth method mixFluids.

@Override
public void mixFluids(World world, BlockPos pos) {
    for (EnumFacing side : EnumFacing.VALUES) {
        if (side != EnumFacing.DOWN) {
            IBlockState offset = world.getBlockState(pos.offset(side));
            if (offset.getMaterial().isLiquid()) {
                if (offset.getBlock() == GDBlocks.sweet_muck_block || offset.getBlock() == GDBlocks.superhot_magma_block) {
                    world.setBlockState(pos, GDBlocks.active_rock.getDefaultState());
                    this.playSound(world, pos);
                    break;
                } else if (offset.getBlock() instanceof BlockFluidBase || offset.getBlock() instanceof BlockLiquid) {
                    if (offset.getMaterial() == Material.WATER) {
                        world.setBlockState(pos, GDBlocks.impure_rock.getDefaultState());
                        this.playSound(world, pos);
                        break;
                    }
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) EnumFacing(net.minecraft.util.EnumFacing)

Example 10 with BlockFluidBase

use of net.minecraftforge.fluids.BlockFluidBase in project Gaia-Dimension by Andromander.

the class GDFluidsRegister method registerFluidModel.

@SideOnly(Side.CLIENT)
public static void registerFluidModel(BlockFluidBase fluid) {
    final Item item = Item.getItemFromBlock(fluid);
    net.minecraft.client.renderer.block.model.ModelBakery.registerItemVariants(item);
    String domain = fluid.getRegistryName() == null ? "minecraft" : fluid.getRegistryName().getResourceDomain();
    ModelResourceLocation modelResourceLocation = new ModelResourceLocation(new ResourceLocation(domain, "blocks/fluids"), fluid.getFluid().getName());
    ModelLoader.setCustomMeshDefinition(item, androsa.gaiadimension.registry.MeshDefinitionFix.create(stack -> modelResourceLocation));
    ModelLoader.setCustomStateMapper(fluid, new net.minecraft.client.renderer.block.statemap.StateMapperBase() {

        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
            return modelResourceLocation;
        }
    });
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Side(net.minecraftforge.fml.relauncher.Side) Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) Fluid(net.minecraftforge.fluids.Fluid) FluidRegistry(net.minecraftforge.fluids.FluidRegistry) ModelLoader(net.minecraftforge.client.model.ModelLoader) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) BlockFluidBase(net.minecraftforge.fluids.BlockFluidBase) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

BlockFluidBase (net.minecraftforge.fluids.BlockFluidBase)18 Block (net.minecraft.block.Block)10 BlockPos (net.minecraft.util.math.BlockPos)6 BlockStaticLiquid (net.minecraft.block.BlockStaticLiquid)5 IBlockState (net.minecraft.block.state.IBlockState)5 BlockLiquid (net.minecraft.block.BlockLiquid)4 BlockDynamicLiquid (net.minecraft.block.BlockDynamicLiquid)3 ItemBlock (net.minecraft.item.ItemBlock)3 ItemStack (net.minecraft.item.ItemStack)3 EnumFacing (net.minecraft.util.EnumFacing)3 Fluid (net.minecraftforge.fluids.Fluid)3 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)3 HashSet (java.util.HashSet)2 BlockFlower (net.minecraft.block.BlockFlower)2 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)2 PathNodeType (net.minecraft.pathfinding.PathNodeType)2 PathPoint (net.minecraft.pathfinding.PathPoint)2 Chunk (net.minecraft.world.chunk.Chunk)2 IControllable (buildcraft.api.tiles.IControllable)1 CropHandlerPlantable (buildcraft.core.crops.CropHandlerPlantable)1