use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.
the class DynBucketTest method onBucketFill.
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
RayTraceResult target = event.getTarget();
if (target != null) {
IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
if (state.getBlock() instanceof IFluidBlock) {
Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
ItemStack bucket = event.getEmptyBucket();
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(bucket);
if (fluidHandler != null) {
int fillAmount = fluidHandler.fill(fs, true);
if (fillAmount > 0) {
ItemStack filledBucket = fluidHandler.getContainer();
event.setFilledBucket(filledBucket);
event.setResult(Result.ALLOW);
}
}
}
}
}
use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.
the class WorldGenSeaweed method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
IBlockState b;
if (canGenerateAt(world, pos)) {
BlockPos p;
int direction;
if (seaweedBlock.getBlock().canPlaceBlockAt(world, pos)) {
world.setBlockState(pos, seaweedBlock, 2);
}
for (int i = 0; i < height; i++) {
direction = rand.nextInt(4);
switch(direction) {
case 0:
x -= 1;
break;
case 1:
x += 1;
break;
case 2:
z -= 1;
break;
case 3:
z += 1;
break;
default:
// Straight up.
;
break;
}
p = new BlockPos(x, y + i, z);
b = world.getBlockState(p);
if (b == Blocks.WATER.getDefaultState()) {
if (seaweedBlock.getBlock().canPlaceBlockAt(world, p)) {
world.setBlockState(p, seaweedBlock, 2);
}
}
}
}
return true;
}
use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.
the class WorldGenShrubRTG method buildLeaves.
public void buildLeaves(World world, int x, int y, int z, int size) {
IBlockState b = world.getBlockState(new BlockPos(x, y - 2, z));
IBlockState b1 = world.getBlockState(new BlockPos(x, y - 1, z));
if ((b == Blocks.SAND.getDefaultState() || b1 == Blocks.SAND.getDefaultState()) && !rtgConfig.ALLOW_TREES_TO_GENERATE_ON_SAND.get()) {
return;
}
if (b.getMaterial() == Material.GRASS || b.getMaterial() == Material.GROUND || (varSand && b.getMaterial() == Material.SAND)) {
if (b1 != Blocks.WATER.getDefaultState()) {
if (!rtgConfig.ALLOW_SHRUBS_TO_GENERATE_BELOW_SURFACE.get()) {
if (b1.getMaterial() != Material.AIR && b1.getMaterial() != Material.VINE && b1.getMaterial() != Material.PLANTS && b1 != Blocks.SNOW_LAYER.getDefaultState()) {
return;
}
}
for (int i = -size; i <= size; i++) {
for (int j = -1; j <= 1; j++) {
for (int k = -size; k <= size; k++) {
if (Math.abs(i) + Math.abs(j) + Math.abs(k) <= size) {
buildBlock(world, x + i, y + j, z + k, leaveBlock);
}
}
}
}
world.setBlockState(new BlockPos(x, y - 1, z), logBlock, 0);
}
}
}
use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.
the class WorldGenSponge method generate.
@Override
public boolean generate(World world, Random rand, BlockPos pos) {
int x = pos.getX();
int y = pos.getY();
int z = pos.getZ();
while (true) {
if (y > 3) {
label63: {
if (!world.isAirBlock(new BlockPos(x, y - 1, z))) {
IBlockState block = world.getBlockState(new BlockPos(x, y - 1, z));
if (validGroundBlocks.contains(block.getBlock())) {
break label63;
}
}
--y;
continue;
}
}
if (y <= 3) {
return false;
}
int k2 = this.spongeSize;
for (int l = 0; k2 >= 0 && l < 3; ++l) {
int i1 = k2 + rand.nextInt(2);
int j1 = k2 + rand.nextInt(2);
int k1 = k2 + rand.nextInt(2);
float f = (float) (i1 + j1 + k1) * 0.333F + 0.5F;
for (int l1 = x - i1; l1 <= x + i1; ++l1) {
for (int i2 = z - k1; i2 <= z + k1; ++i2) {
for (int j2 = y - j1; j2 <= y + j1; ++j2) {
float f1 = (float) (l1 - x);
float f2 = (float) (i2 - z);
float f3 = (float) (j2 - y);
if (f1 * f1 + f2 * f2 + f3 * f3 <= f * f) {
if (isAdjacent(world, l1, j2, i2)) {
world.setBlockState(new BlockPos(l1, j2, i2), spongeBlock, 2);
//Logger.debug("Sponge generated at %d %d %d", l1, j2, i2);
}
}
}
}
}
x += -(k2 + 1) + rand.nextInt(2 + k2 * 2);
z += -(k2 + 1) + rand.nextInt(2 + k2 * 2);
y += 0 - rand.nextInt(2);
}
return true;
}
}
use of net.minecraft.block.state.IBlockState in project Realistic-Terrain-Generation by Team-RTG.
the class WorldGenVinesRTG method addVine.
protected void addVine(World worldIn, Random rand, BlockPos pos, EnumFacing enumfacing) {
IBlockState iblockstate = this.vineBlock.getDefaultState().withProperty(this.propNorth, enumfacing == EnumFacing.SOUTH).withProperty(this.propEast, enumfacing == EnumFacing.WEST).withProperty(this.propSouth, enumfacing == EnumFacing.NORTH).withProperty(this.propWest, enumfacing == EnumFacing.EAST);
this.setBlockAndNotifyAdequately(worldIn, pos, iblockstate);
int i = rand.nextInt(4) + 1;
for (pos = pos.down(); worldIn.isAirBlock(pos) && i > 0; --i) {
this.setBlockAndNotifyAdequately(worldIn, pos, iblockstate);
pos = pos.down();
}
}
Aggregations