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;
}
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;
}
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;
}
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);
}
}
Aggregations