Search in sources :

Example 21 with PlayerEntity

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);
            }
        }
    }
}
Also used : Matrix4f(net.minecraft.util.math.vector.Matrix4f) BlockState(net.minecraft.block.BlockState) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Vector3d(net.minecraft.util.math.vector.Vector3d) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) BlockBPMultipart(com.bluepowermod.block.BlockBPMultipart) BlockPos(net.minecraft.util.math.BlockPos) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 22 with PlayerEntity

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);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 23 with PlayerEntity

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;
}
Also used : ItemStackHandler(net.minecraftforge.items.ItemStackHandler) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Hand(net.minecraft.util.Hand) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 24 with PlayerEntity

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;
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) FarmlandBlock(net.minecraft.block.FarmlandBlock) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Hand(net.minecraft.util.Hand) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 25 with PlayerEntity

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;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) Hand(net.minecraft.util.Hand) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PlayerEntity (net.minecraft.entity.player.PlayerEntity)46 ItemStack (net.minecraft.item.ItemStack)22 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)19 World (net.minecraft.world.World)17 BlockPos (net.minecraft.util.math.BlockPos)16 CompoundNBT (net.minecraft.nbt.CompoundNBT)13 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)12 BlockState (net.minecraft.block.BlockState)10 ResourceLocation (net.minecraft.util.ResourceLocation)7 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)6 Nonnull (javax.annotation.Nonnull)6 AgriCraft (com.infinityraider.agricraft.AgriCraft)5 TileEntity (net.minecraft.tileentity.TileEntity)5 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)4 IAgriPlant (com.infinityraider.agricraft.api.v1.plant.IAgriPlant)4 AgriTabs (com.infinityraider.agricraft.content.AgriTabs)4 Names (com.infinityraider.agricraft.reference.Names)4 ItemBase (com.infinityraider.infinitylib.item.ItemBase)4 Nullable (javax.annotation.Nullable)4 Blocks (net.minecraft.block.Blocks)4