use of net.minecraft.block.BlockDirt in project BiomesOPlenty by Glitchfiend.
the class UseHoeEventHandler method useHoe.
@SubscribeEvent
public void useHoe(UseHoeEvent event) {
if (event.getResult() != Event.Result.DEFAULT || event.isCanceled()) {
return;
}
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = world.getBlockState(pos);
Block block = state.getBlock();
boolean result = false;
if (block instanceof BlockBOPDirt && world.isAirBlock(pos.up())) {
result = true;
if (state.getValue(BlockBOPDirt.COARSE)) {
world.setBlockState(pos, state.withProperty(BlockBOPDirt.COARSE, false));
} else {
world.setBlockState(pos, BlockBOPFarmland.paging.getVariantState((BlockBOPDirt.BOPDirtType) state.getValue(BlockBOPDirt.VARIANT)));
}
} else if (block instanceof BlockBOPGrass && world.isAirBlock(pos.up())) {
result = true;
IBlockState dirtState = BlockBOPGrass.getDirtBlockState(state);
if (dirtState.getBlock() instanceof BlockBOPDirt) {
BlockBOPDirt.BOPDirtType dirtType = (BlockBOPDirt.BOPDirtType) dirtState.getValue(BlockBOPDirt.VARIANT);
world.setBlockState(pos, BlockBOPFarmland.paging.getVariantState(dirtType));
} else if (dirtState.getBlock() instanceof BlockDirt) {
world.setBlockState(pos, Blocks.FARMLAND.getDefaultState());
} else {
// There is no associated farmland, so just turn it to its associated dirt
// Mostly useful for overgrown grass turning to stone
world.setBlockState(pos, dirtState);
}
}
if (result) {
event.setResult(Event.Result.ALLOW);
world.playSound(event.getEntityPlayer(), pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
event.getEntityPlayer().swingArm(PlayerUtil.getHandForItemAndMeta(event.getEntityPlayer(), event.getCurrent().getItem(), event.getCurrent().getMetadata()));
event.getCurrent().damageItem(1, event.getEntityPlayer());
}
}
use of net.minecraft.block.BlockDirt in project harvestcraft by MatrexsVigil.
the class TileEntityGroundTrap method countFlowers.
public int countFlowers() {
byte radius = 2;
int count = 0;
// final World world = world;
final int varX = pos.getX();
final int varY = pos.getY();
final int varZ = pos.getZ();
for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
if (offsetX * offsetX + offsetZ * offsetZ <= radius * radius && (offsetX != -(radius - 1) || offsetZ != -(radius - 1)) && (offsetX != radius - 1 || offsetZ != radius - 1) && (offsetX != radius - 1 || offsetZ != -(radius - 1)) && (offsetX != -(radius - 1) || offsetZ != radius - 1)) {
final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
if (!world.isBlockLoaded(pos))
continue;
final Block blockAtCoords = world.getBlockState(pos).getBlock();
if (blockAtCoords instanceof BlockDirt || blockAtCoords instanceof BlockGrass) {
count++;
}
}
}
}
return count;
}
use of net.minecraft.block.BlockDirt in project harvestcraft by MatrexsVigil.
the class TileEntityGroundTrap method getRunTime.
private int getRunTime() {
final int radius = 2;
// final World world = world;
final int varX = pos.getX();
final int varY = pos.getY();
final int varZ = pos.getZ();
int speed = 3500;
for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
if (offsetX * offsetX + offsetZ * offsetZ > radius * radius || offsetX == -radius - 1 && offsetZ == -radius - 1 || offsetX == radius - 1 && offsetZ == radius - 1 || offsetX == radius - 1 && offsetZ == -radius - 1 || offsetX == -radius - 1 && offsetZ == radius - 1)
continue;
final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
if (!world.isBlockLoaded(pos))
continue;
final Block blockAtCoords = world.getBlockState(pos).getBlock();
if (blockAtCoords instanceof BlockDirt || blockAtCoords instanceof BlockGrass) {
speed = (int) (speed * 0.95);
}
if (blockAtCoords != BlockRegistry.groundtrap)
continue;
speed = (int) (speed / 0.85);
}
}
return speed;
}
Aggregations