Search in sources :

Example 76 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class ProPickItem method prospectChunk.

private boolean prospectChunk(World world, ItemStack stack, BlockPos pos, PlayerEntity player) {
    HashSet<BlockState> foundBlocks = new HashSet<BlockState>();
    HashSet<BlockState> depositBlocks = Prospecting.getDepositBlocks();
    ChunkPos tempPos = new ChunkPos(pos);
    for (int x = tempPos.getXStart(); x <= tempPos.getXEnd(); x++) {
        for (int z = tempPos.getZStart(); z <= tempPos.getZEnd(); z++) {
            for (int y = 0; y < world.getHeight(); y++) {
                BlockState state = world.getBlockState(new BlockPos(x, y, z));
                if (depositBlocks.contains(state)) {
                    foundBlocks.add(state);
                }
            }
        }
    }
    if (!foundBlocks.isEmpty()) {
        Geolosys.proxy.sendProspectingMessage(player, foundBlocks, null);
        return true;
    }
    player.sendStatusMessage(new TranslationTextComponent("geolosys.pro_pick.tooltip.nonefound_surface"), true);
    return false;
}
Also used : BlockState(net.minecraft.block.BlockState) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 77 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class PacketHelpers method decodeBlocks.

public static HashSet<BlockState> decodeBlocks(CompoundNBT comp) {
    HashSet<BlockState> ret = new HashSet<BlockState>();
    ListNBT list = comp.getList(BLOCK_NBT_NAME, 10);
    list.forEach((c) -> {
        if (c instanceof CompoundNBT) {
            ret.add(NBTUtil.readBlockState((CompoundNBT) c));
        } else {
            Geolosys.getInstance().LOGGER.error("The following compound appears to be broken: {}", c);
        }
    });
    return ret;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) HashSet(java.util.HashSet)

Example 78 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class SparseDeposit method generate.

/**
 * Handles full-on generation of this type of pluton. Requires 0 arguments as
 * everything is self-contained in this class
 *
 * @return (int) the number of pluton resource blocks placed. If 0 -- this
 *         should be evaluted as a false for use of Mojang's sort-of sketchy
 *         generation code in
 *         {@link DepositFeature#generate(net.minecraft.world.ISeedReader, net.minecraft.world.gen.ChunkGenerator, java.util.Random, net.minecraft.util.math.BlockPos, net.minecraft.world.gen.feature.NoFeatureConfig)}
 */
@Override
public int generate(ISeedReader reader, BlockPos pos, IDepositCapability cap) {
    /* Check biome allowance */
    if (!DepositUtils.canPlaceInBiome(reader.getBiome(pos), this.biomeFilter, this.biomeTypeFilter, this.isBiomeFilterBl)) {
        return 0;
    }
    int totlPlaced = 0;
    int totlPnding = 0;
    ChunkPos thisChunk = new ChunkPos(pos);
    int randY = this.yMin + reader.getRandom().nextInt(this.yMax - this.yMin);
    int max = Utils.getTopSolidBlock(reader, pos).getY();
    if (randY > max) {
        randY = Math.max(yMin, max);
    }
    float ranFlt = reader.getRandom().nextFloat() * (float) Math.PI;
    double x1 = (float) (pos.getX() + 8) + MathHelper.sin(ranFlt) * (float) this.size / 8.0F;
    double x2 = (float) (pos.getX() + 8) - MathHelper.sin(ranFlt) * (float) this.size / 8.0F;
    double z1 = (float) (pos.getZ() + 8) + MathHelper.cos(ranFlt) * (float) this.size / 8.0F;
    double z2 = (float) (pos.getZ() + 8) - MathHelper.cos(ranFlt) * (float) this.size / 8.0F;
    double y1 = randY + reader.getRandom().nextInt(3) - 2;
    double y2 = randY + reader.getRandom().nextInt(3) - 2;
    for (int i = 0; i < this.size; ++i) {
        float radScl = (float) i / (float) this.size;
        double xn = x1 + (x2 - x1) * (double) radScl;
        double yn = y1 + (y2 - y1) * (double) radScl;
        double zn = z1 + (z2 - z1) * (double) radScl;
        double noise = reader.getRandom().nextDouble() * (double) this.size / 16.0D;
        double radius = (double) (MathHelper.sin((float) Math.PI * radScl) + 1.0F) * noise + 1.0D;
        int xmin = MathHelper.floor(xn - radius / 2.0D);
        int ymin = MathHelper.floor(yn - radius / 2.0D);
        int zmin = MathHelper.floor(zn - radius / 2.0D);
        int xmax = MathHelper.floor(xn + radius / 2.0D);
        int ymax = MathHelper.floor(yn + radius / 2.0D);
        int zmax = MathHelper.floor(zn + radius / 2.0D);
        for (int x = xmin; x <= xmax; ++x) {
            double layerRadX = ((double) x + 0.5D - xn) / (radius / 2.0D);
            if (layerRadX * layerRadX < 1.0D) {
                for (int y = ymin; y <= ymax; ++y) {
                    double layerRadY = ((double) y + 0.5D - yn) / (radius / 2.0D);
                    if (layerRadX * layerRadX + layerRadY * layerRadY < 1.0D) {
                        for (int z = zmin; z <= zmax; ++z) {
                            double layerRadZ = ((double) z + 0.5D - zn) / (radius / 2.0D);
                            if (layerRadX * layerRadX + layerRadY * layerRadY + layerRadZ * layerRadZ < 1.0D) {
                                // Randomize spread on the X and Z Axes
                                int xSpread = reader.getRandom().nextInt(this.spread) * (reader.getRandom().nextBoolean() ? 1 : -1);
                                int zSpread = reader.getRandom().nextInt(this.spread) * (reader.getRandom().nextBoolean() ? 1 : -1);
                                BlockPos placePos = new BlockPos(x + xSpread, y, z + zSpread);
                                BlockState tmp = this.getOre();
                                if (tmp == null) {
                                    continue;
                                }
                                // Skip this block if it can't replace the target block
                                if (!this.getBlockStateMatchers().contains(FeatureUtils.tryGetBlockState(reader, thisChunk, placePos))) {
                                    continue;
                                }
                                if (FeatureUtils.tryPlaceBlock(reader, thisChunk, placePos, tmp, cap)) {
                                    totlPlaced++;
                                } else {
                                    totlPnding++;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return totlPlaced + totlPnding;
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 79 with BlockState

use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.

the class BlockColorInit method registerItemColors.

@SubscribeEvent
public static void registerItemColors(ColorHandlerEvent.Item evt) {
    final BlockColors blockColors = evt.getBlockColors();
    final ItemColors itemColors = evt.getItemColors();
    // Use the Block's colour handler for an ItemBlock
    IItemColor itemBlockColourHandler = (stack, tintIndex) -> {
        BlockState state = ((BlockItem) stack.getItem()).getBlock().getDefaultState();
        return blockColors.getColor(state, null, null, tintIndex);
    };
    if (itemBlockColourHandler != null) {
        itemColors.register(itemBlockColourHandler, ModBlocks.getInstance().peat);
        itemColors.register(itemBlockColourHandler, ModBlocks.getInstance().rhododendron);
    }
}
Also used : IItemColor(net.minecraft.client.renderer.color.IItemColor) BlockColors(net.minecraft.client.renderer.color.BlockColors) IItemColor(net.minecraft.client.renderer.color.IItemColor) BiomeColors(net.minecraft.world.biome.BiomeColors) ItemColors(net.minecraft.client.renderer.color.ItemColors) BlockItem(net.minecraft.item.BlockItem) GrassColors(net.minecraft.world.GrassColors) Mod(net.minecraftforge.fml.common.Mod) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) BlockState(net.minecraft.block.BlockState) ColorHandlerEvent(net.minecraftforge.client.event.ColorHandlerEvent) ModBlocks(com.oitsjustjose.geolosys.common.blocks.ModBlocks) Dist(net.minecraftforge.api.distmarker.Dist) BlockState(net.minecraft.block.BlockState) ItemColors(net.minecraft.client.renderer.color.ItemColors) BlockColors(net.minecraft.client.renderer.color.BlockColors) BlockItem(net.minecraft.item.BlockItem) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

BlockState (net.minecraft.block.BlockState)79 BlockPos (net.minecraft.util.math.BlockPos)32 TileEntity (net.minecraft.tileentity.TileEntity)19 Direction (net.minecraft.util.Direction)16 Nonnull (javax.annotation.Nonnull)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)12 World (net.minecraft.world.World)12 ChunkPos (net.minecraft.util.math.ChunkPos)11 Block (net.minecraft.block.Block)10 Nullable (javax.annotation.Nullable)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashSet (java.util.HashSet)4 Blocks (net.minecraft.block.Blocks)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ServerWorld (net.minecraft.world.server.ServerWorld)4 IForgeBlockState (net.minecraftforge.common.extensions.IForgeBlockState)4 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)3 AgriCraft (com.infinityraider.agricraft.AgriCraft)3 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)3