Search in sources :

Example 31 with BlockState

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();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) Dynamic(com.mojang.serialization.Dynamic) IForgeBlockState(net.minecraftforge.common.extensions.IForgeBlockState) BlockState(net.minecraft.block.BlockState) Pair(com.mojang.datafixers.util.Pair)

Example 32 with BlockState

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);
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) TileEntity(net.minecraft.tileentity.TileEntity) ITickableTileEntity(net.minecraft.tileentity.ITickableTileEntity) IForgeBlockState(net.minecraftforge.common.extensions.IForgeBlockState) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack)

Example 33 with BlockState

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();
}
Also used : BlockState(net.minecraft.block.BlockState) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) HashSet(java.util.HashSet)

Example 34 with BlockState

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);
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

Example 35 with BlockState

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;
}
Also used : BlockState(net.minecraft.block.BlockState) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos)

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