Search in sources :

Example 1 with Direction

use of net.minecraft.util.Direction in project Bookshelf by Darkhax-Minecraft.

the class RenderUtils method renderModel.

/**
 * Renders a block model. Allows the sites rendered to be specifically controlled by the
 * caller.
 *
 * @param renderer The block model renderer instance.
 * @param world The world instance.
 * @param model The model to render.
 * @param state The state of the block.
 * @param pos The position of the block.
 * @param matrix The render matrix.
 * @param buffer The render buffer.
 * @param sides The sides of the model to render.
 */
public static void renderModel(BlockModelRenderer renderer, IBlockDisplayReader world, IBakedModel model, BlockState state, BlockPos pos, MatrixStack matrix, IVertexBuilder buffer, Direction[] sides) {
    final IModelData modelData = model.getModelData(world, pos, state, EmptyModelData.INSTANCE);
    // Renders only the sided model quads.
    for (final Direction side : sides) {
        RANDOM.setSeed(0L);
        final List<BakedQuad> sidedQuads = model.getQuads(state, side, RANDOM, modelData);
        if (!sidedQuads.isEmpty()) {
            final int lightForSide = WorldRenderer.getLightColor(world, state, pos.relative(side));
            renderer.renderModelFaceFlat(world, state, pos, lightForSide, OverlayTexture.NO_OVERLAY, false, matrix, buffer, sidedQuads, BITS);
        }
    }
    // Renders the non-sided model quads.
    RANDOM.setSeed(0L);
    final List<BakedQuad> unsidedQuads = model.getQuads(state, null, RANDOM, modelData);
    if (!unsidedQuads.isEmpty()) {
        renderer.renderModelFaceFlat(world, state, pos, -1, OverlayTexture.NO_OVERLAY, true, matrix, buffer, unsidedQuads, BITS);
    }
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Direction(net.minecraft.util.Direction) IModelData(net.minecraftforge.client.model.data.IModelData)

Example 2 with Direction

use of net.minecraft.util.Direction in project NetherEx by LogicTechCorp.

the class SoulGlassBlock method onEntityCollision.

@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
    if (entity instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) entity;
        boolean sinking = player.getLookVec().y < -0.75D;
        CompoundNBT playerData = player.getPersistentData();
        Direction shootDirection = null;
        if (!player.isPotionActive(NetherExEffects.SOUL_SUCKED.get())) {
            playerData.remove(SHOOT_DIRECTION_KEY);
        }
        if (playerData.contains(SHOOT_DIRECTION_KEY)) {
            shootDirection = Direction.byIndex(playerData.getInt(SHOOT_DIRECTION_KEY));
        }
        if (player.isShiftKeyDown()) {
            if (!sinking) {
                if (shootDirection == null) {
                    shootDirection = player.getHorizontalFacing().getOpposite();
                }
                Block blockOneBack = world.getBlockState(pos.offset(shootDirection)).getBlock();
                Block blockTwoBack = world.getBlockState(pos.offset(shootDirection, 2)).getBlock();
                Block blockThreeBack = world.getBlockState(pos.offset(shootDirection, 3)).getBlock();
                if (blockOneBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
                }
                if (blockOneBack == this && blockTwoBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
                } else if (blockOneBack == this && blockThreeBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
                } else if (blockOneBack == this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
                }
            } else {
                if (shootDirection == null) {
                    shootDirection = Direction.UP;
                }
                Block blockUpOne = world.getBlockState(pos.up()).getBlock();
                Block blockUpTwo = world.getBlockState(pos.up(2)).getBlock();
                Block blockUpThree = world.getBlockState(pos.up(3)).getBlock();
                if (blockUpOne != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
                }
                if (blockUpOne == this && blockUpTwo != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
                } else if (blockUpOne == this && blockUpThree != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
                } else if (blockUpOne == this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
                    player.setPosition(player.getPosX(), player.prevPosY, player.getPosZ());
                }
                player.setMotion(player.getMotion().mul(1.0D, 0.25D, 1.0D));
            }
        } else {
            EffectInstance effect = player.getActivePotionEffect(NetherExEffects.SOUL_SUCKED.get());
            int amplifier = 1;
            if (effect != null) {
                amplifier = (effect.getAmplifier() + 1);
            }
            Vec3d motion = player.getMotion();
            if (!sinking && shootDirection != null && shootDirection != Direction.UP) {
                Direction playerDirection = shootDirection.getOpposite();
                if (playerDirection == Direction.NORTH) {
                    if (motion.getZ() < 0) {
                        player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
                    } else if (motion.getZ() == 0) {
                        player.setMotion(new Vec3d(motion.getX(), motion.getY(), 0.5D));
                    }
                } else if (playerDirection == Direction.EAST) {
                    if (motion.getX() > 0) {
                        player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
                    } else if (motion.getX() == 0) {
                        player.setMotion(new Vec3d(-0.5D, motion.getY(), motion.getZ()));
                    }
                } else if (playerDirection == Direction.SOUTH) {
                    if (motion.getZ() > 0) {
                        player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
                    } else if (motion.getZ() == 0) {
                        player.setMotion(new Vec3d(motion.getX(), motion.getY(), -0.5D));
                    }
                } else if (playerDirection == Direction.WEST) {
                    if (motion.getX() < 0) {
                        player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
                    } else if (motion.getX() == 0) {
                        player.setMotion(new Vec3d(0.5D, motion.getY(), motion.getZ()));
                    }
                }
                if (motion.getX() > -6.0D && motion.getX() < 6.0D) {
                    player.setMotion(new Vec3d((motion.getX() * 1.15D * amplifier), motion.getY(), motion.getZ()));
                }
                if (motion.getZ() > -6.0D && motion.getZ() < 6.0D) {
                    player.setMotion(new Vec3d(motion.getX(), motion.getY(), (motion.getZ() * 1.15D * amplifier)));
                }
            } else {
                if (motion.getY() <= 0) {
                    player.setMotion(new Vec3d(motion.getX(), 0.105D, motion.getZ()));
                }
                if (motion.getY() < 1.315D) {
                    player.setMotion(new Vec3d(motion.getX(), (motion.getY() + (amplifier * 0.1D)), motion.getZ()));
                }
            }
        }
        if (shootDirection != null) {
            playerData.putInt(SHOOT_DIRECTION_KEY, shootDirection.getIndex());
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) GlassBlock(net.minecraft.block.GlassBlock) Block(net.minecraft.block.Block) Direction(net.minecraft.util.Direction) EffectInstance(net.minecraft.potion.EffectInstance) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with Direction

use of net.minecraft.util.Direction in project NetherEx by LogicTechCorp.

the class EnokiStemBlock method isValidPosition.

@Override
public boolean isValidPosition(BlockState state, IWorldReader world, BlockPos pos) {
    BlockState upState = world.getBlockState(pos.up());
    boolean flag = !world.getBlockState(pos.down()).isAir() && !upState.isAir();
    for (Direction direction : Direction.Plane.HORIZONTAL) {
        BlockPos offsetPos = pos.offset(direction);
        Block block = world.getBlockState(offsetPos).getBlock();
        if (block == this) {
            if (flag) {
                return false;
            }
            Block upBlock = world.getBlockState(offsetPos.up()).getBlock();
            if (upBlock == this || upBlock == NetherExBlocks.LIVELY_NETHERRACK.get()) {
                return true;
            }
        }
    }
    Block upBlock = upState.getBlock();
    return upBlock == this || upBlock == NetherExBlocks.LIVELY_NETHERRACK.get();
}
Also used : BlockState(net.minecraft.block.BlockState) Block(net.minecraft.block.Block) SixWayBlock(net.minecraft.block.SixWayBlock) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction)

Example 4 with Direction

use of net.minecraft.util.Direction in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerLeftClick.

@SubscribeEvent
public static void onPlayerLeftClick(PlayerInteractEvent.LeftClickBlock event) {
    World world = event.getWorld();
    Direction direction = event.getFace();
    BlockPos pos = event.getPos();
    PlayerEntity player = event.getPlayer();
    if (direction != null) {
        BlockPos offsetPos = pos.offset(direction);
        Block offsetBlock = world.getBlockState(offsetPos).getBlock();
        if (offsetBlock == NetherExBlocks.BLUE_FIRE.get()) {
            world.playEvent(player, 1009, offsetPos, 0);
            world.setBlockState(offsetPos, Blocks.AIR.getDefaultState());
            event.setCanceled(true);
        }
    }
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with Direction

use of net.minecraft.util.Direction in project Overloaded by CJ-MC-Mods.

the class ModelRenderOBJ method renderModel.

private void renderModel(IBakedModel modelIn, ItemStack stack, int combinedLightIn, int combinedOverlayIn, MatrixStack matrixStackIn, IVertexBuilder bufferIn) {
    Random random = new Random();
    long i = 42L;
    // matrixStackIn.translate(0,-12,0);
    for (Direction direction : Direction.values()) {
        random.setSeed(i);
        Minecraft.getInstance().getItemRenderer().renderQuadList(matrixStackIn, bufferIn, modelIn.getQuads(null, direction, random), stack, combinedLightIn, combinedOverlayIn);
    }
    random.setSeed(i);
    Minecraft.getInstance().getItemRenderer().renderQuadList(matrixStackIn, bufferIn, modelIn.getQuads(null, null, random), stack, combinedLightIn, combinedOverlayIn);
}
Also used : Random(java.util.Random) Direction(net.minecraft.util.Direction)

Aggregations

Direction (net.minecraft.util.Direction)51 BlockState (net.minecraft.block.BlockState)18 TileEntity (net.minecraft.tileentity.TileEntity)17 BlockPos (net.minecraft.util.math.BlockPos)16 ItemStack (net.minecraft.item.ItemStack)13 Block (net.minecraft.block.Block)10 Nonnull (javax.annotation.Nonnull)8 Nullable (javax.annotation.Nullable)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 World (net.minecraft.world.World)6 IPowerBase (com.bluepowermod.api.power.IPowerBase)5 Capability (net.minecraftforge.common.capabilities.Capability)5 BlutricityStorage (com.bluepowermod.api.power.BlutricityStorage)4 CapabilityBlutricity (com.bluepowermod.api.power.CapabilityBlutricity)4 EnergyHelper (com.bluepowermod.helper.EnergyHelper)4 BPTileEntityType (com.bluepowermod.tile.BPTileEntityType)4 TileMachineBase (com.bluepowermod.tile.TileMachineBase)4 INBT (net.minecraft.nbt.INBT)4 LazyOptional (net.minecraftforge.common.util.LazyOptional)4