Search in sources :

Example 26 with IBlockState

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

the class TreeRTGQuercusRobur method generateTrunk.

/**
     * Places the trunk for the big tree that is being generated. Able to generate double-sized trunks by changing a
     * field that is always 1 to 2.
     */
void generateTrunk() {
    BlockPos blockpos = this.basePos;
    BlockPos blockpos1 = this.basePos.up(this.height);
    IBlockState block = this.logBlock;
    this.func_175937_a(blockpos, blockpos1, block);
    if (this.trunkSize == 2) {
        this.func_175937_a(blockpos.east(), blockpos1.east(), block);
        this.func_175937_a(blockpos.east().south(), blockpos1.east().south(), block);
        this.func_175937_a(blockpos.south(), blockpos1.south(), block);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 27 with IBlockState

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

the class TreeRTGPinusMonticola method buildLeaves.

@Override
public void buildLeaves(World world, int x, int y, int z) {
    if (!this.noLeaves) {
        IBlockState b = world.getBlockState(new BlockPos(x, y, z));
        this.placeLeavesBlock(world, new BlockPos(x, y, z), this.leavesBlock, this.generateFlag);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockPos(net.minecraft.util.math.BlockPos)

Example 28 with IBlockState

use of net.minecraft.block.state.IBlockState in project Guide-API by TeamAmeriFrance.

the class ItemGuideBook method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!world.isRemote || !player.isSneaking())
        return EnumActionResult.PASS;
    ItemStack stack = player.getHeldItem(hand);
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() instanceof IGuideLinked) {
        IGuideLinked guideLinked = (IGuideLinked) state.getBlock();
        ResourceLocation entryKey = guideLinked.getLinkedEntry(world, pos, player, stack);
        if (entryKey == null)
            return EnumActionResult.FAIL;
        for (CategoryAbstract category : book.getCategoryList()) {
            if (category.entries.containsKey(entryKey)) {
                GuideMod.proxy.openEntry(book, category, category.entries.get(entryKey), player, stack);
                return EnumActionResult.SUCCESS;
            }
        }
    }
    return EnumActionResult.PASS;
}
Also used : IGuideLinked(amerifrance.guideapi.api.IGuideLinked) IBlockState(net.minecraft.block.state.IBlockState) CategoryAbstract(amerifrance.guideapi.api.impl.abstraction.CategoryAbstract) ItemStack(net.minecraft.item.ItemStack)

Example 29 with IBlockState

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

the class WorldPhysicsCollider method updatePotentialCollisionCache.

private void updatePotentialCollisionCache() {
    final AxisAlignedBB collisionBB = parent.collisionBB.expand(expansion, expansion, expansion).addCoord(calculator.linearMomentum.X * calculator.invMass, calculator.linearMomentum.Y * calculator.invMass, calculator.linearMomentum.Z * calculator.invMass);
    ticksSinceCacheUpdate = 0D;
    //in the same tick
    if (Math.random() > .5) {
        ticksSinceCacheUpdate -= .05D;
    }
    // cachedPotentialHits = new ArrayList<BlockPos>();
    cachedPotentialHits = new TIntArrayList();
    // Ship is outside of world blockSpace, just skip this all together
    if (collisionBB.maxY < 0 || collisionBB.minY > 255) {
        // internalCachedPotentialHits = new BlockPos[0];
        return;
    }
    //Has a -1 on the minY value, I hope this helps with preventing things from falling through the floor
    final BlockPos min = new BlockPos(collisionBB.minX, Math.max(collisionBB.minY - 1, 0), collisionBB.minZ);
    final BlockPos max = new BlockPos(collisionBB.maxX, Math.min(collisionBB.maxY, 255), collisionBB.maxZ);
    centerPotentialHit = new BlockPos((min.getX() + max.getX()) / 2D, (min.getY() + max.getY()) / 2D, (min.getZ() + max.getZ()) / 2D);
    final ChunkCache cache = parent.surroundingWorldChunksCache;
    final Vector inLocal = new Vector();
    int maxX, maxY, maxZ, localX, localY, localZ, x, y, z, chunkX, chunkZ;
    double rangeCheck = 1.8D;
    if (ValkyrienWarfareMod.highAccuracyCollisions) {
        rangeCheck = 3D;
    }
    Chunk chunk, chunkIn;
    ExtendedBlockStorage extendedblockstorage;
    IBlockState state, localState;
    int chunkMinX = min.getX() >> 4;
    int chunkMaxX = (max.getX() >> 4) + 1;
    int storageMinY = min.getY() >> 4;
    int storageMaxY = (max.getY() >> 4) + 1;
    int chunkMinZ = min.getZ() >> 4;
    int chunkMaxZ = (max.getZ() >> 4) + 1;
    int storageY;
    int mmX = min.getX(), mmY = min.getY(), mmZ = min.getZ(), mxX = max.getX(), mxY = max.getY(), mxZ = max.getZ();
    Vector inBody = new Vector();
    Vector speedInBody = new Vector();
    for (chunkX = chunkMinX; chunkX < chunkMaxX; chunkX++) {
        for (chunkZ = chunkMinZ; chunkZ < chunkMaxZ; chunkZ++) {
            int arrayChunkX = chunkX - cache.chunkX;
            int arrayChunkZ = chunkZ - cache.chunkZ;
            if (!(arrayChunkX < 0 || arrayChunkZ < 0 || arrayChunkX > cache.chunkArray.length - 1 || arrayChunkZ > cache.chunkArray[0].length - 1)) {
                chunk = cache.chunkArray[arrayChunkX][arrayChunkZ];
                for (storageY = storageMinY; storageY < storageMaxY; storageY++) {
                    extendedblockstorage = chunk.storageArrays[storageY];
                    if (extendedblockstorage != null) {
                        int minStorageX = chunkX << 4;
                        int minStorageY = storageY << 4;
                        int minStorageZ = chunkZ << 4;
                        int maxStorageX = minStorageX + 16;
                        int maxStorageY = minStorageY + 16;
                        int maxStorageZ = minStorageZ + 16;
                        minStorageX = Math.max(minStorageX, mmX);
                        minStorageY = Math.max(minStorageY, mmY);
                        minStorageZ = Math.max(minStorageZ, mmZ);
                        maxStorageX = Math.min(maxStorageX, mxX);
                        maxStorageY = Math.min(maxStorageY, mxY);
                        maxStorageZ = Math.min(maxStorageZ, mxZ);
                        for (x = minStorageX; x < maxStorageX; x++) {
                            for (y = minStorageY; y < maxStorageY; y++) {
                                for (z = minStorageZ; z < maxStorageZ; z++) {
                                    state = extendedblockstorage.get(x & 15, y & 15, z & 15);
                                    if (state.getMaterial().isSolid()) {
                                        inLocal.X = x + .5D;
                                        inLocal.Y = y + .5D;
                                        inLocal.Z = z + .5D;
                                        parent.coordTransform.fromGlobalToLocal(inLocal);
                                        inBody.setSubtraction(inLocal, parent.centerCoord);
                                        parent.physicsProcessor.setVectorToVelocityAtPoint(inBody, speedInBody);
                                        speedInBody.multiply(-parent.physicsProcessor.physRawSpeed);
                                        if (ValkyrienWarfareMod.highAccuracyCollisions) {
                                            speedInBody.multiply(20D);
                                        }
                                        //											System.out.println(speedInBody);
                                        int minX, minY, minZ;
                                        if (speedInBody.X > 0) {
                                            minX = MathHelper.floor_double(inLocal.X - rangeCheck);
                                            maxX = MathHelper.floor_double(inLocal.X + rangeCheck + speedInBody.X);
                                        } else {
                                            minX = MathHelper.floor_double(inLocal.X - rangeCheck + speedInBody.X);
                                            maxX = MathHelper.floor_double(inLocal.X + rangeCheck);
                                        }
                                        if (speedInBody.Y > 0) {
                                            minY = MathHelper.floor_double(inLocal.Y - rangeCheck);
                                            maxY = MathHelper.floor_double(inLocal.Y + rangeCheck + speedInBody.Y);
                                        } else {
                                            minY = MathHelper.floor_double(inLocal.Y - rangeCheck + speedInBody.Y);
                                            maxY = MathHelper.floor_double(inLocal.Y + rangeCheck);
                                        }
                                        if (speedInBody.Z > 0) {
                                            minZ = MathHelper.floor_double(inLocal.Z - rangeCheck);
                                            maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck + speedInBody.Z);
                                        } else {
                                            minZ = MathHelper.floor_double(inLocal.Z - rangeCheck + speedInBody.Z);
                                            maxZ = MathHelper.floor_double(inLocal.Z + rangeCheck);
                                        }
                                        /** The Old Way of doing things; approx. 33% slower overall when running this code instead of new
											for (localX = minX; localX < maxX; localX++) {
												for (localZ = minZ; localZ < maxZ; localZ++) {
													for (localY = minY; localY < maxY; localY++) {
														if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
															chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
															localState = chunkIn.getBlockState(localX, localY, localZ);
															if (localState.getMaterial().isSolid()) {
																cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
																localX = localY = localZ = Integer.MAX_VALUE - 420;
															}
														}
													}
												}
											}
											**/
                                        int shipChunkMinX = minX >> 4;
                                        int shipChunkMinY = Math.max(minY >> 4, 0);
                                        int shipChunkMinZ = minZ >> 4;
                                        int shipChunkMaxX = maxX >> 4;
                                        int shipChunkMaxY = Math.min(maxY >> 4, 15);
                                        int shipChunkMaxZ = maxZ >> 4;
                                        shipChunkMaxX++;
                                        shipChunkMaxY++;
                                        shipChunkMaxZ++;
                                        if (shipChunkMaxZ - shipChunkMinZ > 200 || shipChunkMaxX - shipChunkMinX > 200) {
                                            System.err.println("Wtf. This fucking error");
                                            return;
                                        }
                                        testForNearbyBlocks: for (int shipChunkX = shipChunkMinX; shipChunkX < shipChunkMaxX; shipChunkX++) {
                                            for (int shipChunkZ = shipChunkMinZ; shipChunkZ < shipChunkMaxZ; shipChunkZ++) {
                                                if (parent.ownsChunk(shipChunkX, shipChunkZ)) {
                                                    chunkIn = parent.VKChunkCache.getChunkAt(shipChunkX, shipChunkZ);
                                                    for (int shipChunkYStorage = shipChunkMinY; shipChunkYStorage < shipChunkMaxY; shipChunkYStorage++) {
                                                        ExtendedBlockStorage storage = chunkIn.storageArrays[shipChunkYStorage];
                                                        if (storage != null) {
                                                            int shipStorageMinX = shipChunkX << 4;
                                                            int shipStorageMinY = shipChunkYStorage << 4;
                                                            int shipStorageMinZ = shipChunkZ << 4;
                                                            int shipStorageMaxX = shipStorageMinX + 16;
                                                            int shipStorageMaxY = shipStorageMinY + 16;
                                                            int shipStorageMaxZ = shipStorageMinZ + 16;
                                                            shipStorageMinX = Math.max(shipStorageMinX, minX);
                                                            shipStorageMinY = Math.max(shipStorageMinY, minY);
                                                            shipStorageMinZ = Math.max(shipStorageMinZ, minZ);
                                                            shipStorageMaxX = Math.min(shipStorageMaxX, maxX);
                                                            shipStorageMaxY = Math.min(shipStorageMaxY, maxY);
                                                            shipStorageMaxZ = Math.min(shipStorageMaxZ, maxZ);
                                                            for (localX = shipStorageMinX; localX < shipStorageMaxX; localX++) {
                                                                for (localY = shipStorageMinY; localY < shipStorageMaxY; localY++) {
                                                                    for (localZ = shipStorageMinZ; localZ < shipStorageMaxZ; localZ++) {
                                                                        localState = chunkIn.getBlockState(localX, localY, localZ);
                                                                        if (localState.getMaterial().isSolid()) {
                                                                            cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
                                                                            break testForNearbyBlocks;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    /**
		for (x = min.getX(); x <= max.getX(); x++) {
			for (z = min.getZ(); z < max.getZ(); z++) {
				chunkX = (x >> 4) - cache.chunkX;
				chunkZ = (z >> 4) - cache.chunkZ;
				if (!(chunkX < 0 || chunkZ < 0 || chunkX > cache.chunkArray.length - 1 || chunkZ > cache.chunkArray[0].length - 1)) {
					chunk = cache.chunkArray[chunkX][chunkZ];
					for (y = min.getY(); y < max.getY(); y++) {
						extendedblockstorage = chunk.storageArrays[y >> 4];
						if (extendedblockstorage != null) {
							state = extendedblockstorage.get(x & 15, y & 15, z & 15);

							if (state.getMaterial().isSolid()) {
								inLocal.X = x + .5D;
								inLocal.Y = y + .5D;
								inLocal.Z = z + .5D;
								parent.coordTransform.fromGlobalToLocal(inLocal);

								maxX = (int) Math.floor(inLocal.X + rangeCheck);
								maxY = (int) Math.floor(inLocal.Y + rangeCheck);
								maxZ = (int) Math.floor(inLocal.Z + rangeCheck);

								for (localX = MathHelper.floor_double(inLocal.X - rangeCheck); localX < maxX; localX++) {
									for (localZ = MathHelper.floor_double(inLocal.Z - rangeCheck); localZ < maxZ; localZ++) {
										for (localY = MathHelper.floor_double(inLocal.Y - rangeCheck); localY < maxY; localY++) {
											if (parent.ownsChunk(localX >> 4, localZ >> 4)) {
												chunkIn = parent.VKChunkCache.getChunkAt(localX >> 4, localZ >> 4);
												localState = chunkIn.getBlockState(localX, localY, localZ);
												if (localState.getMaterial().isSolid()) {
													cachedPotentialHits.add(SpatialDetector.getHashWithRespectTo(x, y, z, centerPotentialHit));
													localX = localY = localZ = Integer.MAX_VALUE - 420;
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		**/
    cachedPotentialHits.shuffle(rand);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) ChunkCache(net.minecraft.world.ChunkCache) BlockPos(net.minecraft.util.math.BlockPos) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) Vector(ValkyrienWarfareBase.API.Vector) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Example 30 with IBlockState

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

the class WorldPhysicsCollider method processPotentialCollisionsAccurately.

// Runs through the cache ArrayList, checking each possible BlockPos for SOLID blocks that can collide, if it finds any it will
// move to the next method
//TODO: Optimize from here, this is taking 10x the processing time of updating collision cache!
private void processPotentialCollisionsAccurately() {
    final MutableBlockPos localCollisionPos = new MutableBlockPos();
    final Vector inWorld = new Vector();
    int minX, minY, minZ, maxX, maxY, maxZ, x, y, z;
    final double rangeCheck = .65D;
    TIntIterator intIterator = cachedPotentialHits.iterator();
    while (intIterator.hasNext()) {
        // Converts the int to a mutablePos
        SpatialDetector.setPosWithRespectTo(intIterator.next(), centerPotentialHit, mutablePos);
        inWorld.X = mutablePos.getX() + .5;
        inWorld.Y = mutablePos.getY() + .5;
        inWorld.Z = mutablePos.getZ() + .5;
        parent.coordTransform.fromGlobalToLocal(inWorld);
        minX = MathHelper.floor_double(inWorld.X - rangeCheck);
        minY = MathHelper.floor_double(inWorld.Y - rangeCheck);
        minZ = MathHelper.floor_double(inWorld.Z - rangeCheck);
        maxX = MathHelper.floor_double(inWorld.X + rangeCheck);
        maxY = MathHelper.floor_double(inWorld.Y + rangeCheck);
        maxZ = MathHelper.floor_double(inWorld.Z + rangeCheck);
        /**
			 * Something here is causing the game to freeze :/
			 */
        int minChunkX = minX >> 4;
        int minChunkY = minY >> 4;
        int minChunkZ = minZ >> 4;
        int maxChunkX = maxX >> 4;
        int maxChunkY = maxY >> 4;
        int maxChunkZ = maxZ >> 4;
        entireLoop: if (!(minChunkY > 15 || maxChunkY < 0)) {
            for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) {
                for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ++) {
                    if (parent.ownsChunk(chunkX, chunkZ)) {
                        final Chunk chunkIn = parent.VKChunkCache.getChunkAt(chunkX, chunkZ);
                        int minXToCheck = chunkX << 4;
                        int maxXToCheck = minXToCheck + 15;
                        int minZToCheck = chunkZ << 4;
                        int maxZToCheck = minZToCheck + 15;
                        minXToCheck = Math.max(minXToCheck, minX);
                        maxXToCheck = Math.min(maxXToCheck, maxX);
                        minZToCheck = Math.max(minZToCheck, minZ);
                        maxZToCheck = Math.min(maxZToCheck, maxZ);
                        for (int chunkY = minChunkY; chunkY <= maxChunkY; chunkY++) {
                            ExtendedBlockStorage storage = chunkIn.storageArrays[chunkY];
                            if (storage != null) {
                                int minYToCheck = chunkY << 4;
                                int maxYToCheck = minYToCheck + 15;
                                minYToCheck = Math.max(minYToCheck, minY);
                                maxYToCheck = Math.min(maxYToCheck, maxY);
                                for (x = minXToCheck; x <= maxXToCheck; x++) {
                                    for (z = minZToCheck; z <= maxZToCheck; z++) {
                                        for (y = minYToCheck; y <= maxYToCheck; y++) {
                                            final IBlockState state = storage.get(x & 15, y & 15, z & 15);
                                            if (state.getMaterial().isSolid()) {
                                                localCollisionPos.setPos(x, y, z);
                                                boolean brokeAWorldBlock = handleLikelyCollision(mutablePos, localCollisionPos, parent.surroundingWorldChunksCache.getBlockState(mutablePos), state);
                                                if (brokeAWorldBlock) {
                                                    int positionRemoved = SpatialDetector.getHashWithRespectTo(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ(), centerPotentialHit);
                                                    cachedHitsToRemove.add(positionRemoved);
                                                    break entireLoop;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    //The old way of doing things
    /*for (x = minX; x <= maxX; x++) {
				for (z = minZ; z <= maxZ; z++) {
					if (parent.ownsChunk(x >> 4, z >> 4)) {
						for (y = minY; y <= maxY; y++) {
							final Chunk chunkIn = parent.VKChunkCache.getChunkAt(x >> 4, z >> 4);
							final IBlockState state = chunkIn.getBlockState(x, y, z);
							if (state.getMaterial().isSolid()) {
								localCollisionPos.setPos(x, y, z);

								handleLikelyCollision(mutablePos, localCollisionPos, parent.surroundingWorldChunksCache.getBlockState(mutablePos), state);
							}
						}
					}
				}
			}*/
    }
}
Also used : TIntIterator(gnu.trove.iterator.TIntIterator) IBlockState(net.minecraft.block.state.IBlockState) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) Vector(ValkyrienWarfareBase.API.Vector)

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