use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class TileEntitySeedAnalyzer method getObserverOrientation.
@Override
public Vector2f getObserverOrientation() {
if (this.observerOrientation == null) {
BlockState state = this.getBlockState();
Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
// The analyzer looking glass is tilted 22.5 degrees, therefore we have to pitch down 67.5 degrees
this.observerOrientation = new Vector2f(67.5F, dir.getOpposite().getHorizontalAngle());
}
return this.observerOrientation;
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class BlockIrrigationChannelAbstract method getStateForPlacement.
@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
World world = context.getWorld();
BlockPos pos = context.getPos();
BlockState state = this.getDefaultState();
for (Direction dir : Direction.values()) {
Optional<InfProperty<Boolean>> prop = getConnection(dir);
if (prop.isPresent()) {
TileEntity tile = world.getTileEntity(pos.offset(dir));
if (tile instanceof TileEntityIrrigationComponent) {
TileEntityIrrigationComponent component = (TileEntityIrrigationComponent) tile;
if (component.isSameMaterial(context.getItem())) {
state = prop.get().apply(state, true);
}
}
}
}
return state;
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class ItemCropSticks method placeCropSticksOnSoil.
protected ActionResultType placeCropSticksOnSoil(World world, BlockPos pos, BlockItemUseContext context) {
// Test if the placement is valid
BlockState newState = this.getVariant().getBlock().getStateForPlacement(context);
if (newState == null) {
return ActionResultType.FAIL;
}
// Set the block to a crop.
final boolean success = world.setBlockState(pos, newState);
// If there was trouble, abort.
if (!success) {
AgriCore.getCoreLogger().debug("ItemCrop#onItemUse failed to create the BlockCrop!");
return ActionResultType.FAIL;
}
// Remove the crop used from the stack.
this.consumeItem(context.getPlayer(), context.getHand());
// Play placement sound.
CropHelper.playPlantingSound(world, pos, context.getPlayer());
// Action was a success.
return ActionResultType.SUCCESS;
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class ItemCropSticks method placeCropSticksOnPlant.
protected ActionResultType placeCropSticksOnPlant(World world, BlockPos pos, @Nullable PlayerEntity player, Hand hand, TileEntityCropPlant plant, BlockState state) {
// Attempt to convert to crop sticks
BlockState newState = this.getVariant().getBlock().getDefaultState();
newState = BlockCropBase.PLANT.mimic(state, newState);
newState = BlockCropBase.LIGHT.mimic(state, newState);
newState = InfProperty.Defaults.fluidlogged().mimic(state, newState);
world.setBlockState(pos, newState);
// If there was trouble, reset and abort.
TileEntity tile = world.getTileEntity(pos);
if (!(tile instanceof TileEntityCropSticks)) {
world.setBlockState(pos, state);
return ActionResultType.FAIL;
}
// Mimic plant and weed
((TileEntityCropSticks) tile).mimicFrom(plant);
// Remove the crop used from the stack
this.consumeItem(player, hand);
// Play placement sound.
CropHelper.playPlantingSound(world, pos, player);
// Action was a success.
return ActionResultType.SUCCESS;
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class ItemCropSticks method onItemUse.
@Nonnull
@Override
@SuppressWarnings("deprecation")
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
// Fetch target world, pos, tile, and state
World world = context.getWorld();
BlockPos pos = context.getPos();
TileEntity tile = world.getTileEntity(pos);
BlockState state = world.getBlockState(pos);
// Try placing on same block
if (tile instanceof TileEntityCropPlant) {
// Place on existing plant
return this.placeCropSticksOnPlant(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropPlant) tile, state);
} else if (tile instanceof TileEntityCropSticks) {
// Make cross crop
return this.tryMakeCrossCrop(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropSticks) tile);
}
// Fetch pos, tile, and state above
pos = pos.offset(context.getFace());
tile = world.getTileEntity(pos);
state = world.getBlockState(pos);
if (state.isAir(world, pos) || state.getFluidState().getFluid() == Fluids.WATER) {
// Place on soil
return this.placeCropSticksOnSoil(world, pos, new BlockItemUseContext(context));
} else if (tile instanceof TileEntityCropPlant) {
// Place on existing plant
return this.placeCropSticksOnPlant(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropPlant) tile, state);
} else if (tile instanceof TileEntityCropSticks) {
// Make cross crop
return this.tryMakeCrossCrop(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropSticks) tile);
}
return ActionResultType.FAIL;
}
Aggregations