Search in sources :

Example 41 with IBlockState

use of net.minecraft.block.state.IBlockState in project Witchworks by Um-Mitternacht.

the class BlockFluid method registerModels.

@Override
@SideOnly(Side.CLIENT)
public void registerModels() {
    final Item item = Item.getItemFromBlock(this);
    assert item != null;
    ModelBakery.registerItemVariants(item);
    final ModelResourceLocation modelResourceLocation = new ModelResourceLocation(LibMod.MOD_ID + ":fluid", getFluid().getName());
    ModelLoader.setCustomMeshDefinition(item, stack -> modelResourceLocation);
    ModelLoader.setCustomStateMapper(this, new StateMapperBase() {

        @Override
        protected ModelResourceLocation getModelResourceLocation(IBlockState p_178132_1_) {
            return modelResourceLocation;
        }
    });
}
Also used : StateMapperBase(net.minecraft.client.renderer.block.statemap.StateMapperBase) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 42 with IBlockState

use of net.minecraft.block.state.IBlockState in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsObject method assembleShip.

private void assembleShip(EntityPlayer player, SpatialDetector detector, BlockPos centerInWorld) {
    MutableBlockPos pos = new MutableBlockPos();
    TIntIterator iter = detector.foundSet.iterator();
    int radiusNeeded = 1;
    while (iter.hasNext()) {
        int i = iter.next();
        detector.setPosWithRespectTo(i, BlockPos.ORIGIN, pos);
        int xRad = Math.abs(pos.getX() >> 4);
        int zRad = Math.abs(pos.getZ() >> 4);
        radiusNeeded = Math.max(Math.max(zRad, xRad), radiusNeeded + 1);
    }
    //		radiusNeeded = Math.max(radiusNeeded, 5);
    iter = detector.foundSet.iterator();
    radiusNeeded = Math.min(radiusNeeded, ValkyrienWarfareMod.chunkManager.getManagerForWorld(wrapper.worldObj).maxChunkRadius);
    // System.out.println(radiusNeeded);
    claimNewChunks(radiusNeeded);
    claimedChunks = new Chunk[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
    claimedChunksEntries = new PlayerChunkMapEntry[(ownedChunks.radius * 2) + 1][(ownedChunks.radius * 2) + 1];
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            Chunk chunk = new Chunk(worldObj, x, z);
            injectChunkIntoWorld(chunk, x, z, true);
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ] = chunk;
        }
    }
    //Prevents weird shit from spawning at the edges of a ship
    replaceOuterChunksWithAir();
    VKChunkCache = new VWChunkCache(worldObj, claimedChunks);
    int minChunkX = claimedChunks[0][0].xPosition;
    int minChunkZ = claimedChunks[0][0].zPosition;
    refrenceBlockPos = getRegionCenter();
    centerCoord = new Vector(refrenceBlockPos.getX(), refrenceBlockPos.getY(), refrenceBlockPos.getZ());
    createPhysicsCalculations();
    //The ship just got build, how can it not be the latest?
    physicsProcessor.isShipPastBuild90 = true;
    BlockPos centerDifference = refrenceBlockPos.subtract(centerInWorld);
    while (iter.hasNext()) {
        int i = iter.next();
        detector.setPosWithRespectTo(i, centerInWorld, pos);
        IBlockState state = detector.cache.getBlockState(pos);
        TileEntity worldTile = detector.cache.getTileEntity(pos);
        pos.setPos(pos.getX() + centerDifference.getX(), pos.getY() + centerDifference.getY(), pos.getZ() + centerDifference.getZ());
        ownedChunks.chunkOccupiedInLocal[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ] = true;
        Chunk chunkToSet = claimedChunks[(pos.getX() >> 4) - minChunkX][(pos.getZ() >> 4) - minChunkZ];
        int storageIndex = pos.getY() >> 4;
        if (chunkToSet.storageArrays[storageIndex] == chunkToSet.NULL_BLOCK_STORAGE) {
            chunkToSet.storageArrays[storageIndex] = new ExtendedBlockStorage(storageIndex << 4, true);
        }
        chunkToSet.storageArrays[storageIndex].set(pos.getX() & 15, pos.getY() & 15, pos.getZ() & 15, state);
        if (worldTile != null) {
            NBTTagCompound tileEntNBT = new NBTTagCompound();
            tileEntNBT = worldTile.writeToNBT(tileEntNBT);
            // Change the Block position to be inside of the Ship
            tileEntNBT.setInteger("x", pos.getX());
            tileEntNBT.setInteger("y", pos.getY());
            tileEntNBT.setInteger("z", pos.getZ());
            //Fuck this old code
            //				TileEntity newInstance = VKChunkCache.getTileEntity(pos);
            //				newInstance.readFromNBT(tileEntNBT);
            TileEntity newInstance = TileEntity.create(worldObj, tileEntNBT);
            newInstance.validate();
            Class tileClass = newInstance.getClass();
            Field[] fields = tileClass.getDeclaredFields();
            for (Field field : fields) {
                try {
                    field.setAccessible(true);
                    Object o = field.get(newInstance);
                    if (o != null) {
                        if (o instanceof BlockPos) {
                            BlockPos inTilePos = (BlockPos) o;
                            int hash = detector.getHashWithRespectTo(inTilePos.getX(), inTilePos.getY(), inTilePos.getZ(), detector.firstBlock);
                            if (detector.foundSet.contains(hash)) {
                                if (!(o instanceof MutableBlockPos)) {
                                    inTilePos = inTilePos.add(centerDifference.getX(), centerDifference.getY(), centerDifference.getZ());
                                    field.set(newInstance, inTilePos);
                                } else {
                                    MutableBlockPos mutable = (MutableBlockPos) o;
                                    mutable.setPos(inTilePos.getX() + centerDifference.getX(), inTilePos.getY() + centerDifference.getY(), inTilePos.getZ() + centerDifference.getZ());
                                }
                            }
                        }
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            worldObj.setTileEntity(newInstance.getPos(), newInstance);
            newInstance.markDirty();
        }
    // chunkCache.setBlockState(pos, state);
    // worldObj.setBlockState(pos, state);
    }
    iter = detector.foundSet.iterator();
    short[][] changes = new short[claimedChunks.length][claimedChunks[0].length];
    while (iter.hasNext()) {
        int i = iter.next();
        // BlockPos respectTo = detector.getPosWithRespectTo(i, centerInWorld);
        detector.setPosWithRespectTo(i, centerInWorld, pos);
        // detector.cache.setBlockState(pos, Blocks.air.getDefaultState());
        // TODO: Get this to update on clientside as well, you bastard!
        TileEntity tile = worldObj.getTileEntity(pos);
        if (tile != null) {
            tile.invalidate();
        }
        worldObj.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
    }
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
        //				claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
        // claimedChunks[x-ownedChunks.minX][z-ownedChunks.minZ].checkLight();
        }
    }
    detectBlockPositions();
    //TODO: This fixes the lighting, but it adds lag; maybe remove this
    for (int x = ownedChunks.minX; x <= ownedChunks.maxX; x++) {
        for (int z = ownedChunks.minZ; z <= ownedChunks.maxZ; z++) {
            //				claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].isTerrainPopulated = true;
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].generateSkylightMap();
            claimedChunks[x - ownedChunks.minX][z - ownedChunks.minZ].checkLight();
        }
    }
    coordTransform = new CoordTransformObject(this);
    physicsProcessor.processInitialPhysicsData();
    physicsProcessor.updateParentCenterOfMass();
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) VWChunkCache(ValkyrienWarfareBase.Relocation.VWChunkCache) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SPacketUnloadChunk(net.minecraft.network.play.server.SPacketUnloadChunk) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) TileEntity(net.minecraft.tileentity.TileEntity) Field(java.lang.reflect.Field) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 43 with IBlockState

use of net.minecraft.block.state.IBlockState in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysicsCalculations method calculateForces.

public void calculateForces() {
    double modifiedDrag = Math.pow(drag, physTickSpeed / .05D);
    linearMomentum.multiply(modifiedDrag);
    angularVelocity.multiply(modifiedDrag);
    if (PhysicsSettings.doGravity) {
        addForceAtPoint(new Vector(0, 0, 0), ValkyrienWarfareMod.gravity.getProduct(mass * physTickSpeed));
    }
    addQueuedForces();
    Collections.shuffle(activeForcePositions);
    Vector blockForce = new Vector();
    Vector inBodyWO = new Vector();
    Vector crossVector = new Vector();
    if (PhysicsSettings.doPhysicsBlocks) {
        for (BlockPos pos : activeForcePositions) {
            IBlockState state = parent.VKChunkCache.getBlockState(pos);
            Block blockAt = state.getBlock();
            BigBastardMath.getBodyPosWithOrientation(pos, centerOfMass, parent.coordTransform.lToWRotation, inBodyWO);
            BlockForce.basicForces.getForceFromState(state, pos, worldObj, physTickSpeed, parent, blockForce);
            if (blockForce != null) {
                if (blockAt instanceof IBlockForceProvider) {
                    Vector otherPosition = ((IBlockForceProvider) blockAt).getBlockForcePosition(worldObj, pos, state, parent.wrapper, physTickSpeed);
                    if (otherPosition != null) {
                        BigBastardMath.getBodyPosWithOrientation(otherPosition, centerOfMass, parent.coordTransform.lToWRotation, inBodyWO);
                    }
                }
                addForceAtPoint(inBodyWO, blockForce, crossVector);
            } else {
            }
        }
    }
    if (PhysicsSettings.doBalloons) {
        for (BalloonProcessor balloon : parent.balloonManager.balloonProcessors) {
            balloon.tickBalloonTemperatures(physTickSpeed, this);
            Vector balloonForce = balloon.getBalloonForce(physTickSpeed, this);
            Vector balloonCenterInBody = balloon.getForceCenter();
            BigBastardMath.getBodyPosWithOrientation(balloonCenterInBody, centerOfMass, parent.coordTransform.lToWRotation, inBodyWO);
            addForceAtPoint(inBodyWO, balloonForce, crossVector);
        }
    }
    convertTorqueToVelocity();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BalloonProcessor(ValkyrienWarfareControl.Balloon.BalloonProcessor) IBlockForceProvider(ValkyrienWarfareBase.API.IBlockForceProvider) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 44 with IBlockState

use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.

the class WorldUtil method isNotSolid.

/**
     * Checks if the Block has a bounding box.
     * @param world The world to check in
     * @param pos The position to check
     * @return True if the block has a bounding box, false otherwise.
     */
public static boolean isNotSolid(World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    AxisAlignedBB boundingBox = state.getCollisionBoundingBox(world, pos);
    return boundingBox == null || boundingBox.equals(Block.NULL_AABB);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState)

Example 45 with IBlockState

use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.

the class MapGenCavesRTG method digBlock.

/**
     * Digs out the current block, default implementation removes stone, filler, and top block
     * Sets the block to lava if y is less then 10, and air other wise.
     * If setting to air, it also checks to see if we've broken the surface and if so
     * tries to make the floor the biome's top block
     *
     * @param data
     *     Block data array
     * @param x
     *     local X position
     * @param y
     *     local Y position
     * @param z
     *     local Z position
     * @param chunkX
     *     Chunk X position
     * @param chunkZ
     *     Chunk Y position
     * @param foundTop
     *     True if we've encountered the biome's top block. Ideally if we've broken the surface.
     */
protected void digBlock(ChunkPrimer data, int x, int y, int z, int chunkX, int chunkZ, boolean foundTop, IBlockState state, IBlockState up) {
    net.minecraft.world.biome.Biome biome = world.getBiome(new BlockPos(x + chunkX * 16, 0, z + chunkZ * 16));
    IBlockState top = biome.topBlock;
    IBlockState filler = biome.fillerBlock;
    if (this.canReplaceBlock(state, up) || state.getBlock() == top.getBlock() || state.getBlock() == filler.getBlock()) {
        if (y - 1 < 10) {
            data.setBlockState(x, y, z, BLK_LAVA);
        } else {
            data.setBlockState(x, y, z, BLK_AIR);
            if (foundTop && data.getBlockState(x, y - 1, z).getBlock() == filler.getBlock()) {
                data.setBlockState(x, y - 1, z, top.getBlock().getDefaultState());
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IBlockState (net.minecraft.block.state.IBlockState)798 BlockPos (net.minecraft.util.math.BlockPos)325 Block (net.minecraft.block.Block)246 ItemStack (net.minecraft.item.ItemStack)118 TileEntity (net.minecraft.tileentity.TileEntity)84 EnumFacing (net.minecraft.util.EnumFacing)81 World (net.minecraft.world.World)66 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)42 EntityPlayer (net.minecraft.entity.player.EntityPlayer)34 Entity (net.minecraft.entity.Entity)30 Random (java.util.Random)28 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)28 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)28 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)23 ArrayList (java.util.ArrayList)22 Vec3d (net.minecraft.util.math.Vec3d)22 SoundType (net.minecraft.block.SoundType)21 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)21 ResourceLocation (net.minecraft.util.ResourceLocation)21 RayTraceResult (net.minecraft.util.math.RayTraceResult)21