Search in sources :

Example 76 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project BuildingGadgets by Direwolf20-MC.

the class GadgetDestruction method use.

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
    ItemStack stack = player.getItemInHand(hand);
    player.startUsingItem(hand);
    if (!world.isClientSide) {
        if (!player.isShiftKeyDown()) {
            BlockPos anchorPos = getAnchor(stack);
            Direction anchorSide = getAnchorSide(stack);
            if (anchorPos != null && anchorSide != null) {
                clearArea(world, anchorPos, anchorSide, (ServerPlayer) player, stack);
                onAnchorRemoved(stack, player);
                return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
            }
            BlockHitResult lookingAt = VectorHelper.getLookingAt(player, stack);
            if (!world.isEmptyBlock(lookingAt.getBlockPos())) {
                clearArea(world, lookingAt.getBlockPos(), lookingAt.getDirection(), (ServerPlayer) player, stack);
                onAnchorRemoved(stack, player);
                return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
            }
            return new InteractionResultHolder<>(InteractionResult.FAIL, stack);
        }
    } else if (player.isShiftKeyDown()) {
        GuiMod.DESTRUCTION.openScreen(player);
    }
    return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
}
Also used : InteractionResultHolder(net.minecraft.world.InteractionResultHolder) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Direction(net.minecraft.core.Direction)

Example 77 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project Silent-Gear by SilentChaos512.

the class DebugOverlay method getDebugText.

@Nonnull
@Override
public List<String> getDebugText() {
    List<String> list = new ArrayList<>();
    Minecraft mc = Minecraft.getInstance();
    LocalPlayer player = mc.player;
    if (player == null)
        return list;
    // addAttributeInfo(list, player, SharedMonsterAttributes.LUCK);
    ItemStack heldItem = player.getItemInHand(InteractionHand.MAIN_HAND);
    if (heldItem.isEmpty())
        return list;
    Item item = heldItem.getItem();
    // Crossbow debugging
    if (item instanceof GearCrossbowItem) {
        float pull = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("pull"), mc.level, player);
        float pulling = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("pulling"), mc.level, player);
        float charged = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("charged"), mc.level, player);
        float firework = ModelPropertiesHelper.getValue(heldItem, new ResourceLocation("firework"), mc.level, player);
        list.add(String.format("pull=%.1f", pull));
        list.add(String.format("pulling=%.1f", pulling));
        list.add(String.format("charged=%.1f", charged));
        list.add(String.format("firework=%.1f", firework));
        list.add(String.format("chargeTime=%d", GearCrossbowItem.getChargeTime(heldItem)));
        return list;
    }
    // Harvest level checks
    HitResult rt = mc.hitResult;
    if (rt != null && rt.getType() == HitResult.Type.BLOCK) {
        BlockHitResult brt = (BlockHitResult) rt;
        Entity renderViewEntity = mc.getCameraEntity();
        if (renderViewEntity != null) {
            BlockPos pos = brt.getBlockPos();
            BlockState state = renderViewEntity.level.getBlockState(pos);
        /*if (item instanceof ICoreTool) {
                    ToolType toolClass = state.getBlock().getHarvestTool(state);
                    final int blockLevel = state.getBlock().getHarvestLevel(state);
                    final int toolLevel = item.getHarvestLevel(heldItem, toolClass, player, state);

                    final boolean canHarvest = toolLevel >= blockLevel;
                    ChatFormatting format = canHarvest ? ChatFormatting.GREEN : ChatFormatting.RED;
                    String name = toolClass == null ? "null" : toolClass.getName();
                    list.add(format + String.format("%s=%d (%d)", name, blockLevel, toolLevel));

                    final float destroySpeed = heldItem.getDestroySpeed(state);
                    if (canHarvest) {
                        int level = TraitHelper.getTraitLevel(heldItem, Const.Traits.LUSTROUS);
                        int light = GearEvents.getLightForLustrousTrait(player.level, player.blockPosition());
                        final float newSpeed = destroySpeed + GearEvents.getLustrousSpeedBonus(level, light);
                        list.add(String.format("speed = %.1f", newSpeed));
                    } else {
                        list.add(String.format("speed = %.1f", destroySpeed));
                    }
                }*/
        }
    } else if (rt != null && rt.getType() == HitResult.Type.ENTITY) {
        EntityHitResult ert = (EntityHitResult) rt;
        Entity entity = ert.getEntity();
        if (entity instanceof LivingEntity) {
            list.add(String.format("%s", entity.getScoreboardName()));
            list.add(String.format("health = %.3f", ((LivingEntity) entity).getHealth()));
        }
    }
    return list;
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) LocalPlayer(net.minecraft.client.player.LocalPlayer) ArrayList(java.util.ArrayList) Minecraft(net.minecraft.client.Minecraft) EntityHitResult(net.minecraft.world.phys.EntityHitResult) BlockHitResult(net.minecraft.world.phys.BlockHitResult) EntityHitResult(net.minecraft.world.phys.EntityHitResult) HitResult(net.minecraft.world.phys.HitResult) LivingEntity(net.minecraft.world.entity.LivingEntity) Item(net.minecraft.world.item.Item) GearCrossbowItem(net.silentchaos512.gear.item.gear.GearCrossbowItem) BlockState(net.minecraft.world.level.block.state.BlockState) ResourceLocation(net.minecraft.resources.ResourceLocation) BlockPos(net.minecraft.core.BlockPos) GearCrossbowItem(net.silentchaos512.gear.item.gear.GearCrossbowItem) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Nonnull(javax.annotation.Nonnull)

Example 78 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project BuildingGadgets by Direwolf20-MC.

the class GadgetUtils method linkToInventory.

public static void linkToInventory(ItemStack stack, Player player) {
    Level world = player.level;
    BlockHitResult lookingAt = VectorHelper.getLookingAt(player, AbstractGadget.shouldRayTraceFluid(stack) ? ClipContext.Fluid.ANY : ClipContext.Fluid.NONE);
    if (world.getBlockState(VectorHelper.getLookingAt(player, stack).getBlockPos()) == Blocks.AIR.defaultBlockState())
        return;
    InventoryLinker.Result result = InventoryLinker.linkInventory(player.level, stack, lookingAt);
    player.displayClientMessage(result.getI18n().componentTranslation(), true);
}
Also used : InventoryLinker(com.direwolf20.buildinggadgets.common.tainted.inventory.InventoryLinker) Level(net.minecraft.world.level.Level) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 79 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project EvilCraft by CyclopsMC.

the class EntityBiomeExtract method onHit.

@Override
protected void onHit(final HitResult movingobjectposition) {
    if (!level.isClientSide() && movingobjectposition.getType() == HitResult.Type.BLOCK) {
        ItemStack itemStack = getItem();
        final Biome biome = ItemBiomeExtract.getBiome(itemStack);
        if (biome != null) {
            // Update biome in organic spread
            Set<ChunkPos> updatedChunks = Sets.newHashSet();
            OrganicSpread spread = new OrganicSpread(level, 2, 5, new OrganicSpread.IOrganicSpreadable() {

                @Override
                public boolean isDone(Level world, BlockPos location) {
                    return world.getBiome(location) == biome;
                }

                @Override
                public void spreadTo(Level world, BlockPos location) {
                    setBiome((ServerLevel) world, location, biome);
                    updatedChunks.add(new ChunkPos(location));
                    // int color = biome.getFoliageColor(); // Only accessible client-side, so we copy and modify its implementation...
                    int color = biome.specialEffects.getFoliageColorOverride().orElseGet(() -> {
                        double d0 = (double) Mth.clamp(biome.climateSettings.temperature, 0.0F, 1.0F);
                        double d1 = (double) Mth.clamp(biome.climateSettings.downfall, 0.0F, 1.0F);
                        // return FoliageColors.get(d0, d1);
                        return Helpers.RGBToInt(20, 200, 20);
                    });
                    showChangedBiome((ServerLevel) world, new BlockPos(location.getX(), ((BlockHitResult) movingobjectposition).getBlockPos().getY(), location.getZ()), color);
                }
            });
            BlockPos pos = new BlockPos(movingobjectposition.getLocation());
            for (int i = 0; i < 50; i++) {
                spread.spreadTick(pos);
            }
            // Send chunk biome data to all players, and reset their grass colors
            if (!level.isClientSide()) {
                for (ChunkPos chunkPos : updatedChunks) {
                    updateChunkAfterBiomeChange(level, chunkPos);
                }
            }
        }
        // Play sound and show particles of splash potion of harming
        this.level.globalLevelEvent(2002, blockPosition(), 16428);
        remove(RemovalReason.DISCARDED);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ChunkPos(net.minecraft.world.level.ChunkPos) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) OrganicSpread(org.cyclops.evilcraft.core.algorithm.OrganicSpread)

Example 80 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project EvilCraft by CyclopsMC.

the class ItemBloodContainer method use.

@Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
    ItemStack itemStack = player.getItemInHand(hand);
    IFluidHandlerItemCapacity fluidHandler = FluidHelpers.getFluidHandlerItemCapacity(itemStack).orElse(null);
    FluidStack fluidStack = FluidUtil.getFluidContained(itemStack).orElse(FluidStack.EMPTY);
    FluidStack drained = fluidHandler.drain(FluidHelpers.BUCKET_VOLUME, IFluidHandler.FluidAction.SIMULATE);
    boolean hasBucket = !drained.isEmpty() && (drained.getAmount() == FluidHelpers.BUCKET_VOLUME);
    boolean hasSpace = fluidStack.isEmpty() || (fluidStack.getAmount() + FluidHelpers.BUCKET_VOLUME <= fluidHandler.getCapacity());
    BlockHitResult movingobjectpositionDrain = (BlockHitResult) this.getPlayerPOVHitResult(world, player, ClipContext.Fluid.NONE);
    BlockHitResult movingobjectpositionFill = (BlockHitResult) this.getPlayerPOVHitResult(world, player, ClipContext.Fluid.SOURCE_ONLY);
    if (movingobjectpositionDrain != null && movingobjectpositionFill != null) {
        if (isPickupFluids() && movingobjectpositionFill.getType() == HitResult.Type.BLOCK) {
            // Fill the container and remove fluid blockState
            BlockPos blockPos = movingobjectpositionFill.getBlockPos();
            BlockState blockState = world.getBlockState(blockPos);
            if (blockState.getBlock() instanceof LiquidBlock && ((LiquidBlock) blockState.getBlock()).getFluid() == getFluid() && blockState.getValue(LiquidBlock.LEVEL) == 0) {
                if (hasSpace) {
                    world.setBlock(blockPos, Blocks.AIR.defaultBlockState(), 3);
                    fluidHandler.fill(new FluidStack(getFluid(), FluidHelpers.BUCKET_VOLUME), IFluidHandler.FluidAction.EXECUTE);
                }
                return MinecraftHelpers.successAction(itemStack);
            }
        }
        // Drain container and place fluid blockState
        if (hasBucket && isPlaceFluids() && movingobjectpositionDrain.getType() == HitResult.Type.BLOCK) {
            BlockPos blockPos = movingobjectpositionFill.getBlockPos();
            Direction direction = movingobjectpositionDrain.getDirection();
            blockPos = blockPos.offset(direction.getNormal());
            if (this.tryPlaceContainedLiquid(world, blockPos, true)) {
                fluidHandler.drain(FluidHelpers.BUCKET_VOLUME, IFluidHandler.FluidAction.EXECUTE);
                return MinecraftHelpers.successAction(itemStack);
            }
        }
    }
    return MinecraftHelpers.successAction(itemStack);
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandlerItemCapacity(org.cyclops.cyclopscore.capability.fluid.IFluidHandlerItemCapacity) BlockPos(net.minecraft.core.BlockPos) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Direction(net.minecraft.core.Direction)

Aggregations

BlockHitResult (net.minecraft.world.phys.BlockHitResult)181 BlockPos (net.minecraft.core.BlockPos)117 Vec3 (net.minecraft.world.phys.Vec3)79 BlockState (net.minecraft.world.level.block.state.BlockState)66 ItemStack (net.minecraft.world.item.ItemStack)63 HitResult (net.minecraft.world.phys.HitResult)51 Direction (net.minecraft.core.Direction)46 Level (net.minecraft.world.level.Level)41 ClipContext (net.minecraft.world.level.ClipContext)33 Player (net.minecraft.world.entity.player.Player)32 ServerLevel (net.minecraft.server.level.ServerLevel)23 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)20 Entity (net.minecraft.world.entity.Entity)19 InteractionHand (net.minecraft.world.InteractionHand)18 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)18 ServerPlayer (net.minecraft.server.level.ServerPlayer)17 LivingEntity (net.minecraft.world.entity.LivingEntity)17 AABB (net.minecraft.world.phys.AABB)17 EntityHitResult (net.minecraft.world.phys.EntityHitResult)17 Minecraft (net.minecraft.client.Minecraft)16