use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.
the class BlockCompostSoil method updateTick.
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random r) {
if (!world.isRemote) {
BlockPos posU = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
IBlockState s = world.getBlockState(posU);
Block b = s.getBlock();
int deg = state.getValue(DEGRADATION);
boolean flag = false;
if (b != null && (b instanceof IPlantable || b instanceof IGrowable)) {
if (b instanceof IGrowable)
flag = ((IGrowable) b).canGrow(world, posU, s, false);
//trigger growth tick
b.updateTick(world, posU, world.getBlockState(posU), r);
//degradation: 0-10
int i = deg;
if (//if random number(0-23) is bigger than degradation
r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
i++;
if (r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
i++;
if (r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
i++;
if (r.nextInt(24) > i)
b.updateTick(world, posU, world.getBlockState(posU), r);
}
if (r.nextInt(5 + (flag ? 3 : 0)) == 0) {
if (deg < 10)
world.setBlockState(pos, state.withProperty(DEGRADATION, deg + 1));
else
world.setBlockState(pos, Blocks.DIRT.getDefaultState());
}
}
}
use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.
the class BlockCompostSoil method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack current = player.inventory.getStackInSlot(player.inventory.currentItem);
if (current == null || !(current.getItem() instanceof ItemHoe))
return false;
BlockPos posU = new BlockPos(pos.getX(), pos.getY() + 1, pos.getZ());
IBlockState stateU = world.getBlockState(posU);
if (stateU.getBlock().isAir(stateU, world, posU)) {
if (!world.isRemote) {
current.damageItem(1, player);
world.setBlockState(pos, ModBlocks.compostSoilTilledBlock.getStateFromMeta(this.getMetaFromState(state)), 3);
}
world.playSound(null, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
return true;
}
use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.
the class BlockSeedBox method getActualState.
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
TileEntity t = worldIn.getTileEntity(pos);
IBlockState ret = state;
if (t != null && t instanceof TileEntitySeedBox) {
TileEntitySeedBox s = (TileEntitySeedBox) t;
ret = ret.withProperty(OUTLET_TOP, s.isOutput(EnumFacing.UP));
ret = ret.withProperty(OUTLET_BOTTOM, s.isOutput(EnumFacing.DOWN));
ret = ret.withProperty(OUTLET_NORTH, s.isOutput(EnumFacing.NORTH));
ret = ret.withProperty(OUTLET_EAST, s.isOutput(EnumFacing.EAST));
ret = ret.withProperty(OUTLET_SOUTH, s.isOutput(EnumFacing.SOUTH));
ret = ret.withProperty(OUTLET_WEST, s.isOutput(EnumFacing.WEST));
}
return ret;
}
use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.
the class BlockEnderProof method rayTraceBlocks.
public static List<BlockPos> rayTraceBlocks(World w, Vec3d vec31, Vec3d vec32, boolean ignoreBlockWithoutBoundingBox, @Nullable FloodFill.BlockMatcher matcher) {
List<BlockPos> ret = new ArrayList<>();
if (!Double.isNaN(vec31.xCoord) && !Double.isNaN(vec31.yCoord) && !Double.isNaN(vec31.zCoord)) {
if (!Double.isNaN(vec32.xCoord) && !Double.isNaN(vec32.yCoord) && !Double.isNaN(vec32.zCoord)) {
int i = MathHelper.floor(vec32.xCoord);
int j = MathHelper.floor(vec32.yCoord);
int k = MathHelper.floor(vec32.zCoord);
int l = MathHelper.floor(vec31.xCoord);
int i1 = MathHelper.floor(vec31.yCoord);
int j1 = MathHelper.floor(vec31.zCoord);
BlockPos blockpos = new BlockPos(l, i1, j1);
IBlockState iblockstate = w.getBlockState(blockpos);
if (!ret.contains(blockpos) && matcher.matches(iblockstate)) {
Block block = iblockstate.getBlock();
if ((!ignoreBlockWithoutBoundingBox || iblockstate.getCollisionBoundingBox(w, blockpos) != Block.NULL_AABB) && block.canCollideCheck(iblockstate, true)) {
RayTraceResult raytraceresult = iblockstate.collisionRayTrace(w, blockpos, vec31, vec32);
if (raytraceresult != null) {
ret.add(blockpos);
}
}
}
int k1 = 200;
while (k1-- >= 0) {
if (Double.isNaN(vec31.xCoord) || Double.isNaN(vec31.yCoord) || Double.isNaN(vec31.zCoord)) {
return ret;
}
if (l == i && i1 == j && j1 == k) {
return ret;
}
boolean flag2 = true;
boolean flag = true;
boolean flag1 = true;
double d0 = 999.0D;
double d1 = 999.0D;
double d2 = 999.0D;
if (i > l) {
d0 = (double) l + 1.0D;
} else if (i < l) {
d0 = (double) l + 0.0D;
} else {
flag2 = false;
}
if (j > i1) {
d1 = (double) i1 + 1.0D;
} else if (j < i1) {
d1 = (double) i1 + 0.0D;
} else {
flag = false;
}
if (k > j1) {
d2 = (double) j1 + 1.0D;
} else if (k < j1) {
d2 = (double) j1 + 0.0D;
} else {
flag1 = false;
}
double d3 = 999.0D;
double d4 = 999.0D;
double d5 = 999.0D;
double d6 = vec32.xCoord - vec31.xCoord;
double d7 = vec32.yCoord - vec31.yCoord;
double d8 = vec32.zCoord - vec31.zCoord;
if (flag2) {
d3 = (d0 - vec31.xCoord) / d6;
}
if (flag) {
d4 = (d1 - vec31.yCoord) / d7;
}
if (flag1) {
d5 = (d2 - vec31.zCoord) / d8;
}
if (d3 == -0.0D) {
d3 = -1.0E-4D;
}
if (d4 == -0.0D) {
d4 = -1.0E-4D;
}
if (d5 == -0.0D) {
d5 = -1.0E-4D;
}
EnumFacing enumfacing;
if (d3 < d4 && d3 < d5) {
enumfacing = i > l ? EnumFacing.WEST : EnumFacing.EAST;
vec31 = new Vec3d(d0, vec31.yCoord + d7 * d3, vec31.zCoord + d8 * d3);
} else if (d4 < d5) {
enumfacing = j > i1 ? EnumFacing.DOWN : EnumFacing.UP;
vec31 = new Vec3d(vec31.xCoord + d6 * d4, d1, vec31.zCoord + d8 * d4);
} else {
enumfacing = k > j1 ? EnumFacing.NORTH : EnumFacing.SOUTH;
vec31 = new Vec3d(vec31.xCoord + d6 * d5, vec31.yCoord + d7 * d5, d2);
}
l = MathHelper.floor(vec31.xCoord) - (enumfacing == EnumFacing.EAST ? 1 : 0);
i1 = MathHelper.floor(vec31.yCoord) - (enumfacing == EnumFacing.UP ? 1 : 0);
j1 = MathHelper.floor(vec31.zCoord) - (enumfacing == EnumFacing.SOUTH ? 1 : 0);
blockpos = new BlockPos(l, i1, j1);
IBlockState iblockstate1 = w.getBlockState(blockpos);
if (!ret.contains(blockpos) && matcher.matches(iblockstate1)) {
Block block1 = iblockstate1.getBlock();
if ((!ignoreBlockWithoutBoundingBox || iblockstate.getCollisionBoundingBox(w, blockpos) != Block.NULL_AABB) && block1.canCollideCheck(iblockstate, true)) {
RayTraceResult raytraceresult = iblockstate1.collisionRayTrace(w, blockpos, vec31, vec32);
if (raytraceresult != null) {
ret.add(blockpos);
}
}
}
}
}
}
return ret;
}
use of net.minecraft.block.state.IBlockState in project ConvenientAdditions by Necr0.
the class BlockSetProvider method getActualState.
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
TileEntity t = worldIn.getTileEntity(pos);
IBlockState ret = state;
if (t != null && t instanceof TileEntitySetProvider) {
TileEntitySetProvider s = (TileEntitySetProvider) t;
ret = ret.withProperty(OUTLET_TOP, s.outletSides.get(EnumFacing.UP));
ret = ret.withProperty(OUTLET_BOTTOM, s.outletSides.get(EnumFacing.DOWN));
ret = ret.withProperty(OUTLET_NORTH, s.outletSides.get(EnumFacing.NORTH));
ret = ret.withProperty(OUTLET_EAST, s.outletSides.get(EnumFacing.EAST));
ret = ret.withProperty(OUTLET_SOUTH, s.outletSides.get(EnumFacing.SOUTH));
ret = ret.withProperty(OUTLET_WEST, s.outletSides.get(EnumFacing.WEST));
}
return ret;
}
Aggregations