use of net.minecraft.util.Hand in project AgriCraft by AgriCraft.
the class JournalViewPointHandler method toggle.
public boolean toggle(PlayerEntity player, Hand hand) {
if (this.isActive(hand)) {
this.setActive(hand, false);
if (AgriCraft.instance.proxy().toggleDynamicCamera(this, false)) {
this.journal = null;
return true;
} else {
this.setActive(hand, true);
this.journal = new JournalClientData(player, hand);
}
} else {
Hand other = hand == Hand.MAIN_HAND ? Hand.OFF_HAND : Hand.MAIN_HAND;
if (!this.isActive(other)) {
this.setActive(hand, true);
if (AgriCraft.instance.proxy().toggleDynamicCamera(this, true)) {
this.journal = new JournalClientData(player, hand);
return true;
} else {
this.setActive(hand, false);
this.journal = null;
}
}
}
return false;
}
use of net.minecraft.util.Hand 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);
}
use of net.minecraft.util.Hand in project BluePower by Qmunity.
the class ItemSeedBag method useOn.
@Override
public ActionResultType useOn(ItemUseContext context) {
PlayerEntity player = context.getPlayer();
World worldIn = context.getLevel();
Hand hand = context.getHand();
BlockPos pos = context.getClickedPos();
if (player.isCrouching()) {
return ActionResultType.PASS;
}
ItemStackHandler seedBagInvHandler = new ItemStackHandler(9);
// Get Active hand
Hand activeHand = Hand.MAIN_HAND;
ItemStack seedBag = player.getItemInHand(activeHand);
if (!(seedBag.getItem() instanceof ItemSeedBag)) {
seedBag = player.getOffhandItem();
activeHand = Hand.OFF_HAND;
}
// Get Items from the NBT Handler
if (seedBag.hasTag())
seedBagInvHandler.deserializeNBT(seedBag.getTag().getCompound("inv"));
ItemStack seed = getSeedType(player.getItemInHand(hand));
Block block = Block.byItem(seed.getItem());
if (!seed.isEmpty() && block instanceof IPlantable) {
IPlantable plant = (IPlantable) block;
BlockState b = worldIn.getBlockState(pos);
if (b.getBlock().canSustainPlant(b, worldIn, pos, Direction.UP, plant) && worldIn.isEmptyBlock(pos.relative(Direction.UP))) {
for (int i = 0; i < 9; i++) {
ItemStack is = seedBagInvHandler.getStackInSlot(i);
if (!is.isEmpty()) {
worldIn.setBlock(pos.relative(Direction.UP), block.defaultBlockState(), 0);
seedBagInvHandler.extractItem(i, 1, false);
break;
}
}
// Update items in the NBT
if (!seedBag.hasTag())
seedBag.setTag(new CompoundNBT());
if (seedBag.getTag() != null) {
seedBag.getTag().put("inv", seedBagInvHandler.serializeNBT());
}
return ActionResultType.SUCCESS;
}
}
return ActionResultType.PASS;
}
use of net.minecraft.util.Hand in project BluePower by Qmunity.
the class ItemCropSeed method useOn.
@Override
public ActionResultType useOn(ItemUseContext itemUseContext) {
PlayerEntity player = itemUseContext.getPlayer();
Hand hand = itemUseContext.getHand();
Direction facing = itemUseContext.getClickedFace();
World world = itemUseContext.getLevel();
BlockPos pos = itemUseContext.getClickedPos();
ItemStack itemStack = player.getItemInHand(hand);
if (facing.ordinal() != 1) {
return ActionResultType.PASS;
} else if (player.mayUseItemAt(pos, facing, itemStack) && player.mayUseItemAt(pos.above(), facing, itemStack)) {
if (world.getBlockState(pos).getBlock().canSustainPlant(world.getBlockState(pos), world, pos, Direction.UP, this) && world.isEmptyBlock(pos.above()) && world.getBlockState(pos).getBlock() instanceof FarmlandBlock) {
world.setBlock(pos.above(), field_150925_a.defaultBlockState(), 2);
itemStack.setCount(itemStack.getCount() - 1);
player.setItemInHand(hand, itemStack);
return ActionResultType.SUCCESS;
} else {
return ActionResultType.PASS;
}
} else {
return ActionResultType.PASS;
}
}
use of net.minecraft.util.Hand in project Geolosys by oitsjustjose.
the class ProPickItem method onItemUse.
@Override
public ActionResultType onItemUse(ItemUseContext context) {
PlayerEntity player = context.getPlayer();
Hand hand = context.getHand();
World worldIn = context.getWorld();
BlockPos pos = context.getPos();
Direction facing = context.getFace();
if (player.isCrouching()) {
this.onItemRightClick(worldIn, player, hand);
} else {
if (!player.isCreative()) {
this.attemptDamageItem(player, pos, hand, worldIn);
}
// At surface or higher
if (worldIn.isRemote) {
player.swingArm(hand);
return ActionResultType.PASS;
}
ItemStack stack = player.getHeldItem(hand);
int xStart;
int xEnd;
int yStart;
int yEnd;
int zStart;
int zEnd;
int confAmt = CommonConfig.PRO_PICK_RANGE.get();
int confDmt = CommonConfig.PRO_PICK_DIAMETER.get();
switch(facing) {
case UP:
xStart = -(confDmt / 2);
xEnd = confDmt / 2;
yStart = -confAmt;
yEnd = 0;
zStart = -(confDmt / 2);
zEnd = (confDmt / 2);
prospect(player, stack, worldIn, pos, facing, xStart, xEnd, yStart, yEnd, zStart, zEnd);
break;
case DOWN:
xStart = -(confDmt / 2);
xEnd = confDmt / 2;
yStart = 0;
yEnd = confAmt;
zStart = -(confDmt / 2);
zEnd = confDmt / 2;
prospect(player, stack, worldIn, pos, facing, xStart, xEnd, yStart, yEnd, zStart, zEnd);
break;
case NORTH:
xStart = -(confDmt / 2);
xEnd = confDmt / 2;
yStart = -(confDmt / 2);
yEnd = confDmt / 2;
zStart = 0;
zEnd = confAmt;
prospect(player, stack, worldIn, pos, facing, xStart, xEnd, yStart, yEnd, zStart, zEnd);
break;
case SOUTH:
xStart = -(confDmt / 2);
xEnd = confDmt / 2;
yStart = -(confDmt / 2);
yEnd = confDmt / 2;
zStart = -confAmt;
zEnd = 0;
prospect(player, stack, worldIn, pos, facing, xStart, xEnd, yStart, yEnd, zStart, zEnd);
break;
case EAST:
xStart = -(confAmt);
xEnd = 0;
yStart = -(confDmt / 2);
yEnd = confDmt / 2;
zStart = -(confDmt / 2);
zEnd = confDmt / 2;
prospect(player, stack, worldIn, pos, facing, xStart, xEnd, yStart, yEnd, zStart, zEnd);
break;
case WEST:
xStart = 0;
xEnd = confAmt;
yStart = -(confDmt / 2);
yEnd = confDmt / 2;
zStart = -(confDmt / 2);
zEnd = confDmt / 2;
prospect(player, stack, worldIn, pos, facing, xStart, xEnd, yStart, yEnd, zStart, zEnd);
break;
}
player.swingArm(hand);
}
return ActionResultType.SUCCESS;
}
Aggregations