Search in sources :

Example 1 with BlockAir

use of net.minecraft.block.BlockAir in project Trains-In-Motion-1.7.10 by EternalBlueFlame.

the class HitboxHandler method getCollision.

/**
     * <h3>Process Entity Collision for train</h3>
     * this checks an area for blocks and other entities and returns true if there is something in that area besides what is supposed to be, (mounted players and bogies).
     */
public boolean getCollision(GenericRailTransport transport) {
    //Be sure the transport has hitboxes
    for (int iteration = 0; iteration < transport.getHitboxPositions().length; iteration++) {
        double[] position = RailUtility.rotatePoint(new double[] { transport.getHitboxPositions()[iteration], 0, 0 }, transport.rotationPitch, transport.rotationYaw, 0);
        if (hitboxList.size() <= iteration || transport.ticksExisted == 0) {
            hitboxList.add(new MultipartHitbox(transport, transport, position[0] + transport.posX, position[1] + transport.posY, position[2] + transport.posZ));
            transport.worldObj.spawnEntityInWorld(hitboxList.get(iteration));
        } else {
            hitboxList.get(iteration).setLocationAndAngles(position[0] + transport.posX, position[1] + transport.posY, position[2] + transport.posZ, transport.rotationYaw, transport.rotationPitch);
        }
    }
    //initialize the variables before the loop to save some CPU
    int k1;
    int l1;
    int i2;
    int l;
    int i1;
    int j1;
    List list;
    Entity entity;
    double[][] vectorCache = new double[2][3];
    //detect collisions with blocks on X, Y, and Z.
    for (MultipartHitbox box : hitboxList) {
        //define the values as temporary variables first since it will be faster than flooring the variable every loop check
        k1 = MathHelper.floor_double(box.boundingBox.minX);
        l1 = MathHelper.floor_double(box.boundingBox.minY);
        i2 = MathHelper.floor_double(box.boundingBox.minZ);
        l = MathHelper.floor_double(box.boundingBox.maxX);
        i1 = MathHelper.floor_double(box.boundingBox.maxY);
        j1 = MathHelper.floor_double(box.boundingBox.maxZ);
        /*
             * check if the chunk exists, then loop for X, Y, and Z to check for a rail or an air block.
             * if one isnt found return true to stop the movement.
             * @see GenericRailTransport#onUpdate()
             */
        if (transport.worldObj.checkChunksExist(k1, l1, i2, l, i1, j1)) {
            for (; k1 <= l; ++k1) {
                for (; l1 <= i1; ++l1) {
                    for (; i2 <= j1; ++i2) {
                        if (!(transport.worldObj.getBlock(k1, l1, i2) instanceof BlockAir) && !RailUtility.isRailBlockAt(transport.worldObj, k1, l1, i2)) {
                            return true;
                        }
                    }
                }
            }
        }
        /*
             * detect collision with entities.
             * we have to create a temporary bounding box that's larger than the current so we can check just a bit past the current box, this gives collision events a bit more time to react.
             * from there we create a list of entities in the new hitbox, and then loop through them to figure out what happens, we can't use the list directly due to concurrent modifications.
             */
        list = transport.worldObj.getEntitiesWithinAABBExcludingEntity(transport, box.boundingBox.copy().expand(0.35, 0, 0.35));
        if (list != null && list.size() > 0) {
            for (Object obj : list) {
                /*cast the entity ahead of time, so we don't need to cast it over and over later.*/
                if (obj instanceof Entity) {
                    entity = (Entity) obj;
                } else {
                    continue;
                }
                /*if it's something we don't collide with, skip to next iteration.*/
                if (entity instanceof EntityBogie || entity instanceof GenericRailTransport || entity.ridingEntity instanceof EntitySeat || entity.ridingEntity instanceof GenericRailTransport || hitboxList.contains(entity)) {
                    continue;
                }
                /*if it's an item, check if we should add it to the inventory, maybe do it, and continue to the next iteration*/
                if (entity instanceof EntityItem) {
                    if (transport.getType().isHopper() && transport.isItemValidForSlot(0, ((EntityItem) entity).getEntityItem()) && ((EntityItem) entity).posY > transport.posY + 1) {
                        transport.addItem(((EntityItem) entity).getEntityItem());
                        ((EntityItem) entity).worldObj.removeEntity((EntityItem) entity);
                    }
                    continue;
                }
                /*if the parent is an Entity Rollingstock, and the other checks were false, we now need to check if we roadkill the entity, or get pushed by it.*/
                if (transport instanceof EntityRollingStockCore) {
                    if (transport.frontBogie.motionX > 0.5 || transport.frontBogie.motionX < -0.5 || transport.frontBogie.motionZ > 0.5 || transport.frontBogie.motionZ < -0.5) {
                        //in the case of roadkill
                        entity.attackEntityFrom(new EntityDamageSource("rollingstock", transport), (float) (transport.frontBogie.motionX + transport.frontBogie.motionZ) * 1000);
                        if (transport.worldObj.isRemote) {
                            entity.applyEntityCollision(transport);
                        }
                    } else {
                        vectorCache[0][0] = entity.posX - transport.posX;
                        vectorCache[0][2] = entity.posZ - transport.posZ;
                        vectorCache[0][1] = MathHelper.sqrt_double(vectorCache[0][0] * vectorCache[0][0] + vectorCache[0][2] * vectorCache[0][2]);
                        if (vectorCache[0][1] >= 0.00999999987D) {
                            vectorCache[0][0] /= vectorCache[0][1];
                            vectorCache[0][2] /= vectorCache[0][1];
                            vectorCache[0][0] *= 1.0D / vectorCache[0][1];
                            vectorCache[0][2] *= 1.0D / vectorCache[0][1];
                            vectorCache[0][0] *= 0.05000000074444445D;
                            vectorCache[0][2] *= 0.05000000074444445D;
                            transport.frontBogie.addVelocity(-vectorCache[0][0], 0.0D, -vectorCache[0][2]);
                            transport.backBogie.addVelocity(-vectorCache[0][0], 0.0D, -vectorCache[0][2]);
                        }
                        entity.applyEntityCollision(transport);
                    }
                /*however if this was n entity Train Core, we just have to figure out if we should roadkill it.*/
                } else if (transport.frontVelocityX > 0.5 || transport.frontVelocityX < -0.5 || transport.frontVelocityZ > 0.5 || transport.frontVelocityZ < -0.5) {
                    entity.attackEntityFrom(new EntityDamageSource("train", transport), (float) (transport.frontVelocityX + transport.frontVelocityZ) * 1000);
                    if (transport.worldObj.isRemote) {
                        entity.applyEntityCollision(transport);
                    }
                } else {
                    boolean bool = rand.nextBoolean();
                    vectorCache[0][0] = bool ? 0.05 : 0;
                    vectorCache[0][2] = bool ? 0 : 0.05;
                    vectorCache[1] = RailUtility.rotatePoint(vectorCache[0], 0, transport.rotationYaw, 0);
                    entity.addVelocity(vectorCache[0][0], -0.5, vectorCache[0][2]);
                    entity.applyEntityCollision(transport);
                }
            }
        }
    }
    //returning true stops the transport, false lets it move.
    return false;
}
Also used : BlockAir(net.minecraft.block.BlockAir) Entity(net.minecraft.entity.Entity) EntityDamageSource(net.minecraft.util.EntityDamageSource) ArrayList(java.util.ArrayList) List(java.util.List) EntityItem(net.minecraft.entity.item.EntityItem)

Example 2 with BlockAir

use of net.minecraft.block.BlockAir in project RFToolsDimensions by McJty.

the class GenericWorldGenerator method initMachines.

private static void initMachines() {
    machines = new ArrayList<>();
    Block crafter1 = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("rftools", "crafter1"));
    if (!(crafter1 instanceof BlockAir)) {
        machines.add(random -> crafter1.getDefaultState().withProperty(BaseBlock.FACING, EnumFacing.HORIZONTALS[random.nextInt(EnumFacing.HORIZONTALS.length)]));
    }
    Block powercell_simple = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("rftools", "powercell_simple"));
    if (!(powercell_simple instanceof BlockAir)) {
        machines.add(random -> powercell_simple.getDefaultState());
    }
    Block rf_monitor = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("rftools", "rf_monitor"));
    if (!(rf_monitor instanceof BlockAir)) {
        machines.add(random -> rf_monitor.getDefaultState().withProperty(BaseBlock.FACING, EnumFacing.HORIZONTALS[random.nextInt(EnumFacing.HORIZONTALS.length)]));
    }
    Block crafter2 = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("rftools", "crafter2"));
    if (!(crafter2 instanceof BlockAir)) {
        machines.add(random -> crafter2.getDefaultState().withProperty(BaseBlock.FACING, EnumFacing.HORIZONTALS[random.nextInt(EnumFacing.HORIZONTALS.length)]));
    }
}
Also used : BlockAir(net.minecraft.block.BlockAir) ResourceLocation(net.minecraft.util.ResourceLocation) BaseBlock(mcjty.lib.container.BaseBlock) Block(net.minecraft.block.Block)

Example 3 with BlockAir

use of net.minecraft.block.BlockAir in project Fracture by HellFirePvP.

the class TileFissureDevice method getOffsetRangeData.

public Map<BlockPos, IBlockState> getOffsetRangeData(@Nullable Map<BlockPos, IBlockState> existingData) {
    int range = Math.max(0, getStructureDepth()) * 4;
    Map<BlockPos, IBlockState> data = new HashMap<>();
    for (int xx = -range; xx <= range; xx++) {
        for (int zz = -range; zz <= range; zz++) {
            BlockPos offsetXZ = getPos().add(xx, 0, zz);
            if (world.isBlockLoaded(offsetXZ) || existingData == null) {
                for (int yy = -range; yy <= range; yy++) {
                    BlockPos offset = new BlockPos(xx, yy, zz);
                    BlockPos real = getPos().add(offset);
                    IBlockState state = world.getBlockState(real);
                    if (state.getBlockHardness(world, real) >= 0 && world.getTileEntity(real) == null && !(state.getBlock() instanceof BlockAir)) {
                        data.put(offset, state);
                    }
                }
            } else {
                for (BlockPos key : existingData.keySet()) {
                    if (key.getX() == xx && key.getZ() == zz) {
                        data.put(key, existingData.get(key));
                    }
                }
            }
        }
    }
    return data;
}
Also used : BlockAir(net.minecraft.block.BlockAir) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockAir

use of net.minecraft.block.BlockAir in project SomeModjam5Mod by HellFirePvP.

the class TranslucentFissureFX method batchRender.

private static void batchRender(float pTicks, Map<BlockPos, Tuple<FissureData, FissureData>> fissures, IBlockAccess iba) {
    BlockRendererDispatcher brd = Minecraft.getMinecraft().getBlockRendererDispatcher();
    batchDList = GLAllocation.generateDisplayLists(1);
    GlStateManager.enableBlend();
    Blending.OVERLAYDARK.applyStateManager();
    Blending.OVERLAYDARK.apply();
    GlStateManager.glNewList(batchDList, GL11.GL_COMPILE);
    Tessellator tes = Tessellator.getInstance();
    BufferBuilder vb = tes.getBuffer();
    vb.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    // Overlap....
    List<BlockPos> rendered = new ArrayList<>();
    for (Map.Entry<BlockPos, Tuple<FissureData, FissureData>> fissureData : fissures.entrySet()) {
        FissureData limiter = fissureData.getValue().getSecond();
        for (BlockPos offset : BlockPos.getAllInBox(limiter.getMin().add(fissureData.getKey()), limiter.getMax().add(fissureData.getKey()))) {
            if (offset.equals(fissureData.getKey()))
                continue;
            IBlockState real = Minecraft.getMinecraft().world.getBlockState(offset);
            IBlockState state = iba.getBlockState(offset);
            if (real.getBlock() instanceof BlockAir) {
                rendered.add(offset);
            } else if ((state.getBlock() instanceof BlockAir) && !rendered.contains(offset)) {
                rendered.add(offset);
                brd.renderBlock(real, offset, Minecraft.getMinecraft().world, vb);
            }
        }
    }
    vb.sortVertexData((float) TileEntityRendererDispatcher.staticPlayerX, (float) TileEntityRendererDispatcher.staticPlayerY, (float) TileEntityRendererDispatcher.staticPlayerZ);
    tes.draw();
    GlStateManager.glEndList();
    Blending.DEFAULT.applyStateManager();
    Blending.DEFAULT.apply();
    GlStateManager.color(1F, 1F, 1F, 1F);
    GL11.glColor4f(1F, 1F, 1F, 1F);
}
Also used : BlockAir(net.minecraft.block.BlockAir) FissureData(hellfirepvp.fracture.common.fissure.FissureData) IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos) Tuple(net.minecraft.util.Tuple)

Example 5 with BlockAir

use of net.minecraft.block.BlockAir in project SomeModjam5Mod by HellFirePvP.

the class TileFissureDevice method getOffsetRangeData.

public Map<BlockPos, IBlockState> getOffsetRangeData(@Nullable Map<BlockPos, IBlockState> existingData) {
    int range = Math.max(0, getStructureDepth()) * 4;
    Map<BlockPos, IBlockState> data = new HashMap<>();
    for (int xx = -range; xx <= range; xx++) {
        for (int zz = -range; zz <= range; zz++) {
            BlockPos offsetXZ = getPos().add(xx, 0, zz);
            if (world.isBlockLoaded(offsetXZ) || existingData == null) {
                for (int yy = -range; yy <= range; yy++) {
                    BlockPos offset = new BlockPos(xx, yy, zz);
                    BlockPos real = getPos().add(offset);
                    IBlockState state = world.getBlockState(real);
                    if (state.getBlockHardness(world, real) >= 0 && world.getTileEntity(real) == null && !(state.getBlock() instanceof BlockAir)) {
                        data.put(offset, state);
                    }
                }
            } else {
                for (BlockPos key : existingData.keySet()) {
                    if (key.getX() == xx && key.getZ() == zz) {
                        data.put(key, existingData.get(key));
                    }
                }
            }
        }
    }
    return data;
}
Also used : BlockAir(net.minecraft.block.BlockAir) IBlockState(net.minecraft.block.state.IBlockState) HashMap(java.util.HashMap) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

BlockAir (net.minecraft.block.BlockAir)15 Block (net.minecraft.block.Block)8 IBlockState (net.minecraft.block.state.IBlockState)7 BlockPos (net.minecraft.util.math.BlockPos)5 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)3 BlockPos (net.minecraft.util.BlockPos)3 FissureData (hellfirepvp.fracture.common.fissure.FissureData)2 HashMap (java.util.HashMap)2 BaseBlock (mcjty.lib.container.BaseBlock)2 Entity (net.minecraft.entity.Entity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Tuple (net.minecraft.util.Tuple)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ModularStorageTileEntity (mcjty.rftools.blocks.storage.ModularStorageTileEntity)1