use of net.minecraft.entity.player.PlayerEntity in project BluePower by Qmunity.
the class BPEventHandler method blockHighlightEvent.
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public void blockHighlightEvent(DrawHighlightEvent event) {
PlayerEntity player = Minecraft.getInstance().player;
if (player == null) {
return;
}
World world = player.level;
if (world == null) {
return;
}
RayTraceResult mop = event.getTarget();
if (mop instanceof BlockRayTraceResult) {
BlockPos pos = ((BlockRayTraceResult) mop).getBlockPos();
BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockBPMultipart) {
BlockState partstate = MultipartUtils.getClosestState(player, pos);
IVertexBuilder builder = event.getBuffers().getBuffer(RenderType.lines());
if (partstate != null) {
VoxelShape shape = partstate.getShape(world, pos, ISelectionContext.of(player));
Vector3d projectedView = event.getInfo().getPosition();
double d0 = pos.getX() - projectedView.x();
double d1 = pos.getY() - projectedView.y();
double d2 = pos.getZ() - projectedView.z();
Matrix4f matrix4f = event.getMatrix().last().pose();
shape.forAllEdges((startX, startY, startZ, endX, endY, endZ) -> {
builder.vertex(matrix4f, (float) (startX + d0), (float) (startY + d1), (float) (startZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
builder.vertex(matrix4f, (float) (endX + d0), (float) (endY + d1), (float) (endZ + d2)).color(0.0F, 0.0F, 0.0F, 0.4F).endVertex();
});
event.setCanceled(true);
}
}
}
}
use of net.minecraft.entity.player.PlayerEntity in project BluePower by Qmunity.
the class BPEventHandler method dropHeads.
private void dropHeads(LivingDeathEvent event) {
if (event.getEntityLiving() instanceof CreeperEntity) {
event.getEntityLiving().spawnAtLocation(new ItemStack(Items.CREEPER_HEAD, 1), 0.0F);
}
if (event.getEntityLiving() instanceof PlayerEntity) {
ItemStack drop = new ItemStack(Items.PLAYER_HEAD, 1);
drop.setTag(new CompoundNBT());
drop.getTag().putString("SkullOwner", event.getEntityLiving().getDisplayName().getString());
event.getEntityLiving().spawnAtLocation(drop, 0.0F);
}
if (event.getEntityLiving() instanceof AbstractSkeletonEntity) {
AbstractSkeletonEntity sk = (AbstractSkeletonEntity) event.getEntityLiving();
if (sk instanceof SkeletonEntity) {
event.getEntityLiving().spawnAtLocation(new ItemStack(Items.SKELETON_SKULL, 1), 0.0F);
} else {
event.getEntityLiving().spawnAtLocation(new ItemStack(Items.WITHER_SKELETON_SKULL, 1), 0.0F);
}
}
if (event.getEntityLiving() instanceof ZombieEntity) {
event.getEntityLiving().spawnAtLocation(new ItemStack(Items.ZOMBIE_HEAD, 1), 0.0F);
}
}
use of net.minecraft.entity.player.PlayerEntity 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.entity.player.PlayerEntity 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.entity.player.PlayerEntity 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