use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class ItemChannelValve method onItemUse.
@Nonnull
@Override
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
World world = context.getWorld();
BlockPos pos = context.getPos();
BlockState state = world.getBlockState(context.getPos());
if (state.getBlock() instanceof BlockIrrigationChannelAbstract) {
if (!BlockIrrigationChannelAbstract.VALVE.fetch(state).hasValve()) {
world.setBlockState(pos, BlockIrrigationChannelAbstract.VALVE.apply(state, BlockIrrigationChannelAbstract.Valve.OPEN));
if (world.isRemote()) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityIrrigationChannel) {
((TileEntityIrrigationChannel) tile).setValveState(TileEntityIrrigationChannel.ValveState.OPEN);
}
}
if (context.getPlayer() != null && !context.getPlayer().isCreative()) {
context.getPlayer().getHeldItem(context.getHand()).shrink(1);
}
return ActionResultType.SUCCESS;
}
}
return super.onItemUse(context);
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class TileEntitySeedAnalyzer method calculateObserverPosition.
protected Vector3d calculateObserverPosition(double fov) {
// calculate offset from the center of the looking glass based on fov
double d = 0.75 * (0.5 / Math.tan(Math.PI * fov / 360));
double dy = d * MathHelper.sin((float) Math.PI * 67.5F / 180);
double dx = d * MathHelper.cos((float) Math.PI * 67.5F / 180);
// fetch orientation, to determine the center of the looking glass
BlockState state = this.getBlockState();
Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
// apply observer position (center of looking glass + fov offset)
return this.observerPosition = new Vector3d(this.getPos().getX() + 0.5 + (dx + 0.3125) * dir.getXOffset(), this.getPos().getY() + 0.6875 + dy, this.getPos().getZ() + 0.5 + (dx + 0.3125) * dir.getZOffset());
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class TileEntitySeedAnalyzerSeedRenderer method renderGenome.
protected void renderGenome(TileEntitySeedAnalyzer tile, float partialTick, MatrixStack transforms, IRenderTypeBuffer buffer) {
// fetch genes
List<IAgriGenePair<?>> genes = tile.getGenesToRender();
if (genes == null) {
// should never be possible
return;
}
// push a new matrix to the stack
transforms.push();
// fetch helpers
SeedAnalyzerViewPointHandler viewHandler = SeedAnalyzerViewPointHandler.getInstance();
AgriGenomeRenderer renderer = AgriGenomeRenderer.getInstance();
// fetch scroll position
int index = viewHandler.getScrollIndex();
float partial = viewHandler.getPartialScrollProgress(partialTick);
// fetch orientation
BlockState state = tile.getBlockState();
Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
// helix dimensions
float h = Constants.HALF;
float r = h / 10;
// transform to the desired position
float dx = Constants.HALF + Constants.UNIT * dir.getXOffset();
float dy = 5 * Constants.UNIT;
float dz = Constants.HALF + Constants.UNIT * dir.getZOffset();
transforms.translate(dx, dy, dz);
transforms.rotate(new Quaternion(Vector3f.YP, tile.getHorizontalAngle(), true));
// render the helix
renderer.renderDoubleHelix(genes, transforms, buffer, index, partial, r, h, 1.0F, false);
// render the text
if (index >= 0 && index < genes.size()) {
transforms.push();
transforms.translate(0, 0, -3 * Constants.UNIT);
transforms.rotate(TEXT_ROTATION);
float scale = 2.0F / Math.max(this.getScaledWindowWidth(), this.getScaledWindowHeight());
transforms.scale(scale, scale, 1);
renderer.renderTextOverlay(transforms, genes.get(index));
transforms.pop();
}
// pop the matrix off the stack
transforms.pop();
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class GreenHouseHandler method checkAndFormGreenHouse.
public void checkAndFormGreenHouse(World world, BlockPos pos) {
BlockState state = world.getBlockState(pos);
if (!state.getBlock().isAir(state, world, pos)) {
return;
}
new GreenHouseFormer(world, pos).getGreenHouse().ifPresent(greenHouse -> {
if (greenHouse.isValid()) {
CapabilityGreenHouseData.getInstance().addGreenHouse(world, greenHouse);
greenHouse.convertAirBlocks(world);
}
});
}
use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.
the class VanillaSeedConversionHandler method runPlantingConversion.
protected boolean runPlantingConversion(World world, BlockPos pos, ItemStack stack, PlayerEntity player, Hand hand) {
return !AgriCraft.instance.getConfig().convertSeedsOnlyInAnalyzer() && AgriApi.getGenomeAdapterizer().valueOf(stack).map(seed -> {
// The player is attempting to plant a seed, convert it to an agricraft crop
return AgriApi.getSoil(world, pos.down()).map(soil -> {
// check if there are crop sticks above
MutableBoolean consumed = new MutableBoolean(false);
boolean cropSticks = AgriApi.getCrop(world, pos).map(crop -> {
if (!crop.hasPlant() && !crop.isCrossCrop() && crop.plantGenome(seed, player)) {
if (player == null || !player.isCreative()) {
stack.shrink(1);
consumed.setValue(true);
}
if (player != null) {
player.swingArm(hand);
}
}
return true;
}).orElse(false);
// if there were crop sticks, return the result of the crop sticks action
if (cropSticks) {
return consumed.getValue();
}
// no crop sticks, try planting as a plant
BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, pos);
if (newState != null && world.setBlockState(pos, newState, 11)) {
boolean planted = AgriApi.getCrop(world, pos).map(crop -> crop.plantGenome(seed, player)).orElse(false);
if (planted) {
// reduce stack size
if (player == null || !player.isCreative()) {
stack.shrink(1);
}
// return success
return true;
} else {
world.setBlockState(pos, Blocks.AIR.getDefaultState());
}
}
return false;
}).orElse(false);
}).orElse(false);
}
Aggregations