Java Code Examples for net.minecraft.util.math.BlockPos.MutableBlockPos#setPos()

The following examples show how to use net.minecraft.util.math.BlockPos.MutableBlockPos#setPos() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private boolean checkMultiblockValid(Map<BlockPos, MetaTileEntityTank> tankMap, BlockPos lowestCorner, int sizeX, int sizeY, int sizeZ) {
    //iterate each block to ensure that we have tanks in valid positions
    HashSet<BlockPos> visitedPositions = new HashSet<>();
    MutableBlockPos blockPos = new MutableBlockPos();
    for (int i = 0; i < sizeX; i++) {
        for (int j = 0; j < sizeY; j++) {
            for (int k = 0; k < sizeZ; k++) {
                blockPos.setPos(lowestCorner.getX() + i, lowestCorner.getY() + j, lowestCorner.getZ() + k);
                MetaTileEntityTank tankHere = tankMap.get(blockPos);
                if (tankHere == null) {
                    //tank is not here, so multiblock is not formed
                    return false;
                }
                //add found tank into the visited position list
                visitedPositions.add(tankHere.getPos());
            }
        }
    }
    //multiblock is assembled only if every tank neighbour is in the multiblock
    return visitedPositions.containsAll(tankMap.keySet());
}
 
Example 2
Source File: WorldPhysicsCollider.java    From Valkyrien-Skies with Apache License 2.0 6 votes vote down vote up
public void processCollisionTask(ShipCollisionTask task) {
    MutableBlockPos inWorldPos = new MutableBlockPos();
    MutableBlockPos inLocalPos = new MutableBlockPos();

    Iterator<CollisionInformationHolder> collisionIterator = task
        .getCollisionInformationIterator();

    while (collisionIterator.hasNext()) {
        CollisionInformationHolder info = collisionIterator.next();
        inWorldPos.setPos(info.inWorldX, info.inWorldY, info.inWorldZ);
        inLocalPos.setPos(info.inLocalX, info.inLocalY, info.inLocalZ);
        handleActualCollision(info.collider, inWorldPos, inLocalPos, info.inWorldState,
            info.inLocalState);
    }

    /*
     * for (CollisionInformationHolder info :
     * task.getCollisionInformationGenerated()) { inWorldPos.setPos(info.inWorldX,
     * info.inWorldY, info.inWorldZ); inLocalPos.setPos(info.inLocalX,
     * info.inLocalY, info.inLocalZ); handleActualCollision(info.collider,
     * inWorldPos, inLocalPos, info.inWorldState, info.inLocalState); }
     */

    task.getCollisionInformationGenerated().clear();
}
 
Example 3
Source File: PositionUtils.java    From enderutilities with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the MutableBlockPos <b>pos</b> with a position set to <b>posReference</b> offset by <b>amount</b> in the direction <b>side</b>.
 */
public static MutableBlockPos getOffsetPosition(MutableBlockPos pos, BlockPos posReference, EnumFacing side, int amount)
{
    switch (side)
    {
        case NORTH:
            pos.setPos(posReference.getX(), posReference.getY(), posReference.getZ() - amount);
        case SOUTH:
            pos.setPos(posReference.getX(), posReference.getY(), posReference.getZ() + amount);
        case EAST:
            pos.setPos(posReference.getX() + amount, posReference.getY(), posReference.getZ());
        case WEST:
            pos.setPos(posReference.getX() - amount, posReference.getY(), posReference.getZ());
        case UP:
            pos.setPos(posReference.getX(), posReference.getY() + amount, posReference.getZ());
        case DOWN:
            pos.setPos(posReference.getX(), posReference.getY() - amount, posReference.getZ());
    }

    return pos;
}
 
Example 4
Source File: CachedGridEntry.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean populateChunk(World world) {
    MutableBlockPos blockPos = new MutableBlockPos();
    boolean generatedAnything = false;
    for (OreDepositDefinition definition : oreBlocks.keySet()) {
        TLongList blockIndexList = oreBlocks.get(definition);
        TLongSet generatedBlocks = new TLongHashSet();
        boolean generatedOreVein = false;
        for (int i = 0; i < blockIndexList.size(); i++) {
            long blockIndex = blockIndexList.get(i);
            int xyzValue = (int) (blockIndex >> 32);
            int blockX = (byte) xyzValue;
            int blockZ = (byte) (xyzValue >> 8);
            int blockY = (short) (xyzValue >> 16);
            int index = (int) blockIndex;
            blockPos.setPos(chunkX * 16 + blockX, blockY, chunkZ * 16 + blockZ);
            IBlockState currentState = world.getBlockState(blockPos);
            IBlockState newState;
            if (index == 0) {
                //it's primary ore block
                if (!definition.getGenerationPredicate().test(currentState, world, blockPos))
                    continue; //do not generate if predicate didn't match
                newState = definition.getBlockFiller().apply(currentState, world, blockPos, blockX, blockY, blockZ);
            } else {
                //it's populator-generated block with index
                VeinBufferPopulator populator = (VeinBufferPopulator) definition.getVeinPopulator();
                newState = populator.getBlockByIndex(world, blockPos, index - 1);
            }
            //set flags as 16 to avoid observer updates loading neighbour chunks
            world.setBlockState(blockPos, newState, 16);
            generatedBlocks.add(Block.getStateId(newState));
            generatedOreVein = true;
            generatedAnything = true;
        }
        if (generatedOreVein) {
            this.generatedBlocksSet.put(definition, generatedBlocks);
            this.generatedOres.add(definition);
        }
    }
    return generatedAnything;
}
 
Example 5
Source File: BlockPattern.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MutableBlockPos setActualRelativeOffset(MutableBlockPos pos, int x, int y, int z, EnumFacing facing) {
    //if (!ArrayUtils.contains(ALLOWED_FACINGS, facing))
    //    throw new IllegalArgumentException("Can rotate only horizontally");
    int[] c0 = new int[]{x, y, z}, c1 = new int[3];
    for (int i = 0; i < 3; i++) {
        switch (structureDir[i].getActualFacing(facing)) {
            case UP:
                c1[1] = c0[i];
                break;
            case DOWN:
                c1[1] = -c0[i];
                break;
            case WEST:
                c1[0] = -c0[i];
                break;
            case EAST:
                c1[0] = c0[i];
                break;
            case NORTH:
                c1[2] = -c0[i];
                break;
            case SOUTH:
                c1[2] = c0[i];
                break;
        }
    }
    return pos.setPos(c1[0], c1[1], c1[2]);
}
 
Example 6
Source File: SpatialDetector.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public static void setPosWithRespectTo(int hash, BlockPos start, MutableBlockPos toSet) {
    int y = hash % maxRange;
    int x = ((hash - y) / maxRange) % maxRange;
    int z = (hash - (x * maxRange) - y) / (maxRangeSquared);
    x -= maxRangeHalved;
    z -= maxRangeHalved;
    toSet.setPos(x + start.getX(), y, z + start.getZ());
}
 
Example 7
Source File: PhysicsParticleManager.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public void tickParticle(PhysicsCalculations physicsSource, MutableBlockPos bufferBlockPos,
    Vector bufferVector, float timeStep) {
    // First move the particle forward
    this.posX += velX * timeStep;
    this.posY += velY * timeStep;
    this.posZ += velZ * timeStep;
    // Then advance the particle death clock
    this.particleLife -= timeStep;
    this.isParticleDead = (particleLife < 0);
    // Then check for collision in the world
    bufferBlockPos.setPos(posX, posY, posZ);
    if (!canParticlePassThrough(physicsSource.getParent().world(), bufferBlockPos)) {
        // The particle hit a block in the world, so kill it.
        this.isParticleDead = true;
    }
    // If the particle still isn't dead then check for collision in ship
    if (!isParticleDead) {
        bufferVector.setValue(posX, posY, posZ);
        physicsSource.getParent().getShipTransformationManager()
            .getCurrentPhysicsTransform()
            .transform(bufferVector, TransformType.GLOBAL_TO_SUBSPACE);
        bufferBlockPos.setPos(bufferVector.X, bufferVector.Y, bufferVector.Z);
        if (!canParticlePassThrough(physicsSource.getParent().world(), bufferBlockPos)) {
            this.isParticleDead = true;
            addMomentumToShip = true;
        }
    }
}
 
Example 8
Source File: TeleporterNoPortalSeekBlock.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public boolean placeInExistingPortal(Entity entityIn, float rotationYaw) {
	
	double x, y, z;
	x = entityIn.posX;
	y = entityIn.posY;
	z = entityIn.posZ;
	MutableBlockPos pos = new MutableBlockPos();
	
	for(int yy = (int) y; yy < world.getHeight(); yy++) {
		pos.setPos(x, yy, z);
		if(world.isAirBlock(pos) && world.isAirBlock(pos.add(0,1,0))){
			y = yy;
			break;
		}
	}
       
    if (entityIn instanceof EntityPlayerMP)
    {
        ((EntityPlayerMP)entityIn).connection.setPlayerLocation(x,y,z, entityIn.rotationYaw, entityIn.rotationPitch);
    }
    else
    {
        entityIn.setLocationAndAngles(x,y,z, entityIn.rotationYaw, entityIn.rotationPitch);
    }
    
    return true;
}
 
Example 9
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private MutableBlockPos clampBounds(MutableBlockPos bounds)
{
    int x = MathHelper.clamp(bounds.getX(), 0, this.maxSize);
    int y = MathHelper.clamp(bounds.getY(), 0, this.maxSize);
    int z = MathHelper.clamp(bounds.getZ(), 0, this.maxSize);

    return bounds.setPos(x, y, z);
}
 
Example 10
Source File: ItemBuildersWand.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setFromPacked(MutableBlockPos bounds, int packed)
{
    int x = MathHelper.clamp((packed >> 16) & 0xFF, 0, this.maxSize);
    int y = MathHelper.clamp((packed >>  8) & 0xFF, 0, this.maxSize);
    int z = MathHelper.clamp(packed         & 0xFF, 0, this.maxSize);

    bounds.setPos(x, y, z);
}
 
Example 11
Source File: TreeChopTask.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void move(MutableBlockPos blockPos) {
    blockPos.setPos(blockPos.getX() + direction.getX(),
        blockPos.getY() + direction.getY(),
        blockPos.getZ() + direction.getZ());
}
 
Example 12
Source File: PhysRenderChunk.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
private void updateList(BlockRenderLayer layerToUpdate) {
    if (parent.toRender.getShipRenderer() == null) {
        return;
    }
    BlockPos offsetPos = parent.toRender.getShipRenderer().offsetPos;
    if (offsetPos == null) {
        return;
    }
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder worldrenderer = tessellator.getBuffer();
    worldrenderer.begin(7, DefaultVertexFormats.BLOCK);
    worldrenderer.setTranslation(-offsetPos.getX(), -offsetPos.getY(), -offsetPos.getZ());
    GL11.glPushMatrix();
    switch (layerToUpdate) {
        case CUTOUT:
            GLAllocation.deleteDisplayLists(glCallListCutout);
            GL11.glNewList(glCallListCutout, GL11.GL_COMPILE);
            break;
        case CUTOUT_MIPPED:
            GLAllocation.deleteDisplayLists(glCallListCutoutMipped);
            GL11.glNewList(glCallListCutoutMipped, GL11.GL_COMPILE);
            break;
        case SOLID:
            GLAllocation.deleteDisplayLists(glCallListSolid);
            GL11.glNewList(glCallListSolid, GL11.GL_COMPILE);
            break;
        case TRANSLUCENT:
            GLAllocation.deleteDisplayLists(glCallListTranslucent);
            GL11.glNewList(glCallListTranslucent, GL11.GL_COMPILE);
            break;
        default:
            break;
    }

    GlStateManager.pushMatrix();
    // worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    IBlockState iblockstate;

    BlockRenderLayer oldLayer = MinecraftForgeClient.getRenderLayer();
    ForgeHooksClient.setRenderLayer(layerToUpdate);
    MutableBlockPos pos = new MutableBlockPos();
    for (int x = chunkToRender.x * 16; x < chunkToRender.x * 16 + 16; x++) {
        for (int z = chunkToRender.z * 16; z < chunkToRender.z * 16 + 16; z++) {
            for (int y = yMin; y <= yMax; y++) {
                pos.setPos(x, y, z);
                iblockstate = chunkToRender.getBlockState(pos);
                try {
                    if (iblockstate.getBlock()
                            .canRenderInLayer(iblockstate, layerToUpdate)) {
                        Minecraft.getMinecraft().getBlockRendererDispatcher()
                                .renderBlock(iblockstate, pos, chunkToRender.world,
                                        worldrenderer);
                    }
                } catch (NullPointerException e) {
                    System.out.println(
                            "Something was null! LValkyrienSkiesBase/render/PhysRenderChunk#updateList");
                }
            }
        }
    }
    tessellator.draw();
    // worldrenderer.finishDrawing();
    ForgeHooksClient.setRenderLayer(oldLayer);
    GlStateManager.popMatrix();
    GL11.glEndList();
    GL11.glPopMatrix();
    worldrenderer.setTranslation(0, 0, 0);

    switch (layerToUpdate) {
        case CUTOUT:
            needsCutoutUpdate = false;
            break;
        case CUTOUT_MIPPED:
            needsCutoutMippedUpdate = false;
            break;
        case SOLID:
            needsSolidUpdate = false;
            break;
        case TRANSLUCENT:
            needsTranslucentUpdate = false;
            break;
        default:
            break;
    }
}