Search in sources :

Example 1 with Vector3i

use of net.minecraft.util.math.vector.Vector3i in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method rightClickWithItem.

public void rightClickWithItem(@Nonnull ServerPlayerEntity player, RightClickBlockMessage message) {
    BlockPos pos = message.getPos();
    Direction sideHit = message.getHitSide();
    float hitX = message.getHitX();
    float hitY = message.getHitY();
    float hitZ = message.getHitZ();
    ServerWorld worldIn = player.getLevel();
    ItemStack multiTool = player.getMainHandItem();
    if (multiTool.getItem() != this) {
        return;
    }
    ItemStack blockStack = getSelectedBlockItemStack(multiTool);
    if (blockStack.isEmpty()) {
        player.displayClientMessage(new StringTextComponent("No block type selected to place."), true);
        return;
    }
    if (!(blockStack.getItem() instanceof BlockItem)) {
        player.displayClientMessage(new StringTextComponent("No valid block type selected to place."), true);
        return;
    }
    LazyOptional<IEnergyStorage> opEnergy = multiTool.getCapability(ENERGY);
    if (!opEnergy.isPresent()) {
        Overloaded.logger.warn("MultiTool has no Energy Capability? NBT: " + multiTool.getTag());
        return;
    }
    IEnergyStorage energy = opEnergy.orElseThrow(() -> new RuntimeException("Impossible Condition"));
    Vector3i sideVector = sideHit.getNormal();
    BlockPos.Mutable newPosition = pos.offset(sideVector).mutable();
    switch(placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ)) {
        case FAIL_PREREQUISITE:
            player.displayClientMessage(new StringTextComponent("Do not have the required items"), true);
            return;
        case FAIL_DENY:
            player.displayClientMessage(new StringTextComponent("Unable to place blocks"), true);
            return;
        case FAIL_RANGE:
            player.displayClientMessage(new StringTextComponent("To far away"), true);
            return;
        case FAIL_ENERGY:
            player.displayClientMessage(new StringTextComponent("Not enough energy"), true);
            return;
        case SUCCESS:
    }
    if (player.isShiftKeyDown()) {
        BlockPos playerPos = player.blockPosition();
        switch(sideHit) {
            case UP:
                while (newPosition.getY() < playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case DOWN:
                while (newPosition.getY() > playerPos.getY()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case NORTH:
                while (newPosition.getZ() > playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case SOUTH:
                while (newPosition.getZ() < playerPos.getZ()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case EAST:
                while (newPosition.getX() < playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
            case WEST:
                while (newPosition.getX() > playerPos.getX()) {
                    newPosition.move(sideHit);
                    if (placeBlock(blockStack, player, worldIn, newPosition, sideHit, energy, hitX, hitY, hitZ) != BlockPlaceResult.SUCCESS)
                        break;
                }
                break;
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) Vector3i(net.minecraft.util.math.vector.Vector3i) BlockPos(net.minecraft.util.math.BlockPos) StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem)

Example 2 with Vector3i

use of net.minecraft.util.math.vector.Vector3i in project Overloaded by CJ-MC-Mods.

the class ModelUtils method renderQuads.

public static void renderQuads(List<BakedQuad> listQuads) {
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder vertexbuffer = tessellator.getBuilder();
    int i = 0;
    vertexbuffer.begin(7, DefaultVertexFormats.BLOCK);
    for (int j = listQuads.size(); i < j; ++i) {
        BakedQuad bakedquad = listQuads.get(i);
        // vertexbuffer.putBulkData(bakedquad);
        vertexbuffer.color(1, 1, 1, 1);
        Vector3i vec3i = bakedquad.getDirection().getNormal();
        vertexbuffer.normal((float) vec3i.getX(), (float) vec3i.getY(), (float) vec3i.getZ());
    }
    tessellator.end();
}
Also used : BakedQuad(net.minecraft.client.renderer.model.BakedQuad) Tessellator(net.minecraft.client.renderer.Tessellator) BufferBuilder(net.minecraft.client.renderer.BufferBuilder) Vector3i(net.minecraft.util.math.vector.Vector3i)

Aggregations

Vector3i (net.minecraft.util.math.vector.Vector3i)2 BufferBuilder (net.minecraft.client.renderer.BufferBuilder)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 BakedQuad (net.minecraft.client.renderer.model.BakedQuad)1 BlockItem (net.minecraft.item.BlockItem)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 StringTextComponent (net.minecraft.util.text.StringTextComponent)1 ServerWorld (net.minecraft.world.server.ServerWorld)1 IEnergyStorage (net.minecraftforge.energy.IEnergyStorage)1