use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBPMultipart method load.
@Override
public void load(BlockState blockState, CompoundNBT compound) {
super.load(blockState, compound);
Map<BlockState, TileEntity> states = new HashMap<>();
int size = compound.getInt("size");
for (int i = 0; i < size; i++) {
Optional<Pair<BlockState, INBT>> result = BlockState.CODEC.decode(new Dynamic<>(NBTDynamicOps.INSTANCE, compound.get("state" + i))).result();
if (result.isPresent()) {
BlockState state = result.get().getFirst();
TileEntity tile = state.getBlock().createTileEntity(state, getLevel());
if (tile != null) {
tile.load(state, compound.getCompound("tile" + i));
tile.setPosition(worldPosition);
}
states.put(state, tile);
}
}
this.stateMap = states;
markDirtyClient();
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBPMultipart method removeState.
public void removeState(BlockState state) {
// Drop Items
if (level instanceof ServerWorld) {
NonNullList<ItemStack> drops = NonNullList.create();
drops.addAll(Block.getDrops(state, (ServerWorld) level, worldPosition, this));
InventoryHelper.dropContents(level, worldPosition, drops);
}
// Remove Tile Entity
if (stateMap.get(state) != null) {
stateMap.get(state).setRemoved();
}
// Remove State
this.stateMap.remove(state);
markDirtyClient();
if (stateMap.size() == 1) {
// Convert back to Standalone Block
TileEntity te = (TileEntity) stateMap.values().toArray()[0];
if (level != null) {
CompoundNBT nbt = te != null ? te.save(new CompoundNBT()) : null;
level.setBlockAndUpdate(worldPosition, ((BlockState) stateMap.keySet().toArray()[0]));
TileEntity tile = level.getBlockEntity(worldPosition);
if (tile != null && nbt != null)
tile.load(getBlockState(), nbt);
}
} else if (stateMap.size() == 0) {
// Remove if this is empty
if (level != null) {
level.removeBlock(worldPosition, false);
}
}
if (level != null)
level.getBlockState(worldPosition).neighborChanged(level, worldPosition, getBlockState().getBlock(), worldPosition, false);
}
use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.
the class DepositUtils method getDefaultMatchers.
@SuppressWarnings("unchecked")
public static HashSet<BlockState> getDefaultMatchers() {
// If the cached data isn't there yet, load it.
if (defaultMatchersCached == null) {
defaultMatchersCached = new HashSet<BlockState>();
// GeolosysAPI.plutonRegistry.getStones().forEach(x ->
// defaultMatchersCached.add(x.getOre()));
CommonConfig.DEFAULT_REPLACEMENT_MATS.get().forEach(s -> {
Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(s));
if (block == null || !addDefaultMatcher(block)) {
Geolosys.getInstance().LOGGER.warn("{} is not a valid block. Please verify.", s);
}
});
}
return (HashSet<BlockState>) defaultMatchersCached.clone();
}
use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.
the class LayerDeposit method afterGen.
/**
* Handles what to do after the world has generated
*/
@Override
public void afterGen(ISeedReader reader, BlockPos pos, IDepositCapability cap) {
// Debug the pluton
if (CommonConfig.DEBUG_WORLD_GEN.get()) {
Geolosys.getInstance().LOGGER.debug("Generated {} in Chunk {} (Pos [{} {} {}])", this.toString(), new ChunkPos(pos), pos.getX(), pos.getY(), pos.getZ());
}
ChunkPos thisChunk = new ChunkPos(pos);
int maxSampleCnt = Math.min(CommonConfig.MAX_SAMPLES_PER_CHUNK.get(), (this.radius / CommonConfig.MAX_SAMPLES_PER_CHUNK.get()) + (this.radius % CommonConfig.MAX_SAMPLES_PER_CHUNK.get()));
for (int i = 0; i < maxSampleCnt; i++) {
BlockPos samplePos = SampleUtils.getSamplePosition(reader, new ChunkPos(pos));
BlockState tmp = this.getSample();
if (tmp == null) {
continue;
}
if (samplePos == null || SampleUtils.inNonWaterFluid(reader, samplePos)) {
continue;
}
if (SampleUtils.isInWater(reader, samplePos) && tmp.hasProperty(BlockStateProperties.WATERLOGGED)) {
tmp = tmp.with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(true));
}
FeatureUtils.tryPlaceBlock(reader, thisChunk, samplePos, tmp, cap);
FeatureUtils.fixSnowyBlock(reader, samplePos);
}
}
use of net.minecraft.block.BlockState in project Geolosys by oitsjustjose.
the class LayerDeposit 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;
ChunkPos thisChunk = new ChunkPos(pos);
int x = ((thisChunk.getXStart() + thisChunk.getXEnd()) / 2) - reader.getRandom().nextInt(8) + reader.getRandom().nextInt(16);
int y = this.yMin + reader.getRandom().nextInt(Math.abs(this.yMax - this.yMin));
int z = ((thisChunk.getZStart() + thisChunk.getZEnd()) / 2) - reader.getRandom().nextInt(8) + reader.getRandom().nextInt(16);
int max = Utils.getTopSolidBlock(reader, pos).getY();
if (y > max) {
y = Math.max(yMin, max);
}
BlockPos basePos = new BlockPos(x, y, z);
for (int dX = -this.radius; dX <= this.radius; dX++) {
for (int dZ = -this.radius; dZ <= this.radius; dZ++) {
for (int dY = 0; dY < depth; dY++) {
float dist = dX * dX + dZ * dZ;
if (dist > this.radius * 2) {
continue;
}
BlockPos placePos = basePos.add(dX, dY, dZ);
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++;
}
}
}
}
return totlPlaced;
}
Aggregations